I was not lucky to get a Mockito to capture the values ββof function arguments! I make fun of a search engine index and instead of creating an index, I just use a hash.
// Fake index for solr Hashmap<Integer,Document> fakeIndex; // Add a document 666 to the fakeIndex SolrIndexReader reader = Mockito.mock(SolrIndexReader.class); // Give the reader access to the fake index Mockito.when(reader.document(666)).thenReturn(document(fakeIndex(666))
I cannot use arbitrary arguments because I check the results of the queries (i.e. which documents they return). Similarly, I do not want to specify a specific value and have a row for each document!
Mockito.when(reader.document(0)).thenReturn(document(fakeIndex(0)) Mockito.when(reader.document(1)).thenReturn(document(fakeIndex(1)) .... Mockito.when(reader.document(n)).thenReturn(document(fakeIndex(n))
I looked at the callbacks section of the Using Mockito page. Unfortunately, this is not Java, and I could not get my own interpretation of this to work in Java.
EDIT (for clarification): How do I get a Mockito to grab the X argument and pass it to my function? I want the exact value (or ref) of X to be passed to the function.
I do not want to list all cases, and an arbitrary argument will not work, because I am testing different results for different queries.
The Mockito page says:
val mockedList = mock[List[String]] mockedList.get(anyInt) answers { i => "The parameter is " + i.toString }
This is not java, and I do not know how to translate into java or pass everything that happened to a function.
java mockito
nflacco Jul 08 2018-11-11T00: 00Z
source share