Skip to content

Commit b5c12a7

Browse files
author
Heinrich Filter
committed
Make snapshot file path configurable
1 parent 861b609 commit b5c12a7

File tree

4 files changed

+14
-5
lines changed

4 files changed

+14
-5
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package io.github.jsonSnapshot;
2+
3+
public class Config {
4+
public String filePath = "src/test/java/";
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 Config());
36+
}
37+
38+
public static void start(Config 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.filePath,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 Config DEFAULT_CONFIG = new Config();
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.filePath,"anyFilePath");
3334
snapshot = new Snapshot(snapshotFile, String.class,
3435
String.class.getDeclaredMethod("toString"), "anyObject");
3536
}

0 commit comments

Comments
 (0)