From: David S. <ds...@us...> - 2007-04-26 19:56:48
|
Update of /cvsroot/junit/junit/src/org/junit/tests In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv1805/src/org/junit/tests Modified Files: SuiteMethodTest.java AllTests.java AssertionTest.java Added Files: AnnotatedDescriptionTest.java Log Message: [Junit-trackers] [ junit-Bugs-1684562 ] assertEquals throws NPE while comparing null elements Descriptions now have Annotations --- NEW FILE: AnnotatedDescriptionTest.java --- package org.junit.tests; import static org.junit.Assert.*; import java.lang.annotation.Annotation; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import org.junit.Ignore; import org.junit.Test; import org.junit.runner.Description; import org.junit.runner.Request; public class AnnotatedDescriptionTest { @Retention(RetentionPolicy.RUNTIME) public @interface MyOwnAnnotation { } @MyOwnAnnotation public static class AnnotatedClass { @Test public void a() { } } @Test public void annotationsExistOnDescriptionsOfClasses() { assertTrue((describe(AnnotatedClass.class).getAnnotation( MyOwnAnnotation.class) != null)); } @Test public void getAnnotationsReturnsAllAnnotations() { assertEquals(1, describe(ValueAnnotatedClass.class).getAnnotations() .size()); } @Ignore public static class IgnoredClass { @Test public void a() { } } @Test public void annotationsExistOnDescriptionsOfIgnoredClass() { assertTrue((describe(IgnoredClass.class).getAnnotation(Ignore.class) != null)); } @Retention(RetentionPolicy.RUNTIME) public @interface ValuedAnnotation { String value(); } @ValuedAnnotation("hello") public static class ValueAnnotatedClass { @Test public void a() { } } @Test public void descriptionOfTestClassHasValuedAnnotation() { Description description= describe(ValueAnnotatedClass.class); assertEquals("hello", description.getAnnotation(ValuedAnnotation.class) .value()); } @Test public void characterizeCreatingMyOwnAnnotation() { Annotation annotation= new Ignore() { public String value() { return "message"; } public Class<? extends Annotation> annotationType() { return Ignore.class; } }; assertEquals(Ignore.class, annotation.annotationType()); } private Description describe(Class<?> testClass) { return Request.aClass(testClass).getRunner().getDescription(); } } Index: SuiteMethodTest.java =================================================================== RCS file: /cvsroot/junit/junit/src/org/junit/tests/SuiteMethodTest.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- SuiteMethodTest.java 6 Dec 2006 01:22:48 -0000 1.1 +++ SuiteMethodTest.java 26 Apr 2007 19:56:30 -0000 1.2 @@ -1,11 +1,15 @@ package org.junit.tests; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.*; import junit.framework.JUnit4TestAdapter; import junit.framework.TestCase; import junit.framework.TestSuite; +import org.junit.Ignore; import org.junit.Test; +import org.junit.runner.Description; import org.junit.runner.JUnitCore; +import org.junit.runner.Request; +import org.junit.runner.Result; public class SuiteMethodTest { public static boolean wasRun; @@ -47,4 +51,23 @@ JUnitCore.runClasses(NewTest.class); assertTrue(wasRun); } + + + public static class CompatibilityTest { + @Ignore @Test + public void ignored() { + } + + public static junit.framework.Test suite() { + return new JUnit4TestAdapter(CompatibilityTest.class); + } + } + + @Test public void descriptionAndRunNotificationsAreConsistent() { + Result result= JUnitCore.runClasses(CompatibilityTest.class); + assertEquals(0, result.getIgnoreCount()); + + Description description= Request.aClass(CompatibilityTest.class).getRunner().getDescription(); + assertEquals(0, description.getChildren().size()); + } } Index: AllTests.java =================================================================== RCS file: /cvsroot/junit/junit/src/org/junit/tests/AllTests.java,v retrieving revision 1.10 retrieving revision 1.11 diff -u -d -r1.10 -r1.11 --- AllTests.java 21 Feb 2007 18:24:10 -0000 1.10 +++ AllTests.java 26 Apr 2007 19:56:30 -0000 1.11 @@ -46,7 +46,8 @@ SuiteMethodTest.class, TestClassMethodsRunnerTest.class, IgnoreClassTest.class, - OldTestClassAdaptingListenerTest.class + OldTestClassAdaptingListenerTest.class, + AnnotatedDescriptionTest.class }) public class AllTests { public static Test suite() { Index: AssertionTest.java =================================================================== RCS file: /cvsroot/junit/junit/src/org/junit/tests/AssertionTest.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- AssertionTest.java 8 Feb 2007 22:45:20 -0000 1.6 +++ AssertionTest.java 26 Apr 2007 19:56:30 -0000 1.7 @@ -193,6 +193,36 @@ assertEquals(1.0d, 1.0d, 0.0d); } + @Test(expected= AssertionError.class) public void notEqualsObjectWithNull() { + assertEquals(new Object(), null); + } + + @Test(expected= AssertionError.class) public void notEqualsNullWithObject() { + assertEquals(null, new Object()); + } + + @Test public void notEqualsObjectWithNullWithMessage() { + Object o = new Object(); + try { + assertEquals("message", null, o); + fail(); + } + catch(AssertionError e) { + assertEquals("message expected:<null> but was:<" + o.toString() + ">", e.getMessage()); + } + } + + @Test public void notEqualsNullWithObjectWithMessage() { + Object o = new Object(); + try { + assertEquals("message", o, null); + fail(); + } + catch(AssertionError e) { + assertEquals("message expected:<"+ o.toString() + "> but was:<null>", e.getMessage()); + } + } + @Test(expected= AssertionError.class) public void objectsNotEquals() { assertEquals(new Object(), new Object()); } |