From 7b6de8b76abb90210152f2ac198d00c8c4ef36b6 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Mille Date: Fri, 18 Feb 2022 14:48:36 +0100 Subject: [PATCH] Clean up JUnit3 references JUnit3 is not supported. --- src/main/java/org/mockito/InjectMocks.java | 1 - src/main/java/org/mockito/Mock.java | 1 - .../java/org/mockito/MockitoAnnotations.java | 1 - .../internal/junit/ExceptionFactory.java | 2 +- .../internal/junit/ExceptionFactoryTest.java | 42 ++----------------- 5 files changed, 4 insertions(+), 43 deletions(-) diff --git a/src/main/java/org/mockito/InjectMocks.java b/src/main/java/org/mockito/InjectMocks.java index 6ed02abc6c..ea8f188985 100644 --- a/src/main/java/org/mockito/InjectMocks.java +++ b/src/main/java/org/mockito/InjectMocks.java @@ -149,7 +149,6 @@ *

* MockitoAnnotations.openMocks(this) method has to be called to initialize annotated objects. * In above example, openMocks() is called in @Before (JUnit4) method of test's base class. - * For JUnit3 openMocks() can go to setup() method of a base class. * Instead you can also put openMocks() in your JUnit runner (@RunWith) or use the built-in * {@link MockitoJUnitRunner}. Also, make sure to release any mocks after disposing your test class with a corresponding hook. *

diff --git a/src/main/java/org/mockito/Mock.java b/src/main/java/org/mockito/Mock.java index 8b8132000e..62c4faa2df 100644 --- a/src/main/java/org/mockito/Mock.java +++ b/src/main/java/org/mockito/Mock.java @@ -59,7 +59,6 @@ *

* MockitoAnnotations.openMocks(this) method has to be called to initialize annotated objects. * In above example, openMocks() is called in @Before (JUnit4) method of test's base class. - * For JUnit3 openMocks() can go to setup() method of a base class. * Instead you can also put openMocks() in your JUnit runner (@RunWith) or use the built-in * {@link MockitoJUnitRunner}. Also, make sure to release any mocks after disposing your test class with a corresponding hook. *

diff --git a/src/main/java/org/mockito/MockitoAnnotations.java b/src/main/java/org/mockito/MockitoAnnotations.java index 1672422299..5857478ca6 100644 --- a/src/main/java/org/mockito/MockitoAnnotations.java +++ b/src/main/java/org/mockito/MockitoAnnotations.java @@ -56,7 +56,6 @@ * MockitoAnnotations.openMocks(this) method has to be called to initialize annotated fields. *

* In above example, openMocks() is called in @Before (JUnit4) method of test's base class. - * For JUnit3 openMocks() can go to setup() method of a base class. * You can also put openMocks() in your JUnit runner (@RunWith) or use built-in runner: {@link MockitoJUnitRunner}. * If static method mocks are used, it is required to close the initialization. Additionally, if using third-party * mock-makers, other life-cycles might be handled by the open-release routine. diff --git a/src/main/java/org/mockito/internal/junit/ExceptionFactory.java b/src/main/java/org/mockito/internal/junit/ExceptionFactory.java index 7c5a841abb..a1331d2602 100644 --- a/src/main/java/org/mockito/internal/junit/ExceptionFactory.java +++ b/src/main/java/org/mockito/internal/junit/ExceptionFactory.java @@ -36,7 +36,7 @@ private static interface ExceptionFactoryImpl { * Returns an AssertionError that describes the fact that the arguments of an invocation are different. * If {@link org.opentest4j.AssertionFailedError} is on the class path (used by JUnit 5 and others), * it returns a class that extends it. Otherwise, if {@link junit.framework.ComparisonFailure} is on the - * class path (shipped with JUnit 3 and 4), it will return a class that extends that. This provides + * class path (shipped with JUnit 4), it will return a class that extends that. This provides * better IDE support as the comparison result can be opened in a visual diff. If neither are available, * it returns an instance of * {@link org.mockito.exceptions.verification.ArgumentsAreDifferent}. diff --git a/src/test/java/org/mockito/internal/junit/ExceptionFactoryTest.java b/src/test/java/org/mockito/internal/junit/ExceptionFactoryTest.java index 69baf30427..394d0fb391 100644 --- a/src/test/java/org/mockito/internal/junit/ExceptionFactoryTest.java +++ b/src/test/java/org/mockito/internal/junit/ExceptionFactoryTest.java @@ -15,28 +15,19 @@ public class ExceptionFactoryTest { - private static ClassLoader classLoaderWithoutJUnitOrOpenTest = + private static final ClassLoader classLoaderWithoutJUnitOrOpenTest = excludingClassLoader() .withCodeSourceUrlOf(ExceptionFactory.class) .without("org.junit", "junit", "org.opentest4j") .build(); - private static ClassLoader classLoaderWithoutOpenTest = - excludingClassLoader() - .withCodeSourceUrlOf(ExceptionFactory.class, org.junit.ComparisonFailure.class) - .without("org.opentest4j") - .build(); - private static ClassLoader currentClassLoader = ExceptionFactoryTest.class.getClassLoader(); + private static final ClassLoader currentClassLoader = + ExceptionFactoryTest.class.getClassLoader(); /** loaded by the current classloader */ private static Class opentestComparisonFailure; private static Class opentestArgumentsAreDifferent; - /** loaded by the classloader {@value #classLoaderWithoutOpenTest}, which excludes OpenTest4J classes */ - private static Class junit3ComparisonFailure; - - private static Class junit3ArgumentsAreDifferent; - /** loaded by the custom classloader {@value #classLoaderWithoutJUnitOrOpenTest}, which excludes JUnit and OpenTest4J classes */ private static Class nonJunitArgumentsAreDifferent; @@ -44,13 +35,6 @@ public class ExceptionFactoryTest { public static void init() throws ClassNotFoundException { nonJunitArgumentsAreDifferent = classLoaderWithoutJUnitOrOpenTest.loadClass(ArgumentsAreDifferent.class.getName()); - junit3ComparisonFailure = - classLoaderWithoutOpenTest.loadClass( - junit.framework.ComparisonFailure.class.getName()); - junit3ArgumentsAreDifferent = - classLoaderWithoutOpenTest.loadClass( - org.mockito.exceptions.verification.junit.ArgumentsAreDifferent.class - .getName()); opentestComparisonFailure = org.opentest4j.AssertionFailedError.class; opentestArgumentsAreDifferent = org.mockito.exceptions.verification.opentest4j.ArgumentsAreDifferent.class; @@ -63,15 +47,6 @@ public void createArgumentsAreDifferentException_withoutJUnitOrOpenTest() throws assertThat(e).isExactlyInstanceOf(nonJunitArgumentsAreDifferent); } - @Test - public void createArgumentsAreDifferentException_withJUnit3_butNotOpenTest() throws Exception { - AssertionError e = invokeFactoryThroughLoader(classLoaderWithoutOpenTest); - - assertThat(e) - .isExactlyInstanceOf(junit3ArgumentsAreDifferent) - .isInstanceOf(junit3ComparisonFailure); - } - @Test public void createArgumentsAreDifferentException_withOpenTest() throws Exception { AssertionError e = invokeFactoryThroughLoader(currentClassLoader); @@ -92,17 +67,6 @@ public void createArgumentsAreDifferentException_withoutJUnitOrOpenTest_2x() thr assertThat(e).isExactlyInstanceOf(nonJunitArgumentsAreDifferent); } - @Test - public void createArgumentsAreDifferentException_withJUnit3_2x() throws Exception { - AssertionError e; - - e = invokeFactoryThroughLoader(classLoaderWithoutOpenTest); - assertThat(e).isExactlyInstanceOf(junit3ArgumentsAreDifferent); - - e = invokeFactoryThroughLoader(classLoaderWithoutOpenTest); - assertThat(e).isExactlyInstanceOf(junit3ArgumentsAreDifferent); - } - @Test public void createArgumentsAreDifferentException_withOpenTest_2x() throws Exception { AssertionError e;