Skip to content

Commit 27d4a43

Browse files
committed
Make path platform independent
1 parent 4327eae commit 27d4a43

File tree

2 files changed

+25
-9
lines changed

2 files changed

+25
-9
lines changed

httpsnippet/src/test/java/io/github/atkawa7/httpsnippet/fixtures/FixtureBuilder.java

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,36 @@
1111

1212
import com.fasterxml.jackson.databind.ObjectMapper;
1313
import com.smartbear.har.model.HarRequest;
14+
import org.apache.commons.lang3.SystemUtils;
1415

1516
@Slf4j
16-
@NoArgsConstructor(access = AccessLevel.PRIVATE)
1717
public class FixtureBuilder {
1818
private static final ObjectMapper objectMapper = new ObjectMapper();
1919
private final List<FixtureType> fixtureTypes = new ArrayList<>();
2020

21-
private static final String currentPath =
22-
Fixture.class.getProtectionDomain().getCodeSource().getLocation().getPath();
23-
public static final Path FIXTURES_INPUT_PATH = Paths.get(currentPath, "fixtures");
24-
public static final Path FIXTURES_OUTPUT_PATH = Paths.get(currentPath, "output");
21+
private final Path input;
22+
private final Path output;
23+
24+
private FixtureBuilder(){
25+
String currentPath = this.getClass().getProtectionDomain().getCodeSource().getLocation().getPath();
26+
currentPath = SystemUtils.IS_OS_WINDOWS? currentPath.substring(1) : currentPath;
27+
this.input = Paths.get(currentPath, "fixtures");
28+
this.output = Paths.get(currentPath, "output");
29+
}
2530

2631
public static FixtureBuilder builder() {
2732
return new FixtureBuilder();
2833
}
2934

35+
36+
public Path getInput() {
37+
return input;
38+
}
39+
40+
public Path getOutput() {
41+
return output;
42+
}
43+
3044
public FixtureBuilder applicationFormEncoded() {
3145
this.fixtureTypes.add(FixtureType.APPLICATION_FORM_ENCODED);
3246
return this;
@@ -101,8 +115,7 @@ public List<Fixture> build() throws Exception {
101115
List<Fixture> fixtures = new ArrayList<>();
102116
for (FixtureType fixtureType : fixtureTypes) {
103117
Path filePath =
104-
Paths.get(
105-
FIXTURES_INPUT_PATH.toString(), String.format("%s.json", fixtureType.getName()));
118+
Paths.get(input.toString(), String.format("%s.json", fixtureType.getName()));
106119
HarRequest harRequest = objectMapper.readValue(filePath.toFile(), HarRequest.class);
107120
fixtures.add(new Fixture(fixtureType, harRequest));
108121
}

httpsnippet/src/test/java/io/github/atkawa7/httpsnippet/fixtures/FixtureTest.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import lombok.extern.slf4j.Slf4j;
1111

1212
import org.apache.commons.io.FileUtils;
13+
import org.junit.jupiter.api.BeforeAll;
1314
import org.junit.jupiter.api.DisplayName;
1415
import org.junit.jupiter.params.ParameterizedTest;
1516
import org.junit.jupiter.params.provider.MethodSource;
@@ -22,9 +23,11 @@
2223
@Slf4j
2324
public class FixtureTest {
2425

26+
private static FixtureBuilder fixtureBuilder = FixtureBuilder.builder();
27+
2528
public static Stream<Fixture> fixtureStream() throws Exception {
2629
List<Fixture> fixtures =
27-
FixtureBuilder.builder()
30+
fixtureBuilder
2831
.applicationFormEncoded()
2932
.applicationJson()
3033
.cookies()
@@ -60,7 +63,7 @@ void testFixtures(Fixture fixture) throws Exception {
6063
String code = snippet.getCode();
6164
Path codeDir =
6265
Paths.get(
63-
FixtureBuilder.FIXTURES_OUTPUT_PATH.toString(),
66+
fixtureBuilder.getOutput().toString(),
6467
language.getKey().toLowerCase().replaceAll("[^a-zA-Z0-9-_\\.]", ""),
6568
client.getKey().toLowerCase().replaceAll("[^a-zA-Z0-9-_\\.]", ""));
6669
Path codePath =

0 commit comments

Comments
 (0)