Log4j.error 메소드를 호출하는 동안 Throwable을 포함 할 때 어설 션 오류가 발생합니다. @PreparateForTest 블록에 Logger.class, PrintWriter.class, AuthenticationException.class가 있습니다. Throwable을 인수로 전달하지 않으면 오류가 표시되지 않습니다.Logger.error (String, Throwable) 호출시 EasyMock AssertionError
mock 설정이 잘못되었습니다.
Caused by: java.lang.AssertionError:
Unexpected method call AuthenticationException.printStackTrace([email protected]):
at org.junit.Assert.fail(Assert.java:93)
at com.xxx.yy.security.client.ClientTest.authenticateFail(ClientTest.java:282)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.junit.internal.runners.TestMethod.invoke(TestMethod.java:66)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl$PowerMockJUnit44MethodRunner.runTestMethod(PowerMockJUnit44RunnerDelegateImpl.java:310)
... 23 more
의 JUnit 테스트 코드는 다음과 같습니다 :
AuthenticationException mockAuthException = PowerMock
.createMock(AuthenticationException.class);
PrintWriter mockPrintWriter = PowerMock
.createMock(PrintWriter.class);
Logger mockLogger = PowerMock.createMock(Logger.class);
String message = "blah";
mockLogger.error(message, mockAuthException);
EasyMock.expectLastCall();
mockAuthException.printStackTrace(mockPrintWriter);
EasyMock.expectLastCall();
문제를 일으키는
코드는 다음과 같습니다 :
는try{
.
.
}catch (AuthenticationException ex) {
LOGGER.error("SOME MESSAGE HERE", ex);
throw ex;
}