2017-05-23 25 views
1

void 메소드 예외를 모의하려고 할 때 문제가 있습니다. 위의 코드에서 JMockit을 사용하여 void 메소드 예외를 조롱 할 수있는 방법

@Test 
public void throwInternalServerException() throws Exception { 
    new NonStrictExpectations() {{ 
     mockedClassInstance.voidMethod("abc", "def"); 
     result = new ServiceException(); 
    }}; 

    mockMvc.perform(post("/someRestApi/")) 
      .andExpect(status().isInternalServerError()); 

는, 성공은 내가 PARAMS을 교체하는 경우 "ABC"를"DEF"나는 this question의 솔루션을 시도했지만

anyString 와 함께 작동하지 않습니다.

모든 솔루션?

라이브러리 : jmockit 및 spring-test를 사용했습니다.

답변

0

anystring 키워드가 매개 변수 (이 경우 'abc'및 'def')가 될 때 예외가 발생합니다.