'MismatchReportingTestListener' has already been added and not removed using MockitoJUnitRunner
See original GitHub issue- The mockito message in the stacktrace have useful information, but it didn’t help
- The problematic code (if that’s possible) is copied here;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasProperty;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.hamcrest.MockitoHamcrest.argThat;
import java.io.File;
import java.io.IOException;
import java.util.function.Consumer;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.pdfsam.support.params.SingleOutputTaskParametersBuilder;
import org.pdfsam.test.InitializeAndApplyJavaFxThreadRule;
@RunWith(MockitoJUnitRunner.class)
public class BrowsablePdfOutputFieldTest {
@Rule
public TemporaryFolder folder = new TemporaryFolder();
@Rule
public InitializeAndApplyJavaFxThreadRule fxThread = new InitializeAndApplyJavaFxThreadRule();
@Mock
private SingleOutputTaskParametersBuilder<?> builder;
@Mock
private Consumer<String> onError;
@Test
public void valid() throws IOException {
BrowsablePdfOutputField victim = new BrowsablePdfOutputField();
File value = folder.newFile("test.pdf");
victim.getTextField().setText(value.getAbsolutePath());
victim.apply(builder, onError);
verify(builder).output(argThat(hasProperty("destination", equalTo(value))));
verify(onError, never()).accept(anyString());
}
@Test
public void invalid() {
BrowsablePdfOutputField victim = new BrowsablePdfOutputField();
victim.enforceValidation(true, true);
victim.getTextField().setText("ChuckNorris");
victim.apply(builder, onError);
verify(builder, never()).output(any());
verify(onError).accept(anyString());
}
}
- Provide versions (mockito / jdk / os / any other relevant information) Mockito 3.0.0, AdoptOpenJDK 11.0.4, Linux Mint
- Provide a Short, Self Contained, Correct (Compilable), Example of the issue (same as any question on stackoverflow.com)
- Read the contributing guide
I migrated from 1.10.19 to the 3.0.0 version and I have few tests using the MockitoJUnitRunner which are failing with the following stacktrace:
org.mockito.exceptions.misusing.RedundantListenerException:
Problems adding Mockito listener.
Listener of type 'MismatchReportingTestListener' has already been added and not removed.
It indicates that previous listener was not removed according to the API.
When you add a listener, don't forget to remove the listener afterwards:
Mockito.framework().removeListener(myListener);
For more information, see the javadoc for RedundantListenerException class.
at org.mockito.internal.runners.DefaultInternalRunner$1$1.evaluate(DefaultInternalRunner.java:41)
at org.junit.rules.ExternalResource$1.evaluate(ExternalResource.java:48)
at org.pdfsam.test.JavaFXThreadRule$1.lambda$evaluate$0(JavaFXThreadRule.java:48)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:389)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
at com.sun.glass.ui.gtk.GtkApplication._runLoop(Native Method)
at com.sun.glass.ui.gtk.GtkApplication.lambda$runLoop$11(GtkApplication.java:277)
at java.base/java.lang.Thread.run(Thread.java:835)
It seems something internal, I didn’t add or remove any MismatchReportingTestListener
and moreover the same code was working with the 1.10.19 and is working if I remove the MockitoJUnitRunner
and replace the @Mock
annotation with a Mockito.mock
in a @Before
method.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:21 (9 by maintainers)
Top Results From Across the Web
Unit Tests failing due to MismatchReportingTestListener
Listener of type 'MismatchReportingTestListener' has already been added and not removed. It indicates that previous listener was not removed ...
Read more >[Solved] org.mockito.exceptions.misusing ...
This occurred by Mockito framework when instance of MockitoListener is being added to Mockito Framework and there is already a listener with ......
Read more >Mockito (Mockito 4.9.0 API) - javadoc.io
The Mockito library enables mock creation, verification and stubbing. This javadoc content is also available on the https://site.mockito.org/ web page.
Read more >mockito - Bountysource
RedundantListenerException: Problems adding Mockito listener. Listener of type 'MismatchReportingTestListener' has already been added and not removed.
Read more >Diff - platform/external/mockito - Google Git
Local Modifications: - - Added dummy DefaultInvocationFactory to fix build + None ... + * In most healthy tests, this method is not...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@SharonHart, this test works fine with current Mockito (3.0). Can you provide a test that fails with current Mockito? Thank you!
2.26.0 looks like the one introducing this issue, all green in 2.25.1