use of ch.qos.logback.core.Appender in project ddf by codice.
the class AddApplicationCommandTest method testAddApplicationCommandASE.
/**
* Tests the {@link AddApplicationCommand} class and its contained methods
* for the case where the ApplicationService throws an ApplicationServiceException
*
* @throws Exception
*/
// TODO RAP 29 Aug 16: DDF-2443 - Fix test to not depend on specific log output
@Test
public void testAddApplicationCommandASE() throws Exception {
ch.qos.logback.classic.Logger root = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
final Appender mockAppender = mock(Appender.class);
when(mockAppender.getName()).thenReturn("MOCK");
root.addAppender(mockAppender);
root.setLevel(Level.ALL);
ApplicationService testAppService = mock(ApplicationServiceImpl.class);
AddApplicationCommand addApplicationCommand = new AddApplicationCommand();
addApplicationCommand.appName = "TestApp";
addApplicationCommand.setApplicationService(testAppService);
doThrow(new ApplicationServiceException()).when(testAppService).addApplication(any(URI.class));
addApplicationCommand.execute();
verify(mockAppender).doAppend(argThat(new ArgumentMatcher() {
@Override
public boolean matches(final Object argument) {
return ((LoggingEvent) argument).getFormattedMessage().contains(CMD_ERROR_STRING);
}
}));
}
Aggregations