Mockito: List Matchers with generics
Mockito offers: when(mock.process(Matchers.any(List.class))); How to avoid warning if process takes a List<Bar> instead? 4 Answers 4
Mockito offers: when(mock.process(Matchers.any(List.class))); How to avoid warning if process takes a List<Bar> instead? 4 Answers 4
I’ve got such a code snippet: @RunWith(PowerMockRunner.class) @PrepareForTest({Thread.class}) public class AllMeasuresDataTest { @Before public void setUp() throws Exception { } @Test public void testGetMeasures() { AllMeasuresData measure = new AllMeasuresData(); assertEquals(measure.getMeasures(), null); HashMap<String, Measure> map = new HashMap<String, Measure>(); measure.setMeasures(map); assertEquals(measure.getMeasures(), map); measure.setMeasures(null); assertEquals(measure.getMeasures(), null); } @Test public void testAllMeasuresData() throws IOException { ClassLoader loader … Read more
Can anyone please provide me an example showing how to use the org.mockito.ArgumentCaptor class and how it is different from simple matchers that are provided with mockito. I read the provided mockito documents but those doesn’t illustrate it clearly, none of them are able to explain it with clarity. 5 Answers 5
I write jUnit test cases for 3 purposes: To ensure that my code satisfies all of the required functionality, under all (or most of) the input combinations/values. To ensure that I can change the implementation, and rely on JUnit test cases to tell me that all my functionality is still satisfied. As a documentation of … Read more
I’m using Spring 3.1.4.RELEASE and Mockito 1.9.5. In my Spring class I have: @Value(“#{myProps[‘default.url’]}”) private String defaultUrl; @Value(“#{myProps[‘default.password’]}”) private String defaultrPassword; // … From my JUnit test, which I currently have set up like so: @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration({ “classpath:test-context.xml” }) public class MyTest { I would like to mock a value for my “defaultUrl” field. Note … Read more
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.UnfinishedStubbingException: Unfinished stubbing detected here: -> at com.a.b.DomainTestFactory.myTest(DomainTestFactory.java:355) E.g. thenReturn() may be missing. Examples of correct stubbing: when(mock.isOk()).thenReturn(true); when(mock.isOk()).thenThrow(exception); doThrow(exception).when(mock).someVoidMethod(); Hints: 1. missing thenReturn() 2. you are trying to stub a … Read more
I have an interface with a method that expects an array of Foo: public interface IBar { void doStuff(Foo[] arr); } I am mocking this interface using Mockito, and I’d like to assert that doStuff() is called, but I don’t want to validate what argument are passed – “don’t care”. How do I write the … Read more
When creating tests and mocking dependencies, what is the difference between these three approaches? @MockBean: @MockBean MyService myservice; @Mock: @Mock MyService myservice; Mockito.mock() MyService myservice = Mockito.mock(MyService.class); 2 Answers 2
We have been using Mock for python for a while. Now, we have a situation in which we want to mock a function def foo(self, my_param): #do something here, assign something to my_result return my_result Normally, the way to mock this would be (assuming foo being part of an object) self.foo = MagicMock(return_value=”mocked!”) Even, if … Read more
is it possible to pass the type of an interface with generics? The interface: public interface AsyncCallback<T> In my test method: Mockito.any(AsyncCallback.class) Putting <ResponseX> behind or for .class didnt work. 8 Answers 8