@Test public void shouldLogSkipCopyingSingleFileIfDirectory() throws IOException { Asset asset = new Asset(config); File emptyDir = new File(folder.toFile(),"emptyDir"); emptyDir.mkdir(); asset.copySingleFile(emptyDir); verify(mockAppender, times(1)).doAppend(captorLoggingEvent.capture()); LoggingEvent loggingEvent = captorLoggingEvent.getValue(); assertThat(loggingEvent.getMessage()).isEqualTo("Skip copying single asset file [{}]. Is a directory."); }
@Test public void shouldLogWarningIfDocumentTypeNotFound() throws Exception { File sourceFolder = TestUtils.getTestResourcesAsSourceFolder(); JBakeConfiguration config = util.loadConfig(sourceFolder); config.getTemplateFileByDocType("none"); verify(mockAppender, times(1)).doAppend(captorLoggingEvent.capture()); LoggingEvent loggingEvent = captorLoggingEvent.getValue(); assertThat(loggingEvent.getMessage()).isEqualTo("Cannot find configuration key '{}' for document type '{}'"); }
@Test public void shouldLogAWarningIfAsciidocOptionCouldNotBeFound() throws Exception { File sourceFolder = TestUtils.getTestResourcesAsSourceFolder(); DefaultJBakeConfiguration config = (DefaultJBakeConfiguration) util.loadConfig(sourceFolder); config.getAsciidoctorOption("template_dirs"); verify(mockAppender, times(1)).doAppend(captorLoggingEvent.capture()); LoggingEvent loggingEvent = captorLoggingEvent.getValue(); assertThat(loggingEvent.getMessage()).isEqualTo("Cannot find asciidoctor option '{}.{}'"); }
@Test public void shouldLogWarningIfAssetFolderDoesNotExist() throws Exception { String contentFolderName = "content"; String templateFolderName = "template"; String destinationFolderName = "output"; String assetFolderName = "assets"; File templateFolder = TestUtils.newFolder(folder.toFile(), templateFolderName); File contentFolder = TestUtils.newFolder(folder.toFile(), contentFolderName); File destinationFolder = TestUtils.newFolder(folder.toFile(), destinationFolderName); File assetFolder = new File(folder.toFile(), assetFolderName); JBakeConfiguration configuration = mock(JBakeConfiguration.class); when(configuration.getSourceFolder()).thenReturn(folder.toFile()); when(configuration.getTemplateFolder()).thenReturn(templateFolder); when(configuration.getTemplateFolderName()).thenReturn(templateFolderName); when(configuration.getContentFolder()).thenReturn(contentFolder); when(configuration.getContentFolderName()).thenReturn(contentFolderName); when(configuration.getDestinationFolder()).thenReturn(destinationFolder); when(configuration.getAssetFolder()).thenReturn(assetFolder); JBakeConfigurationInspector inspector = new JBakeConfigurationInspector(configuration); inspector.inspect(); verify(mockAppender, times(1)).doAppend(captorLoggingEvent.capture()); LoggingEvent loggingEvent = captorLoggingEvent.getValue(); assertThat(loggingEvent.getMessage()).isEqualTo("No asset folder '{}' was found!"); assertThat(loggingEvent.getFormattedMessage()).isEqualTo("No asset folder '" + assetFolder.getAbsolutePath() + "' was found!"); }
protected void append(LoggingEvent event) { baseImplementation.append(String.valueOf(event.getMessage())); }
@Test public void shouldLogWarning() { verify(appender, atLeastOnce()).doAppend(logCaptor.capture()); LoggingEvent loggingEvent = logCaptor.getValue(); assertThat(loggingEvent.getLevel()).isEqualTo(Level.WARN); assertThat(loggingEvent.getMessage()).containsIgnoringCase("It is recommended to use HoverflyRule with @ClassRule"); }
@Test public void shouldWarnWhenStartHoverflyInstanceTwice() { // Given // Reference: https://dzone.com/articles/unit-testing-asserting-line ch.qos.logback.classic.Logger root = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(ch.qos.logback.classic.Logger.ROOT_LOGGER_NAME); final Appender mockAppender = mock(Appender.class); when(mockAppender.getName()).thenReturn("test-shouldWarnWhenStartHoverflyInstanceTwice"); root.addAppender(mockAppender); startDefaultHoverfly(); // when hoverfly.start(); // then verify(mockAppender).doAppend(argThat(argument -> { LoggingEvent event = (LoggingEvent) argument; return event.getLevel().levelStr.equals("WARN") && event.getMessage().contains("Local Hoverfly is already running"); })); }
ex.writeUTF(evt.getMessage());
ex.writeUTF(evt.getMessage());
@Test public void testWithEnabledLevel() throws Exception { logger.setLevel(Level.DEBUG); client.run(); client.close(); ILoggingEvent rcvdEvent = appender.getLastEvent(); assertEquals(event.getLoggerName(), rcvdEvent.getLoggerName()); assertEquals(event.getLevel(), rcvdEvent.getLevel()); assertEquals(event.getMessage(), rcvdEvent.getMessage()); }