Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions src/test/java/com/toofifty/goaltracker/GoalSerializerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,19 @@
//noinspection UnstableApiUsage
@SuppressWarnings("null")
public class GoalSerializerTest {
/**
* Normalizes all line endings to LF (\n) for consistent string comparisons across platforms.
*
* @param dirtyString The string whose line-endings you want to normalize.
* @return The normalized string with the requested line endings.
*/
private String normalizeLineEndings(String dirtyString) {
if (dirtyString == null) return null;

// Replace and return LF line endings
return dirtyString.replace("\r\n", "\n").replace("\r", "\n");
}

GoalSerializer serializer;

@BeforeEach
Expand Down Expand Up @@ -127,8 +140,10 @@ public void serialize_should_convert_goals_to_json() throws IOException {
.build()
);

assertEquals(expectedJson, serializer.serialize(goals, true));

assertEquals(
normalizeLineEndings(expectedJson),
normalizeLineEndings(serializer.serialize(goals, true))
);
}

@Test
Expand Down Expand Up @@ -178,6 +193,9 @@ public void serialize_should_support_other_task_types() throws IOException {
))).build()
);

assertEquals(expectedJson, serializer.serialize(goals, true));
assertEquals(
normalizeLineEndings(expectedJson),
normalizeLineEndings(serializer.serialize(goals, true))
);
}
}