Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -295,9 +295,6 @@ protected String convertToString(final Object value) throws Throwable {
* @return The default value for the specified type.
*/
protected Object getDefault(final Class<?> type) {
if (type.equals(String.class)) {
return null;
}
return defaultValue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

import org.apache.commons.beanutils2.converters.ArrayConverter;
import org.apache.commons.beanutils2.converters.DateConverter;
import org.apache.commons.beanutils2.converters.StringConverter;

import junit.framework.Test;
import junit.framework.TestCase;
Expand Down Expand Up @@ -146,6 +147,12 @@ protected void setUpShared() {
testCalendar.set(Calendar.MILLISECOND, 0);
testUtilDate = testCalendar.getTime();
testStringDate = "28.12.1992";

/*
* Replacing default StringConverter (having default value) with StringConverter without default value
* to allow testing of nullProperty.
*/
ConvertUtils.register(new StringConverter(), String.class);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import java.util.List;
import java.util.Map;

import org.apache.commons.beanutils2.converters.StringConverter;

import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
Expand Down Expand Up @@ -96,6 +98,11 @@ public DynaBeanUtilsTestCase(final String name) {
public void setUp() throws Exception {

ConvertUtils.deregister();
/*
* Replacing default StringConverter (having default value) with StringConverter without default value
* to allow testing of nullProperty.
*/
ConvertUtils.register(new StringConverter(), String.class);

// Instantiate a new DynaBean instance
final DynaClass dynaClass = createDynaClass();
Expand Down Expand Up @@ -812,6 +819,7 @@ public void testPopulateNested() {
*/
public void testPopulateScalar() {


try {

bean.set("nullProperty", "non-null value");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
*
*/
public class StringConverterTestCase extends TestCase {

private static final String DEFAULT_VALUE = "default";

/** The converter to be tested. */
private StringConverter converter;

Expand Down Expand Up @@ -61,4 +64,12 @@ public void testConvertToUnsupportedType() {
public void testDefaultType() {
assertEquals("Wrong default type", String.class, converter.getDefaultType());
}

/**
* Tests whether the correct default value is returned.
*/
public void testDefaultValue() {
converter.setDefaultValue(DEFAULT_VALUE);
assertEquals("Wrong default value", DEFAULT_VALUE, converter.convert(String.class, null));
}
}