From 3d1523cdcf285f74c158ce3c4ebfb7e369ddbba5 Mon Sep 17 00:00:00 2001 From: Jonathan Bullock Date: Tue, 19 Feb 2019 00:48:37 +0000 Subject: [PATCH] Fixes #594 --- .../JBakeConfigurationFactory.java | 2 +- .../main/java/org/jbake/launcher/Main.java | 2 +- .../org/jbake/launcher/LaunchOptionsTest.java | 25 +++++++++++++++++-- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/jbake-core/src/main/java/org/jbake/app/configuration/JBakeConfigurationFactory.java b/jbake-core/src/main/java/org/jbake/app/configuration/JBakeConfigurationFactory.java index f9bbd4756..a11ec373a 100644 --- a/jbake-core/src/main/java/org/jbake/app/configuration/JBakeConfigurationFactory.java +++ b/jbake-core/src/main/java/org/jbake/app/configuration/JBakeConfigurationFactory.java @@ -92,7 +92,7 @@ public DefaultJBakeConfiguration createDefaultJbakeConfiguration(File sourceFold */ public DefaultJBakeConfiguration createJettyJbakeConfiguration(File sourceFolder, File destinationFolder, boolean isClearCache) throws ConfigurationException { DefaultJBakeConfiguration configuration = (DefaultJBakeConfiguration) getConfigUtil().loadConfig(sourceFolder); - configuration.setDestinationFolder(destinationFolder); + configuration.setDestinationFolder(sourceFolder); configuration.setClearCache(isClearCache); configuration.setSiteHost("http://localhost:"+configuration.getServerPort()); return configuration; diff --git a/jbake-core/src/main/java/org/jbake/launcher/Main.java b/jbake-core/src/main/java/org/jbake/launcher/Main.java index 5f970d439..26fdce8d2 100644 --- a/jbake-core/src/main/java/org/jbake/launcher/Main.java +++ b/jbake-core/src/main/java/org/jbake/launcher/Main.java @@ -150,7 +150,7 @@ private void printUsage(Object options) { parser.printUsage(System.out); } - private void runServer(File path, int port) { + protected void runServer(File path, int port) { jettyServer.run(path.getPath(), String.valueOf(port)); } diff --git a/jbake-core/src/test/java/org/jbake/launcher/LaunchOptionsTest.java b/jbake-core/src/test/java/org/jbake/launcher/LaunchOptionsTest.java index 78d8060f4..2508159a9 100644 --- a/jbake-core/src/test/java/org/jbake/launcher/LaunchOptionsTest.java +++ b/jbake-core/src/test/java/org/jbake/launcher/LaunchOptionsTest.java @@ -1,14 +1,26 @@ package org.jbake.launcher; +import org.jbake.app.configuration.JBakeConfiguration; +import org.jbake.app.configuration.JBakeConfigurationFactory; import org.junit.Test; +import org.junit.runner.RunWith; import org.kohsuke.args4j.CmdLineParser; import java.io.File; +import org.mockito.Mock; +import org.mockito.Spy; +import org.mockito.junit.MockitoJUnitRunner; + import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.*; +@RunWith(MockitoJUnitRunner.class) public class LaunchOptionsTest { + @Spy + Main main; + @Test public void showHelp() throws Exception { String[] args = {"-h"}; @@ -31,13 +43,22 @@ public void runServer() throws Exception { @Test public void runServerWithFolder() throws Exception { - String[] args = {"-s", "/tmp"}; + String path = "/tmp"; + String[] args = {"-s", path}; LaunchOptions res = new LaunchOptions(); CmdLineParser parser = new CmdLineParser(res); parser.parseArgument(args); assertThat(res.isRunServer()).isTrue(); - assertThat(res.getSource()).isEqualTo(new File("/tmp")); + assertThat(res.getSource()).isEqualTo(new File(path)); + + // ensures path supplied is actually used when running server + JBakeConfiguration config = new JBakeConfigurationFactory().createJettyJbakeConfiguration(res.getSource(), res.getDestination(), res.isClearCache()); + // to stop server actually running when method is called + doNothing().when(main).runServer(any(File.class), any(Integer.class)); + main.run(res, config); + // verify method was called with correct path + verify(main).runServer(new File(path), config.getServerPort()); } @Test