Browse Source

Changed use of AssertThrows to @Test(expected = ...)

git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@235 50f2f4bb-b051-0410-bef5-90022cba6387
pull/1/head
Arjen Poutsma 18 years ago
parent
commit
15dc671dd9
  1. 281
      org.springframework.testsuite/src/test/java/org/springframework/util/AssertTests.java

281
org.springframework.testsuite/src/test/java/org/springframework/util/AssertTests.java

@ -16,10 +16,15 @@
package org.springframework.util; package org.springframework.util;
import junit.framework.TestCase; import java.util.ArrayList;
import org.springframework.test.AssertThrows; import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.*; import org.junit.Test;
/** /**
* Unit tests for the {@link Assert} class. * Unit tests for the {@link Assert} class.
@ -27,158 +32,124 @@ import java.util.*;
* @author Keith Donald * @author Keith Donald
* @author Erwin Vervaet * @author Erwin Vervaet
* @author Rick Evans * @author Rick Evans
* @author Arjen Poutsma
*/ */
public class AssertTests extends TestCase { public class AssertTests {
public void testInstanceOf() { @Test(expected = IllegalArgumentException.class)
final Set set = new HashSet(); public void instanceOf() {
Assert.isInstanceOf(HashSet.class, set); final Set set = new HashSet();
new AssertThrows(IllegalArgumentException.class, "a hash map is not a set") { Assert.isInstanceOf(HashSet.class, set);
public void test() throws Exception { Assert.isInstanceOf(HashMap.class, set);
Assert.isInstanceOf(HashMap.class, set); }
}
}.runTest(); @Test
} public void isNullDoesNotThrowExceptionIfArgumentIsNullWithMessage() {
Assert.isNull(null, "Bla");
public void testIsNullDoesNotThrowExceptionIfArgumentIsNullWithMessage() { }
Assert.isNull(null, "Bla");
} @Test
public void isNullDoesNotThrowExceptionIfArgumentIsNull() {
public void testIsNullDoesNotThrowExceptionIfArgumentIsNull() { Assert.isNull(null);
Assert.isNull(null); }
}
@Test(expected = IllegalArgumentException.class)
public void testIsNullThrowsExceptionIfArgumentIsNotNull() { public void isNullThrowsExceptionIfArgumentIsNotNull() {
new AssertThrows(IllegalArgumentException.class, "object is not null") { Assert.isNull(new Object());
public void test() throws Exception { }
Assert.isNull(new Object());
} @Test(expected = IllegalArgumentException.class)
}.runTest(); public void isTrueWithFalseExpressionThrowsException() throws Exception {
} Assert.isTrue(false);
}
public void testIsNullThrowsExceptionIfArgumentIsNotNullWithMessage() {
new AssertThrows(IllegalArgumentException.class, "object is not null") { @Test
public void test() throws Exception { public void isTrueWithTrueExpressionSunnyDay() throws Exception {
Assert.isNull(new Object(), "Bla"); Assert.isTrue(true);
} }
protected void checkExceptionExpectations(Exception actualException) { @Test(expected = IllegalArgumentException.class)
assertEquals("Bla", actualException.getMessage()); public void testHasLengthWithNullStringThrowsException() throws Exception {
super.checkExceptionExpectations(actualException); Assert.hasLength(null);
} }
}.runTest();
} @Test(expected = IllegalArgumentException.class)
public void hasLengthWithEmptyStringThrowsException() throws Exception {
public void testIsTrueWithFalseExpressionThrowsException() throws Exception { Assert.hasLength("");
new AssertThrows(IllegalArgumentException.class) { }
public void test() throws Exception {
Assert.isTrue(false); @Test
} public void hasLengthWithWhitespaceOnlyStringDoesNotThrowException() throws Exception {
}.runTest(); Assert.hasLength("\t ");
} }
public void testIsTrueWithTrueExpressionSunnyDay() throws Exception { @Test
Assert.isTrue(true); public void hasLengthSunnyDay() throws Exception {
} Assert.hasLength("I Heart ...");
}
public void testHasLengthWithNullStringThrowsException() throws Exception {
new AssertThrows(IllegalArgumentException.class) { @Test
public void test() throws Exception { public void doesNotContainWithNullSearchStringDoesNotThrowException() throws Exception {
Assert.hasLength(null); Assert.doesNotContain(null, "rod");
} }
}.runTest();
} @Test
public void doesNotContainWithNullSubstringDoesNotThrowException() throws Exception {
public void testHasLengthWithEmptyStringThrowsException() throws Exception { Assert.doesNotContain("A cool chick's name is Brod. ", null);
new AssertThrows(IllegalArgumentException.class) { }
public void test() throws Exception {
Assert.hasLength(""); @Test
} public void doesNotContainWithEmptySubstringDoesNotThrowException() throws Exception {
}.runTest(); Assert.doesNotContain("A cool chick's name is Brod. ", "");
} }
public void testHasLengthWithWhitespaceOnlyStringDoesNotThrowException() throws Exception { @Test(expected = IllegalArgumentException.class)
Assert.hasLength("\t "); public void assertNotEmptyWithNullCollectionThrowsException() throws Exception {
} Assert.notEmpty((Collection) null);
}
public void testHasLengthSunnyDay() throws Exception {
Assert.hasLength("I Heart ..."); @Test(expected = IllegalArgumentException.class)
} public void assertNotEmptyWithEmptyCollectionThrowsException() throws Exception {
Assert.notEmpty(new ArrayList());
public void testDoesNotContainWithNullSearchStringDoesNotThrowException() throws Exception { }
Assert.doesNotContain(null, "rod");
} @Test
public void assertNotEmptyWithCollectionSunnyDay() throws Exception {
public void testDoesNotContainWithNullSubstringDoesNotThrowException() throws Exception { List<String> collection = new ArrayList<String>();
Assert.doesNotContain("A cool chick's name is Brod. ", null); collection.add("");
} Assert.notEmpty(collection);
}
public void testDoesNotContainWithEmptySubstringDoesNotThrowException() throws Exception {
Assert.doesNotContain("A cool chick's name is Brod. ", ""); @Test(expected = IllegalArgumentException.class)
} public void assertNotEmptyWithNullMapThrowsException() throws Exception {
Assert.notEmpty((Map) null);
public void testAssertNotEmptyWithNullCollectionThrowsException() throws Exception { }
new AssertThrows(IllegalArgumentException.class) {
public void test() throws Exception { @Test(expected = IllegalArgumentException.class)
Assert.notEmpty((Collection) null); public void assertNotEmptyWithEmptyMapThrowsException() throws Exception {
} Assert.notEmpty(new HashMap());
}.runTest(); }
}
@Test
public void testAssertNotEmptyWithEmptyCollectionThrowsException() throws Exception { public void assertNotEmptyWithMapSunnyDay() throws Exception {
new AssertThrows(IllegalArgumentException.class) { Map<String, String> map = new HashMap<String, String>();
public void test() throws Exception { map.put("", "");
Assert.notEmpty(new ArrayList()); Assert.notEmpty(map);
} }
}.runTest();
} @Test(expected = IllegalArgumentException.class)
public void isInstanceofClassWithNullInstanceThrowsException() throws Exception {
public void testAssertNotEmptyWithCollectionSunnyDay() throws Exception { Assert.isInstanceOf(String.class, null);
List collection = new ArrayList(); }
collection.add("");
Assert.notEmpty(collection); @Test(expected = IllegalStateException.class)
} public void stateWithFalseExpressionThrowsException() throws Exception {
Assert.state(false);
public void testAssertNotEmptyWithNullMapThrowsException() throws Exception { }
new AssertThrows(IllegalArgumentException.class) {
public void test() throws Exception { @Test
Assert.notEmpty((Map) null); public void stateWithTrueExpressionSunnyDay() throws Exception {
} Assert.state(true);
}.runTest(); }
}
public void testAssertNotEmptyWithEmptyMapThrowsException() throws Exception {
new AssertThrows(IllegalArgumentException.class) {
public void test() throws Exception {
Assert.notEmpty(new HashMap());
}
}.runTest();
}
public void testAssertNotEmptyWithMapSunnyDay() throws Exception {
Map map = new HashMap();
map.put("", "");
Assert.notEmpty(map);
}
public void testIsInstanceofClassWithNullInstanceThrowsException() throws Exception {
new AssertThrows(IllegalArgumentException.class) {
public void test() throws Exception {
Assert.isInstanceOf(String.class, null);
}
}.runTest();
}
public void testStateWithFalseExpressionThrowsException() throws Exception {
new AssertThrows(IllegalStateException.class) {
public void test() throws Exception {
Assert.state(false);
}
}.runTest();
}
public void testStateWithTrueExpressionSunnyDay() throws Exception {
Assert.state(true);
}
} }

Loading…
Cancel
Save