Skip to content

Commit 635793d

Browse files
committed
Make test logic more robust
1 parent 0b056d0 commit 635793d

File tree

3 files changed

+29
-6
lines changed

3 files changed

+29
-6
lines changed

.github/workflows/ci.yml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,16 @@ jobs:
1919
java-version: '21'
2020
distribution: 'temurin'
2121
cache: maven
22-
22+
23+
- name: Verify test files exist
24+
run: |
25+
ls -R src/tests/java/data
26+
[ -f "src/tests/java/data/test1/expected1.out" ] || exit 1
27+
[ -f "src/tests/java/data/test1/test1.json" ] || exit 1
28+
29+
- name: Run tests
30+
run: mvn test
31+
2332
- name: Build with Maven
2433
run: mvn -B package --file pom.xml
2534

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,7 @@
2222
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
2323
hs_err_pid*
2424
replay_pid*
25+
26+
# Keep test data files
27+
!src/tests/java/data/**/*.json
28+
!src/tests/java/data/**/*.out

src/tests/java/Tests.java

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,29 @@
77
import org.junit.Test;
88

99
import core.FileOperations;
10+
import core.JSONObject;
1011
import core.JSONProcessor;
1112

1213
public class Tests {
1314

1415
@Test
1516
public void testNumbers() {
16-
String expected = String.join("\n", FileOperations.readFile(Path.of("src\\tests\\java\\data\\test1\\expected1.out")));
17-
assertNotNull("Expected file content should not be null", expected);
17+
// Normalize path separators for cross-platform compatibility
18+
Path expectedPath = Path.of("src", "tests", "java", "data", "test1", "expected1.out");
19+
Path testPath = Path.of("src", "tests", "java", "data", "test1", "test1.json");
1820

19-
String result = JSONProcessor.processJson(Path.of("src\\tests\\java\\data\\test1\\test1.json")).toString();
20-
assertNotNull("Processed JSON should not be null", result);
21+
// Read and normalize the expected content
22+
List<String> expectedLines = FileOperations.readFile(expectedPath);
23+
assertNotNull("Expected file content should not be null", expectedLines);
24+
String expected = String.join(System.lineSeparator(), expectedLines).trim();
2125

22-
assertEquals(expected, result);
26+
// Process and normalize the actual result
27+
JSONObject processed = JSONProcessor.processJson(testPath);
28+
assertNotNull("Processed JSON should not be null", processed);
29+
String result = processed.toString().trim();
30+
31+
// Compare normalized strings
32+
assertEquals("JSON content does not match expected output", expected, result);
2333
}
2434

2535
@Test

0 commit comments

Comments
 (0)