Ilmari Vacklin avatar Ilmari Vacklin committed 52c348e

Print "Build started" to the user.

Includes some test refactors.

Comments (0)

Files changed (6)

src/main/java/net/wolverian/march/CommandLine.java

 
 import net.wolverian.march.builders.*;
 
-public class CommandLine {
+public class CommandLine implements BuildListener {
     public static void main(String[] arguments) {
-        new PosixMaven().build();
+        new CommandLine().run();
+    }
+
+    private void run() {
+        new PosixMaven().withListener(this).build();
+    }
+
+    @Override
+    public void buildStarted() {
+        System.out.println("Build started");
     }
 }

src/test/java/net/wolverian/march/CommandLineIT.java

 
 	@Test
 	public void shouldBuildAMavenProject() throws IOException, InterruptedException {
-        ProcessBuilder builder = createBuilder().directory(project.toFile());
-
-        final Process process = builder.start();
-
+        final Process process = runBuild();
         assertThat(CharStreams.toString(new InputStreamReader(process.getErrorStream())), is(""));
         assertThat(process.exitValue(), is(0));
 		assertThat(builtFiles(project.resolve("target")), hasItem(endsWith(".jar")));
 	}
 
+    @Test
+    public void shouldPrintBuildStartedNotification() throws IOException, InterruptedException {
+        Process process = runBuild();
+        assertThat(CharStreams.toString(new InputStreamReader(process.getInputStream())), containsString("Build started"));
+    }
+
+    private Process runBuild() throws IOException, InterruptedException {
+        Process process = createBuilder().directory(project.toFile()).start();
+        process.waitFor();
+        return process;
+    }
+
     private ProcessBuilder createBuilder() {
         String os = System.getProperty("os.name");
 

src/test/java/net/wolverian/march/builders/MavenIT.java

+package net.wolverian.march.builders;
+
+import net.wolverian.march.*;
+import net.wolverian.march.fixtures.*;
+import org.jmock.*;
+import org.jmock.integration.junit4.*;
+import org.junit.*;
+
+import java.nio.file.*;
+
+import static net.wolverian.march.Util.builtFiles;
+import static org.hamcrest.Matchers.endsWith;
+import static org.hamcrest.Matchers.hasItem;
+import static org.junit.Assert.assertThat;
+
+public abstract class MavenIT {
+    @Rule
+    public JUnitRuleMockery context = new JUnitRuleMockery();
+    @Rule
+    public Projects projects = new Projects();
+
+    private final BuildListener listener = context.mock(BuildListener.class);
+
+    private Path path = projects.createMavenProject();
+
+    @Test
+    public void shouldNotifyListenersWhenBuildStarted() {
+        context.checking(new Expectations() {{
+            oneOf(listener).buildStarted();
+        }});
+
+        Maven maven = getMaven();
+
+        maven.withListener(listener)
+             .in(path)
+             .build();
+    }
+
+    @Test
+    public void shouldBuildIntoTarget() {
+        Maven maven = getMaven();
+
+        maven.in(path).build();
+
+        assertThat(builtFiles(path.resolve("target")), hasItem(endsWith(".class")));
+    }
+
+    protected abstract Maven getMaven();
+}

src/test/java/net/wolverian/march/builders/MavenTest.java

-package net.wolverian.march.builders;
-
-import net.wolverian.march.*;
-import net.wolverian.march.fixtures.*;
-import org.jmock.*;
-import org.jmock.integration.junit4.*;
-import org.junit.*;
-
-import java.nio.file.*;
-
-import static net.wolverian.march.Util.builtFiles;
-import static org.hamcrest.Matchers.endsWith;
-import static org.hamcrest.Matchers.hasItem;
-import static org.junit.Assert.assertThat;
-
-public abstract class MavenTest {
-    @Rule
-    public JUnitRuleMockery context = new JUnitRuleMockery();
-    private final BuildListener listener = context.mock(BuildListener.class);
-
-    @Rule
-    public Projects projects = new Projects();
-
-    private Path path = projects.createMavenProject();
-
-    @Test
-    public void foo() {
-        context.checking(new Expectations() {{
-            oneOf(listener).buildStarted();
-        }});
-
-        Maven maven = getMaven();
-
-        maven.withListener(listener)
-             .in(path)
-             .build();
-    }
-
-    @Test
-    public void bar() {
-        Maven maven = getMaven();
-
-        maven.in(path).build();
-
-        assertThat(builtFiles(path.resolve("target")), hasItem(endsWith(".class")));
-    }
-
-    protected abstract Maven getMaven();
-}

src/test/java/net/wolverian/march/builders/PosixMavenIT.java

+package net.wolverian.march.builders;
+
+public class PosixMavenIT extends MavenIT {
+    @Override
+    protected Maven getMaven() {
+        return new PosixMaven();
+    }
+}

src/test/java/net/wolverian/march/builders/PosixMavenTest.java

-package net.wolverian.march.builders;
-
-public class PosixMavenTest extends MavenTest {
-    @Override
-    protected Maven getMaven() {
-        return new PosixMaven();
-    }
-}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.