Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
jonbullock committed Feb 19, 2019
1 parent 5858220 commit 3d1523c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion jbake-core/src/main/java/org/jbake/launcher/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand Down
25 changes: 23 additions & 2 deletions jbake-core/src/test/java/org/jbake/launcher/LaunchOptionsTest.java
Original file line number Diff line number Diff line change
@@ -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"};
Expand All @@ -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
Expand Down

0 comments on commit 3d1523c

Please sign in to comment.