Skip to content

Commit

Permalink
💥 remove csv extension as suggested in #26
Browse files Browse the repository at this point in the history
  • Loading branch information
tyrcho committed Sep 15, 2018
1 parent 334e08b commit dce3090
Show file tree
Hide file tree
Showing 12 changed files with 36 additions and 49 deletions.
10 changes: 5 additions & 5 deletions src/main/java/com/github/writethemfirst/approvals/Approvals.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public static void verifyAllFiles(final Path actualFolder) {
*/
public static <I1> void verifyAllCombinations(final Iterable<I1> args1, final Function1<I1, ?> f) {
final Approver approver = new Approver();
approver.csv().verify(applyCombinations(args1, f));
approver.verify(applyCombinations(args1, f));
}

/**
Expand Down Expand Up @@ -147,7 +147,7 @@ public static <I1, I2> void verifyAllCombinations(
final Function2<I1, I2, ?> f) {

final Approver approver = new Approver();
approver.csv().verify(applyCombinations(args1, args2, f));
approver.verify(applyCombinations(args1, args2, f));
}

/**
Expand Down Expand Up @@ -196,7 +196,7 @@ public static <I1, I2, I3> void verifyAllCombinations(
final Function3<I1, I2, I3, ?> f) {

final Approver approver = new Approver();
approver.csv().verify(applyCombinations(args1, args2, args3, f));
approver.verify(applyCombinations(args1, args2, args3, f));
}

/**
Expand Down Expand Up @@ -253,7 +253,7 @@ public static <I1, I2, I3, I4> void verifyAllCombinations(
final Function4<I1, I2, I3, I4, ?> f) {

final Approver approver = new Approver();
approver.csv().verify(applyCombinations(args1, args2, args3, args4, f));
approver.verify(applyCombinations(args1, args2, args3, args4, f));
}

/**
Expand Down Expand Up @@ -315,7 +315,7 @@ public static <I1, I2, I3, I4, I5> void verifyAllCombinations(
final Function5<I1, I2, I3, I4, I5, ?> f) {

final Approver approver = new Approver();
approver.csv().verify(applyCombinations(args1, args2, args3, args4, args5, f));
approver.verify(applyCombinations(args1, args2, args3, args4, args5, f));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,18 +130,9 @@ public Approver testing(final Class<?> testClass) {
return new Approver(reporter, customFileName, customExtension, testClass, header);
}

/**
* Force the extension to be "csv", useful in conjonction with {@link com.github.writethemfirst.approvals.utils.FunctionUtils}.
*
* @return a copy of this Approver
*/
public Approver csv() {
return new Approver(reporter, customFileName, ".csv", testClass, header);
}

/**
* Specifies a header naming the arguments of the function under test. This header prefixes the *approved* and
* *received* CSV files.
* *received* files.
*
* @param names one name for each argument
* @return a copy of this Approver
Expand Down Expand Up @@ -316,8 +307,8 @@ private String callerMethodName() {
private ApprovalFiles approvedAndReceivedPaths() {
return build(
folder,
customFileName != null ? customFileName : callerMethodName(),
customExtension);
customFileName != null ? customFileName : callerMethodName()
);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,12 @@ public ApprovalFiles resolve(final Path file) {
*
* @param folder The folder in which the approval files should be located
* @param methodName The name of the method calling the test. It is used to actually name the approval files
* @param extension The extension to use for the approval file (by default could be either *approved* or
* *received*)
* @return An {@link ApprovalFiles} object, containing the pair of generated *approved* and *received* entries
*/
//FIXME: That extension field should be removed or refactored. The String concatenation for the extension is super ugly.
public static ApprovalFiles build(final Path folder, final String methodName, final String extension) {
public static ApprovalFiles build(final Path folder, final String methodName) {
return new ApprovalFiles(
buildApprovalFilePath(folder, methodName, "approved" + extension),
buildApprovalFilePath(folder, methodName, "received" + extension));
buildApprovalFilePath(folder, methodName, "approved"),
buildApprovalFilePath(folder, methodName, "received"));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ void shouldCreateApprovedFiles() throws IOException {
// expected
}

assertThat(testUtils.approved.resolve("sample.xml"))
assertThat(testUtils.actual.resolve("sample.xml"))
.exists()
.hasContent("actual");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class ApprovalsSimpleTest {
void shouldThrowWhenMismatchAndUsingCommandReporter() {
final CommandReporter reporter = mock(CommandReporter.class);
final Approver approver = new Approver().reportTo(reporter);
final SimpleTestUtils testUtils = new SimpleTestUtils("shouldThrowWhenMismatchAndUsingCommandReporter", getClass(), "");
final SimpleTestUtils testUtils = new SimpleTestUtils("shouldThrowWhenMismatchAndUsingCommandReporter", getClass());

testUtils.writeApproved("approved text");

Expand All @@ -48,7 +48,7 @@ void shouldThrowWhenMismatchAndUsingCommandReporter() {

@Test
void shouldDoNothingWhenApprovedFileExistsAndIsCorrect() {
final SimpleTestUtils testUtils = new SimpleTestUtils("shouldDoNothingWhenApprovedFileExistsAndIsCorrect", getClass(), "");
final SimpleTestUtils testUtils = new SimpleTestUtils("shouldDoNothingWhenApprovedFileExistsAndIsCorrect", getClass());
testUtils.writeApproved("some text");

approver.verify("some text");
Expand All @@ -59,7 +59,7 @@ void shouldDoNothingWhenApprovedFileExistsAndIsCorrect() {

@Test
void shouldFailWhenApprovedFileExistsAndIsDifferent() {
final SimpleTestUtils testUtils = new SimpleTestUtils("shouldFailWhenApprovedFileExistsAndIsDifferent", getClass(), "");
final SimpleTestUtils testUtils = new SimpleTestUtils("shouldFailWhenApprovedFileExistsAndIsDifferent", getClass());
testUtils.writeApproved("expected text");

assertThatThrownBy(() -> approver.verify("actual text"))
Expand All @@ -72,7 +72,7 @@ void shouldFailWhenApprovedFileExistsAndIsDifferent() {

@Test
void shouldFailWhenApprovedFileDoesNotExist() {
final SimpleTestUtils testUtils = new SimpleTestUtils("shouldFailWhenApprovedFileDoesNotExist", getClass(), "");
final SimpleTestUtils testUtils = new SimpleTestUtils("shouldFailWhenApprovedFileDoesNotExist", getClass());
testUtils.cleanupPaths();

assertThatThrownBy(() -> approver.verify("text"))
Expand All @@ -85,7 +85,7 @@ void shouldFailWhenApprovedFileDoesNotExist() {

@Test
void shouldKeepReceivedFileWhenApprovedFileDoesNotExist() {
final SimpleTestUtils testUtils = new SimpleTestUtils("shouldKeepReceivedFileWhenApprovedFileDoesNotExist", getClass(), "");
final SimpleTestUtils testUtils = new SimpleTestUtils("shouldKeepReceivedFileWhenApprovedFileDoesNotExist", getClass());
testUtils.cleanupPaths();

try {
Expand All @@ -100,7 +100,7 @@ void shouldKeepReceivedFileWhenApprovedFileDoesNotExist() {

@Test
void shouldKeepReceivedFileWhenApprovedFileMismatch() {
final SimpleTestUtils testUtils = new SimpleTestUtils("shouldKeepReceivedFileWhenApprovedFileMismatch", getClass(), "");
final SimpleTestUtils testUtils = new SimpleTestUtils("shouldKeepReceivedFileWhenApprovedFileMismatch", getClass());
testUtils.writeApproved("approved");

try {
Expand All @@ -115,7 +115,7 @@ void shouldKeepReceivedFileWhenApprovedFileMismatch() {

@Test
void shouldRemoveReceivedFileWhenApprovedFileMatch() {
final SimpleTestUtils testUtils = new SimpleTestUtils("shouldRemoveReceivedFileWhenApprovedFileMatch", getClass(), "");
final SimpleTestUtils testUtils = new SimpleTestUtils("shouldRemoveReceivedFileWhenApprovedFileMatch", getClass());
testUtils.writeReceived("last content");
testUtils.writeApproved("same");

Expand All @@ -128,7 +128,7 @@ void shouldRemoveReceivedFileWhenApprovedFileMatch() {

@Test
void shouldCreateApprovedFile() {
final SimpleTestUtils testUtils = new SimpleTestUtils("shouldCreateApprovedFile", getClass(), "");
final SimpleTestUtils testUtils = new SimpleTestUtils("shouldCreateApprovedFile", getClass());
testUtils.cleanupPaths();

try {
Expand All @@ -146,7 +146,7 @@ void shouldCreateApprovedFile() {
void shouldUseSpecificMethodName() {
final Approver approver = new Approver().writeTo("my scala method").reportTo(new ThrowsReporter());

final SimpleTestUtils testUtils = new SimpleTestUtils("my_scala_method", getClass(), "");
final SimpleTestUtils testUtils = new SimpleTestUtils("my_scala_method", getClass());
testUtils.cleanupPaths();

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@

class ApprovalsVerifyAllTest {
private final Reporter reporter = mock(Reporter.class);
private final Approver approver = new Approver().reportTo(reporter).csv();
private final Approver approver = new Approver().reportTo(reporter);

@Test
void shouldReportMismatchWithSingleArgument() {
final SimpleTestUtils testUtils = new SimpleTestUtils("shouldReportMismatchWithSingleArgument", getClass(), ".csv");
final SimpleTestUtils testUtils = new SimpleTestUtils("shouldReportMismatchWithSingleArgument", getClass());

try {
final String combinations = applyCombinations(asList(1, 2, 3), x -> x + 1);
Expand All @@ -51,7 +51,7 @@ void shouldReportMismatchWithSingleArgument() {

@Test
void shouldReportMismatchWithTwoArguments() {
final SimpleTestUtils testUtils = new SimpleTestUtils("shouldReportMismatchWithTwoArguments", getClass(), ".csv");
final SimpleTestUtils testUtils = new SimpleTestUtils("shouldReportMismatchWithTwoArguments", getClass());
try {
final String combinations = applyCombinations(
asList(1, 2),
Expand All @@ -73,7 +73,7 @@ void shouldReportMismatchWithTwoArguments() {
void shouldReportMismatchWithFiveArguments() {

final SimpleTestUtils testUtils =
new SimpleTestUtils("shouldReportMismatchWithFiveArguments", getClass(), ".csv");
new SimpleTestUtils("shouldReportMismatchWithFiveArguments", getClass());

try {
final String combinations = applyCombinations(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class ReporterTest {

@Test
void approvalsShouldCallReporterWhenMismatch() {
final SimpleTestUtils testUtils = new SimpleTestUtils("approvalsShouldCallReporterWhenMismatch", getClass(), "");
final SimpleTestUtils testUtils = new SimpleTestUtils("approvalsShouldCallReporterWhenMismatch", getClass());
testUtils.writeApproved("some text");

try {
Expand All @@ -49,7 +49,7 @@ void approvalsShouldCallReporterWhenMismatch() {

@Test
void approvalsShouldCallReporterWhenNoApprovedFile() {
final SimpleTestUtils testUtils = new SimpleTestUtils("approvalsShouldCallReporterWhenNoApprovedFile", getClass(), "");
final SimpleTestUtils testUtils = new SimpleTestUtils("approvalsShouldCallReporterWhenNoApprovedFile", getClass());
testUtils.cleanupPaths();

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class JUnit5ReporterTest {

@Test
void shouldThrowWhenMismatch() {
final SimpleTestUtils testUtils = new SimpleTestUtils("shouldThrowWhenMismatch", getClass(), "");
final SimpleTestUtils testUtils = new SimpleTestUtils("shouldThrowWhenMismatch", getClass());
testUtils.writeApproved("some text");

assertThatThrownBy(() -> approvals.verify("other text"))
Expand All @@ -42,7 +42,7 @@ void shouldThrowWhenMismatch() {

@Test
void shouldThrowWhenMissing() {
final SimpleTestUtils testUtils = new SimpleTestUtils("shouldThrowWhenMismatch", getClass(), "");
final SimpleTestUtils testUtils = new SimpleTestUtils("shouldThrowWhenMismatch", getClass());
testUtils.cleanupPaths();

assertThatThrownBy(() -> approvals.verify("my text"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
*/
package com.github.writethemfirst.approvals.reporters.windows;

import com.github.writethemfirst.approvals.reporters.windows.Command;
import org.junit.jupiter.api.Test;

import java.io.File;
Expand All @@ -39,9 +38,9 @@

class CommandTest {
private final String OS_SEPARATOR = FileSystems.getDefault().getSeparator();
private String IDEA_8 = "IntelliJ IDEA 2018";
private String IDEA_712 = "IntelliJ IDEA 2017.1.2";
private String IDEA_73 = "IntelliJ IDEA 2017.3";
private final String IDEA_8 = "IntelliJ IDEA 2018";
private final String IDEA_712 = "IntelliJ IDEA 2017.1.2";
private final String IDEA_73 = "IntelliJ IDEA 2017.3";

@Test
void shouldExecuteIntelliJ() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public FolderTestUtils(final String methodName, final Class<?> testClass) throws
final String className = testClass.getSimpleName();
final Path packageResourcesPath = get("src/test/resources/", testClass.getPackage().getName().split("\\."));
final Path folderForClass = packageResourcesPath.resolve(className);
approvalFiles = build(folderForClass, methodName, "");
approvalFiles = build(folderForClass, methodName);
received = approvalFiles.received;
approved = approvalFiles.approved;
actual = Files.createTempDirectory(methodName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ public class SimpleTestUtils {
public final Path approved;
public final ApprovalFiles approvalFiles;

public SimpleTestUtils(final String methodName, final Class<?> testClass, final String extensionWithDot) {
public SimpleTestUtils(final String methodName, final Class<?> testClass) {
final String className = testClass.getSimpleName();
final Path packageResourcesPath = get("src/test/resources/", testClass.getPackage().getName().split("\\."));
final Path folderForClass = packageResourcesPath.resolve(className);
approvalFiles = build(folderForClass, methodName, extensionWithDot);
approvalFiles = build(folderForClass, methodName);
received = approvalFiles.received;
approved = approvalFiles.approved;
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/org/demo/simple/VerifyAll.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ void verifyAllWith3Arguments() {

@Test
void verifyAllWith3NamedArguments() {
final Approver approvals = new Approver().namedArguments("a", "b", "c").csv();
final Approver approvals = new Approver().namedArguments("a", "b", "c");
approvals.verify(applyCombinations(
asList(1, 10, 100),
asList(2, 20, 200),
Expand Down

0 comments on commit dce3090

Please sign in to comment.