Port to JUnit 4. Not 100% done.

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@1142704 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Gary D. Gregory 2011-07-04 15:03:00 +00:00
parent 765297b79c
commit e883181ff4
1 changed files with 64 additions and 88 deletions

View File

@ -93,22 +93,18 @@ public class FieldUtilsTest {
assertNull(FieldUtils.getField(PrivatelyShadowedChild.class, "b")); assertNull(FieldUtils.getField(PrivatelyShadowedChild.class, "b"));
assertNull(FieldUtils.getField(PrivatelyShadowedChild.class, "i")); assertNull(FieldUtils.getField(PrivatelyShadowedChild.class, "i"));
assertNull(FieldUtils.getField(PrivatelyShadowedChild.class, "d")); assertNull(FieldUtils.getField(PrivatelyShadowedChild.class, "d"));
try {
FieldUtils.getField(null, "none");
fail("null class should cause an IllegalArgumentException");
} catch (IllegalArgumentException e) {
// expected
}
try {
FieldUtils.getField(PublicChild.class, null);
fail("null field name should cause an IllegalArgumentException");
} catch (IllegalArgumentException e) {
// expected
}
} }
@Test(expected=IllegalArgumentException.class)
public void testGetFieldIllegalArgumentException1() {
FieldUtils.getField(null, "none");
}
@Test(expected=IllegalArgumentException.class)
public void testGetFieldIllegalArgumentException2() {
FieldUtils.getField(PublicChild.class, null);
}
@Test @Test
public void testGetFieldForceAccess() { public void testGetFieldForceAccess() {
assertEquals(PublicChild.class, FieldUtils.getField(PublicChild.class, "VALUE", true).getDeclaringClass()); assertEquals(PublicChild.class, FieldUtils.getField(PublicChild.class, "VALUE", true).getDeclaringClass());
@ -134,22 +130,18 @@ public class FieldUtilsTest {
.getDeclaringClass()); .getDeclaringClass());
assertEquals(PrivatelyShadowedChild.class, FieldUtils.getField(PrivatelyShadowedChild.class, "d", true) assertEquals(PrivatelyShadowedChild.class, FieldUtils.getField(PrivatelyShadowedChild.class, "d", true)
.getDeclaringClass()); .getDeclaringClass());
try {
FieldUtils.getField(null, "none", true);
fail("null class should cause an IllegalArgumentException");
} catch (IllegalArgumentException e) {
// expected
}
try {
FieldUtils.getField(PublicChild.class, null, true);
fail("null field name should cause an IllegalArgumentException");
} catch (IllegalArgumentException e) {
// expected
}
} }
@Test(expected=IllegalArgumentException.class)
public void testGetFieldForceAccessIllegalArgumentException1() {
FieldUtils.getField(null, "none", true);
}
@Test(expected=IllegalArgumentException.class)
public void testGetFieldForceAccessIllegalArgumentException2() {
FieldUtils.getField(PublicChild.class, null, true);
}
@Test @Test
public void testGetDeclaredField() { public void testGetDeclaredField() {
assertNull(FieldUtils.getDeclaredField(PublicChild.class, "VALUE")); assertNull(FieldUtils.getDeclaredField(PublicChild.class, "VALUE"));
@ -171,22 +163,18 @@ public class FieldUtilsTest {
assertNull(FieldUtils.getDeclaredField(PrivatelyShadowedChild.class, "b")); assertNull(FieldUtils.getDeclaredField(PrivatelyShadowedChild.class, "b"));
assertNull(FieldUtils.getDeclaredField(PrivatelyShadowedChild.class, "i")); assertNull(FieldUtils.getDeclaredField(PrivatelyShadowedChild.class, "i"));
assertNull(FieldUtils.getDeclaredField(PrivatelyShadowedChild.class, "d")); assertNull(FieldUtils.getDeclaredField(PrivatelyShadowedChild.class, "d"));
try {
FieldUtils.getDeclaredField(null, "none");
fail("null class should cause an IllegalArgumentException");
} catch (IllegalArgumentException e) {
// expected
}
try {
FieldUtils.getDeclaredField(PublicChild.class, null);
fail("null field name should cause an IllegalArgumentException");
} catch (IllegalArgumentException e) {
// expected
}
} }
@Test(expected=IllegalArgumentException.class)
public void testGetDeclaredFieldAccessIllegalArgumentException1() {
FieldUtils.getDeclaredField(null, "none");
}
@Test(expected=IllegalArgumentException.class)
public void testGetDeclaredFieldAccessIllegalArgumentException2() {
FieldUtils.getDeclaredField(PublicChild.class, null);
}
@Test @Test
public void testGetDeclaredFieldForceAccess() { public void testGetDeclaredFieldForceAccess() {
assertEquals(PublicChild.class, FieldUtils.getDeclaredField(PublicChild.class, "VALUE", true) assertEquals(PublicChild.class, FieldUtils.getDeclaredField(PublicChild.class, "VALUE", true)
@ -213,64 +201,52 @@ public class FieldUtilsTest {
.getDeclaringClass()); .getDeclaringClass());
assertEquals(PrivatelyShadowedChild.class, FieldUtils.getDeclaredField(PrivatelyShadowedChild.class, "d", true) assertEquals(PrivatelyShadowedChild.class, FieldUtils.getDeclaredField(PrivatelyShadowedChild.class, "d", true)
.getDeclaringClass()); .getDeclaringClass());
try {
FieldUtils.getDeclaredField(null, "none", true);
fail("null class should cause an IllegalArgumentException");
} catch (IllegalArgumentException e) {
// expected
}
try {
FieldUtils.getDeclaredField(PublicChild.class, null, true);
fail("null field name should cause an IllegalArgumentException");
} catch (IllegalArgumentException e) {
// expected
}
} }
@Test(expected=IllegalArgumentException.class)
public void testGetDeclaredFieldForceAccessIllegalArgumentException1() {
FieldUtils.getDeclaredField(null, "none", true);
}
@Test(expected=IllegalArgumentException.class)
public void testGetDeclaredFieldForceAccessIllegalArgumentException2() {
FieldUtils.getDeclaredField(PublicChild.class, null, true);
}
@Test @Test
public void testReadStaticField() throws Exception { public void testReadStaticField() throws Exception {
assertEquals(Foo.VALUE, FieldUtils.readStaticField(FieldUtils.getField(Foo.class, "VALUE"))); assertEquals(Foo.VALUE, FieldUtils.readStaticField(FieldUtils.getField(Foo.class, "VALUE")));
}
try {
FieldUtils.readStaticField(null);
fail("null field should cause an IllegalArgumentException");
} catch (IllegalArgumentException e) {
// expected
}
try { @Test(expected=IllegalArgumentException.class)
Field nonStaticField = FieldUtils.getField(PublicChild.class, "s"); public void testReadStaticFieldIllegalArgumentException1() throws Exception {
assumeNotNull(nonStaticField); FieldUtils.readStaticField(null);
FieldUtils.readStaticField(nonStaticField); }
fail("non-static field should cause an IllegalArgumentException");
} catch (IllegalArgumentException e) { @Test(expected=IllegalArgumentException.class)
// expected public void testReadStaticFieldIllegalArgumentException2() throws Exception {
} assertEquals(Foo.VALUE, FieldUtils.readStaticField(FieldUtils.getField(Foo.class, "VALUE")));
Field nonStaticField = FieldUtils.getField(PublicChild.class, "s");
assumeNotNull(nonStaticField);
FieldUtils.readStaticField(nonStaticField);
} }
@Test @Test
public void testReadStaticFieldForceAccess() throws Exception { public void testReadStaticFieldForceAccess() throws Exception {
assertEquals(Foo.VALUE, FieldUtils.readStaticField(FieldUtils.getField(Foo.class, "VALUE"))); assertEquals(Foo.VALUE, FieldUtils.readStaticField(FieldUtils.getField(Foo.class, "VALUE")));
assertEquals(Foo.VALUE, FieldUtils.readStaticField(FieldUtils.getField(PublicChild.class, "VALUE"))); assertEquals(Foo.VALUE, FieldUtils.readStaticField(FieldUtils.getField(PublicChild.class, "VALUE")));
}
try {
FieldUtils.readStaticField(null, true); @Test(expected=IllegalArgumentException.class)
fail("null field should cause an IllegalArgumentException"); public void testReadStaticFieldForceAccessIllegalArgumentException1() throws Exception {
} catch (IllegalArgumentException e) { FieldUtils.readStaticField(null, true);
// expected }
}
@Test(expected=IllegalArgumentException.class)
try { public void testReadStaticFieldForceAccessIllegalArgumentException2() throws Exception {
Field nonStaticField = FieldUtils.getField(PublicChild.class, "s", true); Field nonStaticField = FieldUtils.getField(PublicChild.class, "s", true);
assumeNotNull(nonStaticField); assumeNotNull(nonStaticField);
FieldUtils.readStaticField(nonStaticField); FieldUtils.readStaticField(nonStaticField);
fail("non-static field should cause an IllegalArgumentException");
} catch (IllegalArgumentException e) {
// expected
}
} }
@Test @Test