/** * Responsible for incremental baking, typically a single file at a time. * * @param fileToBake The file to bake */ public void bake(File fileToBake) { Asset asset = utensils.getAsset(); if(asset.isAssetFile(fileToBake)) { LOGGER.info("Baking a change to an asset [" + fileToBake.getPath() + "]"); asset.copySingleFile(fileToBake); } else { LOGGER.info("Playing it safe and running a full bake..."); bake(); } }
@Test public void shouldSkipCopyingSingleFileIfDirectory() throws IOException { Asset asset = new Asset(config); File emptyDir = new File(folder.toFile(),"emptyDir"); emptyDir.mkdir(); File expectedDir = new File(fixtureDir.getCanonicalPath(), "emptyDir"); asset.copySingleFile(emptyDir); Assertions.assertFalse(expectedDir.exists(), "Directory should be skipped"); }
@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 testCopySingleFile() throws Exception { Asset asset = new Asset(config); String cssSubPath = File.separatorChar + "css" + File.separatorChar + "bootstrap.min.css"; String contentImgPath = File.separatorChar + "blog" + File.separatorChar + "2013" + File.separatorChar + "images" + File.separatorChar + "custom-image.jpg"; // Copy single Asset File File expected = new File(folder.toString() + cssSubPath); Assertions.assertFalse(expected.exists(), "cssFile should not exist before running the test; avoids false positives"); File cssFile = new File(fixtureDir.getPath() + File.separatorChar + "assets" + cssSubPath); asset.copySingleFile(cssFile); Assertions.assertTrue(expected.exists(), "Css asset file did not copy"); // Copy single Content file expected = new File(folder.toString() + contentImgPath); Assertions.assertFalse(expected.exists(), "content image file should not exist before running the test"); File imgFile = new File(fixtureDir.getPath() + File.separatorChar + "content" + contentImgPath); asset.copySingleFile(imgFile); Assertions.assertTrue(expected.exists(), "Content img file did not copy"); }
/** * Responsible for incremental baking, typically a single file at a time. * * @param fileToBake The file to bake */ public void bake(File fileToBake) { Asset asset = utensils.getAsset(); if(asset.isAssetFile(fileToBake)) { LOGGER.info("Baking a change to an asset [" + fileToBake.getPath() + "]"); asset.copySingleFile(fileToBake); } else { LOGGER.info("Playing it safe and running a full bake..."); bake(); } }