Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up JUnit3 references #2570

Merged
merged 1 commit into from Feb 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion src/main/java/org/mockito/InjectMocks.java
Expand Up @@ -149,7 +149,6 @@
* <p>
* <strong><code>MockitoAnnotations.openMocks(this)</code></strong> method has to be called to initialize annotated objects.
* In above example, <code>openMocks()</code> is called in &#064;Before (JUnit4) method of test's base class.
* For JUnit3 <code>openMocks()</code> can go to <code>setup()</code> method of a base class.
* <strong>Instead</strong> you can also put openMocks() in your JUnit runner (&#064;RunWith) or use the built-in
* {@link MockitoJUnitRunner}. Also, make sure to release any mocks after disposing your test class with a corresponding hook.
* </p>
Expand Down
1 change: 0 additions & 1 deletion src/main/java/org/mockito/Mock.java
Expand Up @@ -59,7 +59,6 @@
* <p>
* <strong><code>MockitoAnnotations.openMocks(this)</code></strong> method has to be called to initialize annotated objects.
* In above example, <code>openMocks()</code> is called in &#064;Before (JUnit4) method of test's base class.
* For JUnit3 <code>openMocks()</code> can go to <code>setup()</code> method of a base class.
* <strong>Instead</strong> you can also put openMocks() in your JUnit runner (&#064;RunWith) or use the built-in
* {@link MockitoJUnitRunner}. Also, make sure to release any mocks after disposing your test class with a corresponding hook.
* </p>
Expand Down
1 change: 0 additions & 1 deletion src/main/java/org/mockito/MockitoAnnotations.java
Expand Up @@ -56,7 +56,6 @@
* <b><code>MockitoAnnotations.openMocks(this)</code></b> method has to be called to initialize annotated fields.
* <p>
* In above example, <code>openMocks()</code> is called in &#064;Before (JUnit4) method of test's base class.
* For JUnit3 <code>openMocks()</code> can go to <code>setup()</code> method of a base class.
* You can also put openMocks() in your JUnit runner (&#064;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.
Expand Down
Expand Up @@ -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}.
Expand Down
42 changes: 3 additions & 39 deletions src/test/java/org/mockito/internal/junit/ExceptionFactoryTest.java
Expand Up @@ -15,42 +15,26 @@

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;

@BeforeClass
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;
Expand All @@ -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);
Expand All @@ -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;
Expand Down