mockito Questions
4
I have multiple packages under a folder for which tests were written. These tests pass when run as a Class or from the residing package. But when I run it from the folder as a whole, the tests are ...
6
I have just upgraded from JDK 17 to 21 in my Windows machine. After that when I am running JUNIT test and I am getting the following warring. I have looked over all of the day, but no solution work...
Cirrostratus asked 6/2 at 23:47
2
Solved
I am trying to verify in a test that a static method is called. I am using Mockito for this purpose.
This question is similar to this. However, the solution suggested in the most upvoted reply is n...
Freaky asked 24/8, 2021 at 7:19
6
Solved
So I am getting this error in my Spring boot Gradle project:
'java.lang.AutoCloseable org.mockito.MockitoAnnotations.openMocks(java.lang.Object)'
java.lang.NoSuchMethodError: 'java.lang.AutoClosea...
Kaveri asked 7/5, 2021 at 9:13
2
Solved
In Mockito, is there a way to verify that there are no more interactions on any mock I have created?
For example:
public void test()
{
...
TestObject obj = mock(TestObject);
myClass.test();
v...
3
Solved
I follow the MVP pattern + UseCases to interact with a Model layer. This is a method in a Presenter I want to test:
fun loadPreviews() {
launch(UI) {
val items = previewsUseCase.getPreviews() //...
Tantrum asked 16/4, 2018 at 19:42
9
Solved
I’m using Mockito 1.9.5. How do I mock what is coming back from a protected method? I have this protected method …
protected JSONObject myMethod(final String param1, final String param2)
{
…
}
H...
5
Solved
3
I have a Spring web application that can operate in “special” mode where mockito is used to spy on certain objects. Some of those objects are final (protobuf messages). I know, this may smell like ...
Lawrenson asked 29/7, 2021 at 18:2
6
Solved
As I understand, lenient silences the exceptions thrown by StrictStubbing. Based on this, lenient shouldn't be used, maybe only temporary while doing TDD, because strict stubbing exceptions would g...
Sanious asked 26/2, 2020 at 18:20
5
Solved
I'm trying to port a Scala system to Mockito2. There are a few test cases that use doReturn and now in Mockito 2.18.0 I get this error:
Error:(34, 5) ambiguous reference to overloaded definition,
...
7
2
Junit test case getting failed:
existing static mocking registration must be deregistered
Test class:
@RunWith(MockitoJUnitRunner.class)
public class DeleteReportServiceTest {
@InjectMocks
pri...
2
Solved
One of the interactions I want to test is that a class Foo is supposed to pass a Stream<Changes> to FooListener.someChangesHappened. Is there a Mockito idiom to verify that a stream contained...
Henotheism asked 7/5, 2016 at 13:17
4
Solved
How to mock a method that returns Mono<Void>?
I have this method that returns Mono<Void>
public Mono<Void> deleteMethod(Post post) {
return statusRepository.delete(post);
}
...
Weisbrodt asked 23/7, 2019 at 19:58
9
I am trying to test ViewModel to make sure livedata gets updated correctly. However when using ArgumentMatchers.any() it fails with IllegalStateException saying:
ArgumentMatchers.any(mViewModel.Co...
Borough asked 7/12, 2019 at 20:45
3
Solved
Let's say there's an interface with a callback:
interface SomeInterface {
fun doSomething(arg: String, callback: (Exception?, Long) -> Unit)
}
which I extend into a suspend function like thi...
Overcritical asked 3/8, 2018 at 13:16
7
I have the following simple controller to catch any unexpected exceptions:
@ControllerAdvice
public class ExceptionController {
@ExceptionHandler(Throwable.class)
@ResponseStatus(value = HttpSt...
Santee asked 21/5, 2013 at 11:52
4
Solved
I have a class that has the @Slf4j annotation.
I try to write a test and mock the Logger, but it does not work.
@RequiredArgsConstructor
@Slf4j
public abstract class ExampleClass {
protected fin...
Fur asked 26/3, 2021 at 11:58
3
I want to make the following work, but I don't know how to mock forEach behavior properly. (The code is taken from a related question Testing Java enhanced for behavior with Mockito )
@Test
public...
7
Solved
I'm trying to create a JsonProcessingException to be thrown by a mock object.
when(mapper.writeValueAsString(any(Object.class))).thenThrow(new JsonProcessingException("Error"));
However I'm una...
2
Solved
I have a class which has 2 fields of similar types. I have mocked them both. But when I use InjectMocks, inject mocks wrongly injects a single mock into both those fields.
Here is the example code ...
6
I have interface
Interface MyInterface {
myMethodToBeVerified (String, String);
}
And implementation of interface is
class MyClassToBeTested implements MyInterface {
myMethodToBeVerified(String,...
Evadne asked 12/12, 2013 at 18:58
2
I have a method that includes transactionTemplate in it. My test works when I run debug mode but not when executed directly.
My test works when I run debug mode because I think transactional operat...
8
Solved
I am getting following exception while running the tests. I am using Mockito for mocking. The hints mentioned by Mockito library are not helping.
org.mockito.exceptions.misusing.UnfinishedStubbing...
1 Next >
© 2022 - 2024 — McMap. All rights reserved.