Skip to content

Commit

Permalink
#3 Set up Maven Surefire to run tests properly. Added factory for App…
Browse files Browse the repository at this point in the history
…rovalScriptWriter
  • Loading branch information
maxbechtold committed Dec 31, 2017
1 parent b74f0a1 commit 0d7f828
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 25 deletions.
41 changes: 34 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<junit.jupiter.version>5.0.2</junit.jupiter.version>
<junit.platform.version>1.0.2</junit.platform.version>
</properties>

<dependencies>
Expand All @@ -36,21 +37,47 @@
<version>1.0.0</version>
</dependency>

<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.8.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.8.0</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-launcher</artifactId>
<version>1.0.2</version>
<version>${junit.platform.version}</version>
<scope>test</scope>
</dependency>


</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<excludes>
<exclude>**/ExampleGoldenMasterTest.java</exclude>
</excludes>
</configuration>
<dependencies>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-surefire-provider</artifactId>
<version>${junit.platform.version}</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit.jupiter.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ public ApprovalScriptWriter(OS os, File scriptFile) {
overwriteFlag = determineOverwriteFlag(os);
}

public File getScriptFile() {
return scriptFile;
}

private String determineOverwriteFlag(OS os) {
return os == OS.Windows ? "/Y" : "-f";
}
Expand Down Expand Up @@ -61,4 +65,19 @@ private void writeScriptContent() {
}
}

public static ApprovalScriptWriter create(String approvalScriptName) {
return new ApprovalScriptWriter(guessOperatingSystem(), getApprovalScriptFileName(approvalScriptName));
}

private static File getApprovalScriptFileName(String approvalScriptName) {
if (guessOperatingSystem() == OS.Windows) {
return new File(approvalScriptName + ".bat");
}
return new File(approvalScriptName);
}

private static OS guessOperatingSystem() {
return System.getProperty("os.name").toLowerCase().contains("win") ? OS.Windows : OS.ShellBased;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import maxbe.goldenmaster.approval.ApprovalScriptWriter;
import maxbe.goldenmaster.approval.FileConverter;
import maxbe.goldenmaster.approval.JUnitReporter;
import maxbe.goldenmaster.approval.OS;
import maxbe.goldenmaster.approval.TemplatedTestPathMapper;

public class RunInvocationContextProvider implements TestTemplateInvocationContextProvider, BeforeAllCallback,
Expand Down Expand Up @@ -65,26 +64,11 @@ private int determineRepetitions(ExtensionContext context) {

@Override
public void beforeAll(ExtensionContext context) throws Exception {
ApprovalScriptWriter approvalScriptWriter = createApprovalScriptWriter();
ApprovalScriptWriter approvalScriptWriter = ApprovalScriptWriter.create(APPROVAL_SCRIPT_NAME);
getStore(context).put(SCRIPT_WRITER_KEY, approvalScriptWriter);
getStore(context).put(REPORTER_KEY, new JUnitReporter(approvalScriptWriter));
}

private ApprovalScriptWriter createApprovalScriptWriter() {
return new ApprovalScriptWriter(guessOperatingSystem(), getApprovalScriptFileName());
}

private File getApprovalScriptFileName() {
if (guessOperatingSystem() == OS.Windows) {
return new File(APPROVAL_SCRIPT_NAME + ".bat");
}
return new File(APPROVAL_SCRIPT_NAME);
}

private OS guessOperatingSystem() {
return System.getProperty("os.name").toLowerCase().contains("win") ? OS.Windows : OS.ShellBased;
}

@Override
public void beforeEach(ExtensionContext context) throws Exception {
pathMapper = new TemplatedTestPathMapper<>(context, Paths.get("src", "test", "resources", "approved"));
Expand All @@ -108,7 +92,7 @@ public void afterAll(ExtensionContext context) throws Exception {
boolean scriptCreated = scriptWriter.updateScript();

if (scriptCreated) {
System.out.println("Not all approvals passed, please execute " + getApprovalScriptFileName()
System.out.println("Not all approvals passed, please execute " + scriptWriter.getScriptFile().getName()
+ " to approve current results");
}
outputFile.delete();
Expand Down

0 comments on commit 0d7f828

Please sign in to comment.