Skip to content

Commit 69443e8

Browse files
authored
Merge pull request #6 from HeinrichFilter/master
Make snapshot file path configurable
2 parents 861b609 + 42b5ede commit 69443e8

File tree

5 files changed

+22
-5
lines changed

5 files changed

+22
-5
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package io.github.jsonSnapshot;
2+
3+
import lombok.Getter;
4+
5+
public class DefaultConfig implements SnapshotConfig {
6+
@Getter
7+
private String filePath = "src/test/java/";
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package io.github.jsonSnapshot;
2+
3+
public interface SnapshotConfig {
4+
String getFilePath();
5+
}

src/main/java/io/github/jsonSnapshot/SnapshotFile.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,15 @@
1515
public class SnapshotFile {
1616

1717
private static final String SPLIT_STRING = "\n\n\n";
18-
private static final String FILE_PATH = "src/test/java/";
1918

2019
private String fileName;
2120

2221
@Getter
2322
private Set<String> rawSnapshots;
2423

25-
SnapshotFile(String fileName) throws IOException {
24+
SnapshotFile(String filePath, String fileName) throws IOException {
2625

27-
this.fileName = FILE_PATH + fileName;
26+
this.fileName = filePath + fileName;
2827

2928
StringBuilder fileContent = new StringBuilder();
3029

src/main/java/io/github/jsonSnapshot/SnapshotMatcher.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,14 @@ public class SnapshotMatcher {
3232
private static List<Snapshot> calledSnapshots = new ArrayList<>();
3333

3434
public static void start() {
35+
start(new DefaultConfig());
36+
}
37+
38+
public static void start(SnapshotConfig config) {
3539
try {
3640
StackTraceElement stackElement = findStackElement();
3741
clazz = Class.forName(stackElement.getClassName());
38-
snapshotFile = new SnapshotFile(stackElement.getClassName().replaceAll("\\.", "/") + ".snap");
42+
snapshotFile = new SnapshotFile(config.getFilePath(), stackElement.getClassName().replaceAll("\\.", "/") + ".snap");
3943
} catch (ClassNotFoundException | IOException e) {
4044
throw new SnapshotMatchException(e.getMessage());
4145
}

src/test/java/io/github/jsonSnapshot/SnapshotTest.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
@RunWith(MockitoJUnitRunner.class)
1919
public class SnapshotTest {
2020

21+
private static final SnapshotConfig DEFAULT_CONFIG = new DefaultConfig();
2122
private static final String FILE_PATH = "src/test/java/anyFilePath";
2223
private static final String SNAPSHOT_NAME = "java.lang.String.toString=";
2324
private static final String SNAPSHOT = "java.lang.String.toString=[\n \"anyObject\"\n]";
@@ -29,7 +30,7 @@ public class SnapshotTest {
2930

3031
@Before
3132
public void setUp() throws NoSuchMethodException, IOException {
32-
snapshotFile = new SnapshotFile("anyFilePath");
33+
snapshotFile = new SnapshotFile(DEFAULT_CONFIG.getFilePath(), "anyFilePath");
3334
snapshot = new Snapshot(snapshotFile, String.class,
3435
String.class.getDeclaredMethod("toString"), "anyObject");
3536
}

0 commit comments

Comments
 (0)