Skip to content

Commit c53378b

Browse files
committed
test: add unit test against duplicate keys
1 parent 4905d54 commit c53378b

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

bukkit/src/test/java/net/william278/husktowns/BukkitPluginTests.java

+20-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import be.seeseemelk.mockbukkit.ServerMock;
2424
import com.google.common.collect.ImmutableList;
2525
import net.william278.husktowns.audit.Action;
26+
import net.william278.husktowns.audit.Log;
2627
import net.william278.husktowns.claim.*;
2728
import net.william278.husktowns.map.MapSquare;
2829
import net.william278.husktowns.town.Town;
@@ -334,7 +335,7 @@ private static Stream<Arguments> getTownAndMayorParameters() {
334335
@Order(5)
335336
@Nested
336337
@DisplayName("Town Schema Update Tests")
337-
public class TownSchemaUpdateTests {
338+
public class TownSchemaTests {
338339

339340
@Order(1)
340341
@DisplayName("Test Town Schema Update")
@@ -351,6 +352,24 @@ public void testTownSchemaUpdate() {
351352
);
352353
}
353354

355+
@Order(2)
356+
@DisplayName("Test Deserializing Town Log with Duplicate Keys")
357+
@Test
358+
public void testTownLogSerialization() {
359+
final String logJson = """
360+
{
361+
"actions": {
362+
"2024-02-04T15:09:34.661609Z": { "action": "CREATE_TOWN" },
363+
"2024-02-04T15:09:34.661609Z": { "action": "CREATE_TOWN" }
364+
}
365+
}""";
366+
final Log log = plugin.getGson().fromJson(logJson, Log.class);
367+
Assertions.assertNotNull(log, "Failed to deserialize log with duplicate keys");
368+
369+
final Map<OffsetDateTime, Action> actions = log.getActions();
370+
Assertions.assertEquals(1, actions.size(), "Duplicate keys were not removed on load");
371+
}
372+
354373
}
355374

356375
@NotNull

0 commit comments

Comments
 (0)