/** * Runs the app with the given arguments. * * @param args Application arguments */ public static void main(final String[] args) { try { new Main().run(args); } catch (final JBakeException e) { System.err.println(e.getMessage()); e.printStackTrace(); System.exit(1); } catch (final Throwable e) { System.err.println("An unexpected error occurred: " + e.getMessage()); e.printStackTrace(); System.exit(2); } }
@Test public void shouldThrowAnExceptionIfSourcefolderDoesNotExist() throws Exception { File nonExistentSourceFolder = mock(File.class); when(nonExistentSourceFolder.getAbsolutePath()).thenReturn("/tmp/nonexistent"); when(nonExistentSourceFolder.exists()).thenReturn(false); try { util.loadConfig(nonExistentSourceFolder); fail("Exception should be thrown, as source folder does not exist"); } catch (JBakeException e) { assertThat(e.getMessage()).isEqualTo("The given source folder '/tmp/nonexistent' does not exist."); } }
@Test public void shouldThrowAnExceptionIfSourcefolderIsNotADirectory() throws Exception { File sourceFolder = mock(File.class); when(sourceFolder.exists()).thenReturn(true); when(sourceFolder.isDirectory()).thenReturn(false); try { util.loadConfig(sourceFolder); fail("Exception should be thrown if given source folder is not a directory."); } catch (JBakeException e) { assertThat(e.getMessage()).isEqualTo("The given source folder is not a directory."); } }
@Test public void shouldThrowExceptionIfSourceFolderDoesNotExist() throws Exception { File nonExistentFile = new File(folder.toFile(), "nofolder"); JBakeConfiguration configuration = mock(JBakeConfiguration.class); when(configuration.getSourceFolder()).thenReturn(nonExistentFile); JBakeConfigurationInspector inspector = new JBakeConfigurationInspector(configuration); try { inspector.inspect(); fail("should throw a JBakeException"); } catch (JBakeException e) { assertThat(e.getMessage()).isEqualTo("Error: Source folder must exist: " + nonExistentFile.getAbsolutePath()); } }
@Test public void shouldThrowExceptionIfSourceFolderIsNotReadable() throws Exception { File nonReadableFile = mock(File.class); when(nonReadableFile.exists()).thenReturn(true); when(nonReadableFile.isDirectory()).thenReturn(true); when(nonReadableFile.canRead()).thenReturn(false); JBakeConfiguration configuration = mock(JBakeConfiguration.class); when(configuration.getSourceFolder()).thenReturn(nonReadableFile); JBakeConfigurationInspector inspector = new JBakeConfigurationInspector(configuration); try { inspector.inspect(); fail("should throw a JBakeException"); } catch (JBakeException e) { assertThat(e.getMessage()).isEqualTo("Error: Source folder is not readable: " + nonReadableFile.getAbsolutePath()); } }
@Test public void shouldThrowExceptionIfTemplateFolderDoesNotExist() throws Exception { String templateFolderName = "template"; File expectedFolder = new File(folder.toFile(), templateFolderName); JBakeConfiguration configuration = mock(JBakeConfiguration.class); when(configuration.getSourceFolder()).thenReturn(folder.toFile()); when(configuration.getTemplateFolder()).thenReturn(expectedFolder); when(configuration.getTemplateFolderName()).thenReturn(templateFolderName); JBakeConfigurationInspector inspector = new JBakeConfigurationInspector(configuration); try { inspector.inspect(); fail("should throw a JBakeException"); } catch (JBakeException e) { assertThat(e.getMessage()).isEqualTo("Error: Required folder cannot be found! Expected to find [" + templateFolderName + "] at: " + expectedFolder.getAbsolutePath()); } }
@Test public void shouldThrowExceptionIfContentFolderDoesNotExist() throws Exception { String contentFolderName = "content"; String templateFolderName = "template"; File templateFolder = TestUtils.newFolder(folder.toFile(), templateFolderName); File contentFolder = new File(folder.toFile(), contentFolderName); 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); JBakeConfigurationInspector inspector = new JBakeConfigurationInspector(configuration); try { inspector.inspect(); fail("should throw a JBakeException"); } catch (JBakeException e) { assertThat(e.getMessage()).isEqualTo("Error: Required folder cannot be found! Expected to find [" + contentFolderName + "] at: " + contentFolder.getAbsolutePath()); } }
@Test public void shouldThrowExceptionIfDestinationFolderNotWritable() throws Exception { String contentFolderName = "content"; String templateFolderName = "template"; File templateFolder = TestUtils.newFolder(folder.toFile(), templateFolderName); File contentFolder = TestUtils.newFolder(folder.toFile(), contentFolderName); File destinationFolder = mock(File.class); when(destinationFolder.exists()).thenReturn(true); 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); JBakeConfigurationInspector inspector = new JBakeConfigurationInspector(configuration); try { inspector.inspect(); fail("should throw JBakeException"); } catch (JBakeException e) { assertThat(e.getMessage()).contains("Error: Destination folder is not writable:"); } }
/** * Runs the app with the given arguments. * * @param args Application arguments */ public static void main(final String[] args) { try { new Main().run(args); } catch (final JBakeException e) { System.err.println(e.getMessage()); e.printStackTrace(); System.exit(1); } catch (final Throwable e) { System.err.println("An unexpected error occurred: " + e.getMessage()); e.printStackTrace(); System.exit(2); } }