Проблема при попытке смоделировать параметр в весеннем тесте MVC и kotlin -> сопоставления аргументов вне проверки или заглушки - PullRequest
0 голосов
/ 29 мая 2019

Здравствуйте, я работаю с документами весеннего отдыха и mockito, и у меня возникает проблема, когда я пытаюсь смоделировать вызов какого-либо метода и пытаюсь отправить ложный параметр этому методу.

Мой тест выглядит так:

@Test
    @Throws(Exception::class)
    fun shouldReturnDefaultMessage() {
        val paramsMock = mapOf("swid" to "asudyasd-asdasd-asdasd", "seeAll" to true)
        `when`(apiRequest.parameters).thenReturn(paramsMock)
        `when`(browsePlayerServiceRepresentable.getEntitiesBrowse(any(RequestBrowsePlayerContext::class.java))).thenReturn(Single.just(presentBrowsePlayers()))
        this.mockMvc!!.perform(get("/v1/browse/players").flashAttr("apiRequest", apiRequest))
                .andDo(print()).andExpect(status().isOk)
    }

То, что я делаю, отправляет параметр как any(RequestBrowsePlayerContext::class.java)

Но я борюсь со следующей проблемой:

You cannot use argument matchers outside of verification or stubbing.
Examples of correct usage of argument matchers:
    when(mock.get(anyInt())).thenReturn(null);
    doThrow(new RuntimeException()).when(mock).someVoidMethod(anyObject());
    verify(mock).someMethod(contains("foo"))

This message may appear after an NullPointerException if the last matcher is returning an object 
like any() but the stubbed method signature expect a primitive argument, in this case,
use primitive alternatives.
    when(mock.get(any())); // bad use, will raise NPE
    when(mock.get(anyInt())); // correct usage use

Also, this error might show up because you use argument matchers with methods that cannot be mocked.
Following methods *cannot* be stubbed/verified: final/private/equals()/hashCode().
Mocking methods declared on non-public parent classes is not supported.

Метод открыт, есть ли способ сделать это правильно?

Спасибо

...