moving unit tests from .testsuite -> .beans
This commit is contained in:
parent
248a7de73f
commit
52ac3cea8c
|
@ -16,81 +16,77 @@
|
|||
|
||||
package org.springframework.beans.propertyeditors;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.springframework.test.AssertThrows;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Unit tests for the {@link CustomCollectionEditor} class.
|
||||
*
|
||||
* @author Rick Evans
|
||||
* @author Chris Beams
|
||||
*/
|
||||
public final class CustomCollectionEditorTests extends TestCase {
|
||||
public final class CustomCollectionEditorTests {
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testCtorWithNullCollectionType() throws Exception {
|
||||
new AssertThrows(IllegalArgumentException.class) {
|
||||
public void test() throws Exception {
|
||||
new CustomCollectionEditor(null);
|
||||
}
|
||||
}.runTest();
|
||||
new CustomCollectionEditor(null);
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testCtorWithNonCollectionType() throws Exception {
|
||||
new AssertThrows(IllegalArgumentException.class) {
|
||||
public void test() throws Exception {
|
||||
new CustomCollectionEditor(String.class);
|
||||
}
|
||||
}.runTest();
|
||||
new CustomCollectionEditor(String.class);
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testWithCollectionTypeThatDoesNotExposeAPublicNoArgCtor() throws Exception {
|
||||
new AssertThrows(IllegalArgumentException.class) {
|
||||
public void test() throws Exception {
|
||||
CustomCollectionEditor editor = new CustomCollectionEditor(CollectionTypeWithNoNoArgCtor.class);
|
||||
editor.setValue("1");
|
||||
}
|
||||
}.runTest();
|
||||
CustomCollectionEditor editor = new CustomCollectionEditor(CollectionTypeWithNoNoArgCtor.class);
|
||||
editor.setValue("1");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSunnyDaySetValue() throws Exception {
|
||||
CustomCollectionEditor editor = new CustomCollectionEditor(ArrayList.class);
|
||||
editor.setValue(new int[] {0, 1, 2});
|
||||
Object value = editor.getValue();
|
||||
assertNotNull(value);
|
||||
assertTrue(value instanceof ArrayList);
|
||||
List list = (List) value;
|
||||
List<?> list = (List<?>) value;
|
||||
assertEquals("There must be 3 elements in the converted collection", 3, list.size());
|
||||
assertEquals(new Integer(0), list.get(0));
|
||||
assertEquals(new Integer(1), list.get(1));
|
||||
assertEquals(new Integer(2), list.get(2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWhenTargetTypeIsExactlyTheCollectionInterfaceUsesFallbackCollectionType() throws Exception {
|
||||
CustomCollectionEditor editor = new CustomCollectionEditor(Collection.class);
|
||||
editor.setValue("0, 1, 2");
|
||||
Collection value = (Collection) editor.getValue();
|
||||
Collection<?> value = (Collection<?>) editor.getValue();
|
||||
assertNotNull(value);
|
||||
assertEquals("There must be 1 element in the converted collection", 1, value.size());
|
||||
assertEquals("0, 1, 2", value.iterator().next());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSunnyDaySetAsTextYieldsSingleValue() throws Exception {
|
||||
CustomCollectionEditor editor = new CustomCollectionEditor(ArrayList.class);
|
||||
editor.setValue("0, 1, 2");
|
||||
Object value = editor.getValue();
|
||||
assertNotNull(value);
|
||||
assertTrue(value instanceof ArrayList);
|
||||
List list = (List) value;
|
||||
List<?> list = (List<?>) value;
|
||||
assertEquals("There must be 1 element in the converted collection", 1, list.size());
|
||||
assertEquals("0, 1, 2", list.get(0));
|
||||
}
|
||||
|
||||
|
||||
private static final class CollectionTypeWithNoNoArgCtor extends ArrayList {
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
private static final class CollectionTypeWithNoNoArgCtor extends ArrayList<Object> {
|
||||
public CollectionTypeWithNoNoArgCtor(String anArg) {
|
||||
}
|
||||
}
|
|
@ -16,6 +16,8 @@
|
|||
|
||||
package org.springframework.beans.propertyeditors;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.beans.PropertyEditor;
|
||||
import java.beans.PropertyEditorSupport;
|
||||
import java.beans.PropertyVetoException;
|
||||
|
@ -36,8 +38,7 @@ import java.util.StringTokenizer;
|
|||
import java.util.Vector;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.BeanWrapper;
|
||||
import org.springframework.beans.BeanWrapperImpl;
|
||||
import org.springframework.beans.BeansException;
|
||||
|
@ -48,7 +49,6 @@ import org.springframework.beans.MutablePropertyValues;
|
|||
import org.springframework.beans.NumberTestBean;
|
||||
import org.springframework.beans.PropertyValue;
|
||||
import org.springframework.beans.TestBean;
|
||||
import org.springframework.test.AssertThrows;
|
||||
|
||||
/**
|
||||
* Unit tests for the various PropertyEditors in Spring.
|
||||
|
@ -57,11 +57,13 @@ import org.springframework.test.AssertThrows;
|
|||
* @author Rick Evans
|
||||
* @author Rob Harrop
|
||||
* @author Arjen Poutsma
|
||||
* @author Chris Beams
|
||||
*
|
||||
* @since 10.06.2003
|
||||
*/
|
||||
public class CustomEditorTests extends TestCase {
|
||||
public class CustomEditorTests {
|
||||
|
||||
@Test
|
||||
public void testComplexObject() {
|
||||
TestBean tb = new TestBean();
|
||||
String newName = "Rod";
|
||||
|
@ -80,6 +82,7 @@ public class CustomEditorTests extends TestCase {
|
|||
tb.getSpouse().getName().equals("Kerry") && tb.getSpouse().getAge() == 34);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testComplexObjectWithOldValueAccess() {
|
||||
TestBean tb = new TestBean();
|
||||
String newName = "Rod";
|
||||
|
@ -104,6 +107,7 @@ public class CustomEditorTests extends TestCase {
|
|||
assertSame("Should have remained same object", spouse, tb.getSpouse());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCustomEditorForSingleProperty() {
|
||||
TestBean tb = new TestBean();
|
||||
BeanWrapper bw = new BeanWrapperImpl(tb);
|
||||
|
@ -120,6 +124,7 @@ public class CustomEditorTests extends TestCase {
|
|||
assertEquals("value", tb.getTouchy());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCustomEditorForAllStringProperties() {
|
||||
TestBean tb = new TestBean();
|
||||
BeanWrapper bw = new BeanWrapperImpl(tb);
|
||||
|
@ -136,6 +141,7 @@ public class CustomEditorTests extends TestCase {
|
|||
assertEquals("prefixvalue", tb.getTouchy());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCustomEditorForSingleNestedProperty() {
|
||||
TestBean tb = new TestBean();
|
||||
tb.setSpouse(new TestBean());
|
||||
|
@ -153,6 +159,7 @@ public class CustomEditorTests extends TestCase {
|
|||
assertEquals("value", tb.getTouchy());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCustomEditorForAllNestedStringProperties() {
|
||||
TestBean tb = new TestBean();
|
||||
tb.setSpouse(new TestBean());
|
||||
|
@ -170,6 +177,7 @@ public class CustomEditorTests extends TestCase {
|
|||
assertEquals("prefixvalue", tb.getTouchy());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefaultBooleanEditorForPrimitiveType() {
|
||||
BooleanTestBean tb = new BooleanTestBean();
|
||||
BeanWrapper bw = new BeanWrapperImpl(tb);
|
||||
|
@ -215,6 +223,7 @@ public class CustomEditorTests extends TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefaultBooleanEditorForWrapperType() {
|
||||
BooleanTestBean tb = new BooleanTestBean();
|
||||
BeanWrapper bw = new BeanWrapperImpl(tb);
|
||||
|
@ -249,6 +258,7 @@ public class CustomEditorTests extends TestCase {
|
|||
assertNull("Correct bool2 value", tb.getBool2());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCustomBooleanEditorWithAllowEmpty() {
|
||||
BooleanTestBean tb = new BooleanTestBean();
|
||||
BeanWrapper bw = new BeanWrapperImpl(tb);
|
||||
|
@ -285,6 +295,7 @@ public class CustomEditorTests extends TestCase {
|
|||
assertTrue("Correct bool2 value", tb.getBool2() == null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCustomBooleanEditorWithSpecialTrueAndFalseStrings() throws Exception {
|
||||
final String trueString = "pechorin";
|
||||
final String falseString = "nash";
|
||||
|
@ -306,6 +317,7 @@ public class CustomEditorTests extends TestCase {
|
|||
assertEquals(falseString, editor.getAsText());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefaultNumberEditor() {
|
||||
NumberTestBean tb = new NumberTestBean();
|
||||
BeanWrapper bw = new BeanWrapperImpl(tb);
|
||||
|
@ -349,6 +361,7 @@ public class CustomEditorTests extends TestCase {
|
|||
assertTrue("Correct bigDecimal value", new BigDecimal("4.5").equals(tb.getBigDecimal()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCustomNumberEditorWithoutAllowEmpty() {
|
||||
NumberFormat nf = NumberFormat.getNumberInstance(Locale.GERMAN);
|
||||
NumberTestBean tb = new NumberTestBean();
|
||||
|
@ -405,22 +418,17 @@ public class CustomEditorTests extends TestCase {
|
|||
assertTrue("Correct bigDecimal value", new BigDecimal("4.5").equals(tb.getBigDecimal()));
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testCustomNumberEditorCtorWithNullNumberType() throws Exception {
|
||||
new AssertThrows(IllegalArgumentException.class) {
|
||||
public void test() throws Exception {
|
||||
new CustomNumberEditor(null, true);
|
||||
}
|
||||
}.runTest();
|
||||
new CustomNumberEditor(null, true);
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testCustomNumberEditorCtorWithNonNumberType() throws Exception {
|
||||
new AssertThrows(IllegalArgumentException.class) {
|
||||
public void test() throws Exception {
|
||||
new CustomNumberEditor(String.class, true);
|
||||
}
|
||||
}.runTest();
|
||||
new CustomNumberEditor(String.class, true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCustomNumberEditorWithAllowEmpty() {
|
||||
NumberFormat nf = NumberFormat.getNumberInstance(Locale.GERMAN);
|
||||
NumberTestBean tb = new NumberTestBean();
|
||||
|
@ -450,6 +458,7 @@ public class CustomEditorTests extends TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCustomNumberEditorWithFrenchBigDecimal() throws Exception {
|
||||
NumberFormat nf = NumberFormat.getNumberInstance(Locale.FRENCH);
|
||||
NumberTestBean tb = new NumberTestBean();
|
||||
|
@ -463,15 +472,18 @@ public class CustomEditorTests extends TestCase {
|
|||
assertEquals(1000.5f, tb.getBigDecimal().floatValue(), 0f);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseShortGreaterThanMaxValueWithoutNumberFormat() {
|
||||
new AssertThrows(NumberFormatException.class, Short.MAX_VALUE + 1 + " is greater than max value") {
|
||||
public void test() throws Exception {
|
||||
CustomNumberEditor editor = new CustomNumberEditor(Short.class, true);
|
||||
editor.setAsText(String.valueOf(Short.MAX_VALUE + 1));
|
||||
}
|
||||
}.runTest();
|
||||
try {
|
||||
CustomNumberEditor editor = new CustomNumberEditor(Short.class, true);
|
||||
editor.setAsText(String.valueOf(Short.MAX_VALUE + 1));
|
||||
fail(Short.MAX_VALUE + 1 + " is greater than max value");
|
||||
} catch (NumberFormatException ex) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testByteArrayPropertyEditor() {
|
||||
PrimitiveArrayBean bean = new PrimitiveArrayBean();
|
||||
BeanWrapper bw = new BeanWrapperImpl(bean);
|
||||
|
@ -479,6 +491,7 @@ public class CustomEditorTests extends TestCase {
|
|||
assertEquals("myvalue", new String(bean.getByteArray()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCharArrayPropertyEditor() {
|
||||
PrimitiveArrayBean bean = new PrimitiveArrayBean();
|
||||
BeanWrapper bw = new BeanWrapperImpl(bean);
|
||||
|
@ -486,6 +499,7 @@ public class CustomEditorTests extends TestCase {
|
|||
assertEquals("myvalue", new String(bean.getCharArray()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCharacterEditor() {
|
||||
CharBean cb = new CharBean();
|
||||
BeanWrapper bw = new BeanWrapperImpl(cb);
|
||||
|
@ -507,6 +521,7 @@ public class CustomEditorTests extends TestCase {
|
|||
assertEquals("M", editor.getAsText());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCharacterEditorWithAllowEmpty() {
|
||||
CharBean cb = new CharBean();
|
||||
BeanWrapper bw = new BeanWrapperImpl(cb);
|
||||
|
@ -528,15 +543,13 @@ public class CustomEditorTests extends TestCase {
|
|||
assertNull(cb.getMyCharacter());
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testCharacterEditorSetAsTextWithStringLongerThanOneCharacter() throws Exception {
|
||||
new AssertThrows(IllegalArgumentException.class) {
|
||||
public void test() throws Exception {
|
||||
PropertyEditor charEditor = new CharacterEditor(false);
|
||||
charEditor.setAsText("ColdWaterCanyon");
|
||||
}
|
||||
}.runTest();
|
||||
PropertyEditor charEditor = new CharacterEditor(false);
|
||||
charEditor.setAsText("ColdWaterCanyon");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCharacterEditorGetAsTextReturnsEmptyStringIfValueIsNull() throws Exception {
|
||||
PropertyEditor charEditor = new CharacterEditor(false);
|
||||
assertEquals("", charEditor.getAsText());
|
||||
|
@ -549,15 +562,13 @@ public class CustomEditorTests extends TestCase {
|
|||
assertEquals(" ", charEditor.getAsText());
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testCharacterEditorSetAsTextWithNullNotAllowingEmptyAsNull() throws Exception {
|
||||
new AssertThrows(IllegalArgumentException.class) {
|
||||
public void test() throws Exception {
|
||||
PropertyEditor charEditor = new CharacterEditor(false);
|
||||
charEditor.setAsText(null);
|
||||
}
|
||||
}.runTest();
|
||||
PropertyEditor charEditor = new CharacterEditor(false);
|
||||
charEditor.setAsText(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClassEditor() {
|
||||
PropertyEditor classEditor = new ClassEditor();
|
||||
classEditor.setAsText("org.springframework.beans.TestBean");
|
||||
|
@ -572,15 +583,13 @@ public class CustomEditorTests extends TestCase {
|
|||
assertEquals("", classEditor.getAsText());
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testClassEditorWithNonExistentClass() throws Exception {
|
||||
new AssertThrows(IllegalArgumentException.class) {
|
||||
public void test() throws Exception {
|
||||
PropertyEditor classEditor = new ClassEditor();
|
||||
classEditor.setAsText("hairdresser.on.Fire");
|
||||
}
|
||||
}.runTest();
|
||||
PropertyEditor classEditor = new ClassEditor();
|
||||
classEditor.setAsText("hairdresser.on.Fire");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClassEditorWithArray() {
|
||||
PropertyEditor classEditor = new ClassEditor();
|
||||
classEditor.setAsText("org.springframework.beans.TestBean[]");
|
||||
|
@ -591,6 +600,7 @@ public class CustomEditorTests extends TestCase {
|
|||
/*
|
||||
* SPR_2165 - ClassEditor is inconsistent with multidimensional arrays
|
||||
*/
|
||||
@Test
|
||||
public void testGetAsTextWithTwoDimensionalArray() throws Exception {
|
||||
String[][] chessboard = new String[8][8];
|
||||
ClassEditor editor = new ClassEditor();
|
||||
|
@ -601,6 +611,7 @@ public class CustomEditorTests extends TestCase {
|
|||
/*
|
||||
* SPR_2165 - ClassEditor is inconsistent with multidimensional arrays
|
||||
*/
|
||||
@Test
|
||||
public void testGetAsTextWithRidiculousMultiDimensionalArray() throws Exception {
|
||||
String[][][][][] ridiculousChessboard = new String[8][4][0][1][3];
|
||||
ClassEditor editor = new ClassEditor();
|
||||
|
@ -608,6 +619,7 @@ public class CustomEditorTests extends TestCase {
|
|||
assertEquals("java.lang.String[][][][][]", editor.getAsText());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFileEditor() {
|
||||
PropertyEditor fileEditor = new FileEditor();
|
||||
fileEditor.setAsText("file:myfile.txt");
|
||||
|
@ -615,6 +627,7 @@ public class CustomEditorTests extends TestCase {
|
|||
assertEquals((new File("myfile.txt")).getPath(), fileEditor.getAsText());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFileEditorWithRelativePath() {
|
||||
PropertyEditor fileEditor = new FileEditor();
|
||||
try {
|
||||
|
@ -626,6 +639,7 @@ public class CustomEditorTests extends TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFileEditorWithAbsolutePath() {
|
||||
PropertyEditor fileEditor = new FileEditor();
|
||||
// testing on Windows
|
||||
|
@ -640,6 +654,7 @@ public class CustomEditorTests extends TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLocaleEditor() {
|
||||
PropertyEditor localeEditor = new LocaleEditor();
|
||||
localeEditor.setAsText("en_CA");
|
||||
|
@ -650,6 +665,7 @@ public class CustomEditorTests extends TestCase {
|
|||
assertEquals("", localeEditor.getAsText());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPatternEditor() {
|
||||
final String REGEX = "a.*";
|
||||
|
||||
|
@ -666,6 +682,7 @@ public class CustomEditorTests extends TestCase {
|
|||
assertEquals("", patternEditor.getAsText());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCustomBooleanEditor() {
|
||||
CustomBooleanEditor editor = new CustomBooleanEditor(false);
|
||||
editor.setAsText("true");
|
||||
|
@ -679,6 +696,7 @@ public class CustomEditorTests extends TestCase {
|
|||
assertEquals("", editor.getAsText());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCustomBooleanEditorWithEmptyAsNull() {
|
||||
CustomBooleanEditor editor = new CustomBooleanEditor(true);
|
||||
editor.setAsText("true");
|
||||
|
@ -692,6 +710,7 @@ public class CustomEditorTests extends TestCase {
|
|||
assertEquals("", editor.getAsText());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCustomDateEditor() {
|
||||
CustomDateEditor editor = new CustomDateEditor(null, false);
|
||||
editor.setValue(null);
|
||||
|
@ -699,6 +718,7 @@ public class CustomEditorTests extends TestCase {
|
|||
assertEquals("", editor.getAsText());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCustomDateEditorWithEmptyAsNull() {
|
||||
CustomDateEditor editor = new CustomDateEditor(null, true);
|
||||
editor.setValue(null);
|
||||
|
@ -706,6 +726,7 @@ public class CustomEditorTests extends TestCase {
|
|||
assertEquals("", editor.getAsText());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCustomDateEditorWithExactDateLength() {
|
||||
int maxLength = 10;
|
||||
String validDate = "01/01/2005";
|
||||
|
@ -733,6 +754,7 @@ public class CustomEditorTests extends TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCustomNumberEditor() {
|
||||
CustomNumberEditor editor = new CustomNumberEditor(Integer.class, false);
|
||||
editor.setAsText("5");
|
||||
|
@ -743,12 +765,14 @@ public class CustomEditorTests extends TestCase {
|
|||
assertEquals("", editor.getAsText());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCustomNumberEditorWithHex() {
|
||||
CustomNumberEditor editor = new CustomNumberEditor(Integer.class, false);
|
||||
editor.setAsText("0x" + Integer.toHexString(64));
|
||||
assertEquals(new Integer(64), editor.getValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCustomNumberEditorWithEmptyAsNull() {
|
||||
CustomNumberEditor editor = new CustomNumberEditor(Integer.class, true);
|
||||
editor.setAsText("5");
|
||||
|
@ -762,6 +786,7 @@ public class CustomEditorTests extends TestCase {
|
|||
assertEquals("", editor.getAsText());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStringTrimmerEditor() {
|
||||
StringTrimmerEditor editor = new StringTrimmerEditor(false);
|
||||
editor.setAsText("test");
|
||||
|
@ -779,6 +804,7 @@ public class CustomEditorTests extends TestCase {
|
|||
assertEquals("", editor.getAsText());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStringTrimmerEditorWithEmptyAsNull() {
|
||||
StringTrimmerEditor editor = new StringTrimmerEditor(true);
|
||||
editor.setAsText("test");
|
||||
|
@ -794,6 +820,7 @@ public class CustomEditorTests extends TestCase {
|
|||
assertEquals("", editor.getAsText());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStringTrimmerEditorWithCharsToDelete() {
|
||||
StringTrimmerEditor editor = new StringTrimmerEditor("\r\n\f", false);
|
||||
editor.setAsText("te\ns\ft");
|
||||
|
@ -809,6 +836,7 @@ public class CustomEditorTests extends TestCase {
|
|||
assertEquals("", editor.getAsText());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStringTrimmerEditorWithCharsToDeleteAndEmptyAsNull() {
|
||||
StringTrimmerEditor editor = new StringTrimmerEditor("\r\n\f", true);
|
||||
editor.setAsText("te\ns\ft");
|
||||
|
@ -824,6 +852,7 @@ public class CustomEditorTests extends TestCase {
|
|||
assertEquals("", editor.getAsText());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIndexedPropertiesWithCustomEditorForType() {
|
||||
IndexedTestBean bean = new IndexedTestBean();
|
||||
BeanWrapper bw = new BeanWrapperImpl(bean);
|
||||
|
@ -875,6 +904,7 @@ public class CustomEditorTests extends TestCase {
|
|||
assertEquals("prefixname0", bw.getPropertyValue("map['key2'].name"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIndexedPropertiesWithCustomEditorForProperty() {
|
||||
IndexedTestBean bean = new IndexedTestBean(false);
|
||||
BeanWrapper bw = new BeanWrapperImpl(bean);
|
||||
|
@ -938,6 +968,7 @@ public class CustomEditorTests extends TestCase {
|
|||
assertEquals("mapname0", bw.getPropertyValue("map['key2'].name"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIndexedPropertiesWithIndividualCustomEditorForProperty() {
|
||||
IndexedTestBean bean = new IndexedTestBean(false);
|
||||
BeanWrapper bw = new BeanWrapperImpl(bean);
|
||||
|
@ -1016,6 +1047,7 @@ public class CustomEditorTests extends TestCase {
|
|||
assertEquals("mapkey2name0", bw.getPropertyValue("map['key2'].name"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNestedIndexedPropertiesWithCustomEditorForProperty() {
|
||||
IndexedTestBean bean = new IndexedTestBean();
|
||||
TestBean tb0 = bean.getArray()[0];
|
||||
|
@ -1093,6 +1125,7 @@ public class CustomEditorTests extends TestCase {
|
|||
assertEquals("mapname0", bw.getPropertyValue("map[key2].nestedIndexedBean.map[\"key2\"].name"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNestedIndexedPropertiesWithIndexedCustomEditorForProperty() {
|
||||
IndexedTestBean bean = new IndexedTestBean();
|
||||
TestBean tb0 = bean.getArray()[0];
|
||||
|
@ -1140,6 +1173,7 @@ public class CustomEditorTests extends TestCase {
|
|||
assertEquals("name0", ((TestBean) tb5.getNestedIndexedBean().getMap().get("key2")).getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIndexedPropertiesWithDirectAccessAndPropertyEditors() {
|
||||
IndexedTestBean bean = new IndexedTestBean();
|
||||
BeanWrapper bw = new BeanWrapperImpl(bean);
|
||||
|
@ -1187,6 +1221,7 @@ public class CustomEditorTests extends TestCase {
|
|||
assertEquals("mapf", ((TestBean) bean.getMap().get("key2")).getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIndexedPropertiesWithDirectAccessAndSpecificPropertyEditors() {
|
||||
IndexedTestBean bean = new IndexedTestBean();
|
||||
BeanWrapper bw = new BeanWrapperImpl(bean);
|
||||
|
@ -1261,12 +1296,13 @@ public class CustomEditorTests extends TestCase {
|
|||
assertEquals("mapkey2f", ((TestBean) bean.getMap().get("key2")).getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIndexedPropertiesWithListPropertyEditor() {
|
||||
IndexedTestBean bean = new IndexedTestBean();
|
||||
BeanWrapper bw = new BeanWrapperImpl(bean);
|
||||
bw.registerCustomEditor(List.class, "list", new PropertyEditorSupport() {
|
||||
public void setAsText(String text) throws IllegalArgumentException {
|
||||
List result = new ArrayList();
|
||||
List<TestBean> result = new ArrayList<TestBean>();
|
||||
result.add(new TestBean("list" + text, 99));
|
||||
setValue(result);
|
||||
}
|
||||
|
@ -1277,6 +1313,7 @@ public class CustomEditorTests extends TestCase {
|
|||
assertEquals("test", bean.getList().get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConversionToOldCollections() throws PropertyVetoException {
|
||||
OldCollectionsBean tb = new OldCollectionsBean();
|
||||
BeanWrapper bw = new BeanWrapperImpl(tb);
|
||||
|
@ -1293,13 +1330,14 @@ public class CustomEditorTests extends TestCase {
|
|||
assertEquals("bar", tb.getHashtable().get("foo"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUninitializedArrayPropertyWithCustomEditor() {
|
||||
IndexedTestBean bean = new IndexedTestBean(false);
|
||||
BeanWrapper bw = new BeanWrapperImpl(bean);
|
||||
PropertyEditor pe = new CustomNumberEditor(Integer.class, true);
|
||||
bw.registerCustomEditor(null, "list.age", pe);
|
||||
TestBean tb = new TestBean();
|
||||
bw.setPropertyValue("list", new ArrayList());
|
||||
bw.setPropertyValue("list", new ArrayList<Object>());
|
||||
bw.setPropertyValue("list[0]", tb);
|
||||
assertEquals(tb, bean.getList().get(0));
|
||||
assertEquals(pe, bw.findCustomEditor(int.class, "list.age"));
|
||||
|
@ -1308,6 +1346,7 @@ public class CustomEditorTests extends TestCase {
|
|||
assertEquals(pe, bw.findCustomEditor(null, "list[0].age"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testArrayToArrayConversion() throws PropertyVetoException {
|
||||
IndexedTestBean tb = new IndexedTestBean();
|
||||
BeanWrapper bw = new BeanWrapperImpl(tb);
|
||||
|
@ -1322,6 +1361,7 @@ public class CustomEditorTests extends TestCase {
|
|||
assertEquals("b", tb.getArray()[1].getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testArrayToStringConversion() throws PropertyVetoException {
|
||||
TestBean tb = new TestBean();
|
||||
BeanWrapper bw = new BeanWrapperImpl(tb);
|
||||
|
@ -1334,10 +1374,11 @@ public class CustomEditorTests extends TestCase {
|
|||
assertEquals("-a,b-", tb.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClassArrayEditorSunnyDay() throws Exception {
|
||||
ClassArrayEditor classArrayEditor = new ClassArrayEditor();
|
||||
classArrayEditor.setAsText("java.lang.String,java.util.HashMap");
|
||||
Class[] classes = (Class[]) classArrayEditor.getValue();
|
||||
Class<?>[] classes = (Class<?>[]) classArrayEditor.getValue();
|
||||
assertEquals(2, classes.length);
|
||||
assertEquals(String.class, classes[0]);
|
||||
assertEquals(HashMap.class, classes[1]);
|
||||
|
@ -1346,10 +1387,11 @@ public class CustomEditorTests extends TestCase {
|
|||
classArrayEditor.setAsText(classArrayEditor.getAsText());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClassArrayEditorSunnyDayWithArrayTypes() throws Exception {
|
||||
ClassArrayEditor classArrayEditor = new ClassArrayEditor();
|
||||
classArrayEditor.setAsText("java.lang.String[],java.util.Map[],int[],float[][][]");
|
||||
Class[] classes = (Class[]) classArrayEditor.getValue();
|
||||
Class<?>[] classes = (Class<?>[]) classArrayEditor.getValue();
|
||||
assertEquals(4, classes.length);
|
||||
assertEquals(String[].class, classes[0]);
|
||||
assertEquals(Map[].class, classes[1]);
|
||||
|
@ -1360,6 +1402,7 @@ public class CustomEditorTests extends TestCase {
|
|||
classArrayEditor.setAsText(classArrayEditor.getAsText());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClassArrayEditorSetAsTextWithNull() throws Exception {
|
||||
ClassArrayEditor editor = new ClassArrayEditor();
|
||||
editor.setAsText(null);
|
||||
|
@ -1367,6 +1410,7 @@ public class CustomEditorTests extends TestCase {
|
|||
assertEquals("", editor.getAsText());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClassArrayEditorSetAsTextWithEmptyString() throws Exception {
|
||||
ClassArrayEditor editor = new ClassArrayEditor();
|
||||
editor.setAsText("");
|
||||
|
@ -1374,6 +1418,7 @@ public class CustomEditorTests extends TestCase {
|
|||
assertEquals("", editor.getAsText());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClassArrayEditorSetAsTextWithWhitespaceString() throws Exception {
|
||||
ClassArrayEditor editor = new ClassArrayEditor();
|
||||
editor.setAsText("\n");
|
||||
|
@ -1381,6 +1426,7 @@ public class CustomEditorTests extends TestCase {
|
|||
assertEquals("", editor.getAsText());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCharsetEditor() throws Exception {
|
||||
CharsetEditor editor = new CharsetEditor();
|
||||
String name = "UTF-8";
|
||||
|
@ -1468,23 +1514,23 @@ public class CustomEditorTests extends TestCase {
|
|||
|
||||
private static class OldCollectionsBean {
|
||||
|
||||
private Vector vector;
|
||||
private Vector<?> vector;
|
||||
|
||||
private Hashtable hashtable;
|
||||
private Hashtable<?, ?> hashtable;
|
||||
|
||||
public Vector getVector() {
|
||||
public Vector<?> getVector() {
|
||||
return vector;
|
||||
}
|
||||
|
||||
public void setVector(Vector vector) {
|
||||
public void setVector(Vector<?> vector) {
|
||||
this.vector = vector;
|
||||
}
|
||||
|
||||
public Hashtable getHashtable() {
|
||||
public Hashtable<?, ?> getHashtable() {
|
||||
return hashtable;
|
||||
}
|
||||
|
||||
public void setHashtable(Hashtable hashtable) {
|
||||
public void setHashtable(Hashtable<?, ?> hashtable) {
|
||||
this.hashtable = hashtable;
|
||||
}
|
||||
}
|
|
@ -1,19 +1,36 @@
|
|||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.beans.propertyeditors;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.beans.PropertyEditor;
|
||||
import java.io.File;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.test.AssertThrows;
|
||||
import org.junit.Test;
|
||||
import org.springframework.util.ClassUtils;
|
||||
|
||||
/**
|
||||
* @author Thomas Risberg
|
||||
* @author Chris Beams
|
||||
*/
|
||||
public final class FileEditorTests extends TestCase {
|
||||
public final class FileEditorTests {
|
||||
|
||||
@Test
|
||||
public void testClasspathFileName() throws Exception {
|
||||
PropertyEditor fileEditor = new FileEditor();
|
||||
fileEditor.setAsText("classpath:" + ClassUtils.classPackageAsResourcePath(getClass()) + "/"
|
||||
|
@ -24,16 +41,13 @@ public final class FileEditorTests extends TestCase {
|
|||
assertTrue(file.exists());
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testWithNonExistentResource() throws Exception {
|
||||
new AssertThrows(IllegalArgumentException.class) {
|
||||
|
||||
public void test() throws Exception {
|
||||
PropertyEditor propertyEditor = new FileEditor();
|
||||
propertyEditor.setAsText("classpath:no_way_this_file_is_found.doc");
|
||||
}
|
||||
}.runTest();
|
||||
PropertyEditor propertyEditor = new FileEditor();
|
||||
propertyEditor.setAsText("classpath:no_way_this_file_is_found.doc");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithNonExistentFile() throws Exception {
|
||||
PropertyEditor fileEditor = new FileEditor();
|
||||
fileEditor.setAsText("file:no_way_this_file_is_found.doc");
|
||||
|
@ -43,6 +57,7 @@ public final class FileEditorTests extends TestCase {
|
|||
assertTrue(!file.exists());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAbsoluteFileName() throws Exception {
|
||||
PropertyEditor fileEditor = new FileEditor();
|
||||
fileEditor.setAsText("/no_way_this_file_is_found.doc");
|
||||
|
@ -52,6 +67,7 @@ public final class FileEditorTests extends TestCase {
|
|||
assertTrue(!file.exists());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnqualifiedFileNameFound() throws Exception {
|
||||
PropertyEditor fileEditor = new FileEditor();
|
||||
String fileName = ClassUtils.classPackageAsResourcePath(getClass()) + "/" + ClassUtils.getShortName(getClass())
|
||||
|
@ -68,6 +84,7 @@ public final class FileEditorTests extends TestCase {
|
|||
assertTrue(absolutePath.endsWith(fileName));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnqualifiedFileNameNotFound() throws Exception {
|
||||
PropertyEditor fileEditor = new FileEditor();
|
||||
String fileName = ClassUtils.classPackageAsResourcePath(getClass()) + "/" + ClassUtils.getShortName(getClass())
|
|
@ -16,27 +16,27 @@
|
|||
|
||||
package org.springframework.beans.propertyeditors;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.springframework.test.AssertThrows;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.util.ClassUtils;
|
||||
|
||||
/**
|
||||
* Unit tests for the {@link InputStreamEditor} class.
|
||||
*
|
||||
* @author Rick Evans
|
||||
* @author Chris Beams
|
||||
*/
|
||||
public final class InputStreamEditorTests extends TestCase {
|
||||
public final class InputStreamEditorTests {
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testCtorWithNullResourceEditor() throws Exception {
|
||||
new AssertThrows(IllegalArgumentException.class) {
|
||||
public void test() throws Exception {
|
||||
new InputStreamEditor(null);
|
||||
}
|
||||
}.runTest();
|
||||
new InputStreamEditor(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSunnyDay() throws Exception {
|
||||
InputStream stream = null;
|
||||
try {
|
||||
|
@ -55,16 +55,14 @@ public final class InputStreamEditorTests extends TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testWhenResourceDoesNotExist() throws Exception {
|
||||
new AssertThrows(IllegalArgumentException.class) {
|
||||
public void test() throws Exception {
|
||||
String resource = "classpath:bingo!";
|
||||
InputStreamEditor editor = new InputStreamEditor();
|
||||
editor.setAsText(resource);
|
||||
}
|
||||
}.runTest();
|
||||
String resource = "classpath:bingo!";
|
||||
InputStreamEditor editor = new InputStreamEditor();
|
||||
editor.setAsText(resource);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAsTextReturnsNullByDefault() throws Exception {
|
||||
assertNull(new InputStreamEditor().getAsText());
|
||||
String resource = "classpath:" + ClassUtils.classPackageAsResourcePath(getClass()) + "/" + ClassUtils.getShortName(getClass()) + ".class";
|
|
@ -16,22 +16,25 @@
|
|||
|
||||
package org.springframework.beans.propertyeditors;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.springframework.test.AssertThrows;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Unit tests for the {@link ResourceBundleEditor} class.
|
||||
*
|
||||
* @author Rick Evans
|
||||
* @author Chris Beams
|
||||
*/
|
||||
public final class ResourceBundleEditorTests extends TestCase {
|
||||
public final class ResourceBundleEditorTests {
|
||||
|
||||
private static final String BASE_NAME = ResourceBundleEditorTests.class.getName();
|
||||
private static final String MESSAGE_KEY = "punk";
|
||||
|
||||
|
||||
@Test
|
||||
public void testSetAsTextWithJustBaseName() throws Exception {
|
||||
ResourceBundleEditor editor = new ResourceBundleEditor();
|
||||
editor.setAsText(BASE_NAME);
|
||||
|
@ -43,6 +46,7 @@ public final class ResourceBundleEditorTests extends TestCase {
|
|||
assertEquals(MESSAGE_KEY, string);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetAsTextWithBaseNameThatEndsInDefaultSeparator() throws Exception {
|
||||
ResourceBundleEditor editor = new ResourceBundleEditor();
|
||||
editor.setAsText(BASE_NAME + "_");
|
||||
|
@ -54,6 +58,7 @@ public final class ResourceBundleEditorTests extends TestCase {
|
|||
assertEquals(MESSAGE_KEY, string);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetAsTextWithBaseNameAndLanguageCode() throws Exception {
|
||||
ResourceBundleEditor editor = new ResourceBundleEditor();
|
||||
editor.setAsText(BASE_NAME + "Lang" + "_en");
|
||||
|
@ -65,6 +70,7 @@ public final class ResourceBundleEditorTests extends TestCase {
|
|||
assertEquals("yob", string);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetAsTextWithBaseNameLanguageAndCountryCode() throws Exception {
|
||||
ResourceBundleEditor editor = new ResourceBundleEditor();
|
||||
editor.setAsText(BASE_NAME + "LangCountry" + "_en_GB");
|
||||
|
@ -76,6 +82,7 @@ public final class ResourceBundleEditorTests extends TestCase {
|
|||
assertEquals("chav", string);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetAsTextWithTheKitchenSink() throws Exception {
|
||||
ResourceBundleEditor editor = new ResourceBundleEditor();
|
||||
editor.setAsText(BASE_NAME + "LangCountryDialect" + "_en_GB_GLASGOW");
|
||||
|
@ -87,40 +94,28 @@ public final class ResourceBundleEditorTests extends TestCase {
|
|||
assertEquals("ned", string);
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testSetAsTextWithNull() throws Exception {
|
||||
new AssertThrows(IllegalArgumentException.class) {
|
||||
public void test() throws Exception {
|
||||
ResourceBundleEditor editor = new ResourceBundleEditor();
|
||||
editor.setAsText(null);
|
||||
}
|
||||
}.runTest();
|
||||
ResourceBundleEditor editor = new ResourceBundleEditor();
|
||||
editor.setAsText(null);
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testSetAsTextWithEmptyString() throws Exception {
|
||||
new AssertThrows(IllegalArgumentException.class) {
|
||||
public void test() throws Exception {
|
||||
ResourceBundleEditor editor = new ResourceBundleEditor();
|
||||
editor.setAsText("");
|
||||
}
|
||||
}.runTest();
|
||||
ResourceBundleEditor editor = new ResourceBundleEditor();
|
||||
editor.setAsText("");
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testSetAsTextWithWhiteSpaceString() throws Exception {
|
||||
new AssertThrows(IllegalArgumentException.class) {
|
||||
public void test() throws Exception {
|
||||
ResourceBundleEditor editor = new ResourceBundleEditor();
|
||||
editor.setAsText(" ");
|
||||
}
|
||||
}.runTest();
|
||||
ResourceBundleEditor editor = new ResourceBundleEditor();
|
||||
editor.setAsText(" ");
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testSetAsTextWithJustSeparatorString() throws Exception {
|
||||
new AssertThrows(IllegalArgumentException.class) {
|
||||
public void test() throws Exception {
|
||||
ResourceBundleEditor editor = new ResourceBundleEditor();
|
||||
editor.setAsText("_");
|
||||
}
|
||||
}.runTest();
|
||||
ResourceBundleEditor editor = new ResourceBundleEditor();
|
||||
editor.setAsText("_");
|
||||
}
|
||||
|
||||
}
|
|
@ -16,19 +16,21 @@
|
|||
|
||||
package org.springframework.beans.propertyeditors;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.beans.PropertyEditor;
|
||||
import java.net.URL;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.test.AssertThrows;
|
||||
import org.junit.Test;
|
||||
import org.springframework.util.ClassUtils;
|
||||
|
||||
/**
|
||||
* @author Rick Evans
|
||||
* @author Chris Beams
|
||||
*/
|
||||
public final class URLEditorTests extends TestCase {
|
||||
public final class URLEditorTests {
|
||||
|
||||
@Test
|
||||
public void testStandardURI() throws Exception {
|
||||
PropertyEditor urlEditor = new URLEditor();
|
||||
urlEditor.setAsText("mailto:juergen.hoeller@interface21.com");
|
||||
|
@ -38,6 +40,7 @@ public final class URLEditorTests extends TestCase {
|
|||
assertEquals(url.toExternalForm(), urlEditor.getAsText());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStandardURL() throws Exception {
|
||||
PropertyEditor urlEditor = new URLEditor();
|
||||
urlEditor.setAsText("http://www.springframework.org");
|
||||
|
@ -47,6 +50,7 @@ public final class URLEditorTests extends TestCase {
|
|||
assertEquals(url.toExternalForm(), urlEditor.getAsText());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClasspathURL() throws Exception {
|
||||
PropertyEditor urlEditor = new URLEditor();
|
||||
urlEditor.setAsText("classpath:" + ClassUtils.classPackageAsResourcePath(getClass()) +
|
||||
|
@ -58,15 +62,13 @@ public final class URLEditorTests extends TestCase {
|
|||
assertTrue(!url.getProtocol().startsWith("classpath"));
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testWithNonExistentResource() throws Exception {
|
||||
new AssertThrows(IllegalArgumentException.class) {
|
||||
public void test() throws Exception {
|
||||
PropertyEditor urlEditor = new URLEditor();
|
||||
urlEditor.setAsText("gonna:/freak/in/the/morning/freak/in/the.evening");
|
||||
}
|
||||
}.runTest();
|
||||
PropertyEditor urlEditor = new URLEditor();
|
||||
urlEditor.setAsText("gonna:/freak/in/the/morning/freak/in/the.evening");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetAsTextWithNull() throws Exception {
|
||||
PropertyEditor urlEditor = new URLEditor();
|
||||
urlEditor.setAsText(null);
|
||||
|
@ -74,17 +76,15 @@ public final class URLEditorTests extends TestCase {
|
|||
assertEquals("", urlEditor.getAsText());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAsTextReturnsEmptyStringIfValueNotSet() throws Exception {
|
||||
PropertyEditor urlEditor = new URLEditor();
|
||||
assertEquals("", urlEditor.getAsText());
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testCtorWithNullResourceEditor() throws Exception {
|
||||
new AssertThrows(IllegalArgumentException.class) {
|
||||
public void test() throws Exception {
|
||||
new URLEditor(null);
|
||||
}
|
||||
}.runTest();
|
||||
new URLEditor(null);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue