diff --git a/src/main/java/world/bentobox/bentobox/database/objects/adapters/AdapterInterface.java b/src/main/java/world/bentobox/bentobox/database/objects/adapters/AdapterInterface.java index 096e59b07..7c688b9d1 100644 --- a/src/main/java/world/bentobox/bentobox/database/objects/adapters/AdapterInterface.java +++ b/src/main/java/world/bentobox/bentobox/database/objects/adapters/AdapterInterface.java @@ -10,17 +10,17 @@ package world.bentobox.bentobox.database.objects.adapters; */ public interface AdapterInterface { - /** - * Serialize object - * @param object - object to serialize - * @return serialized object - */ - S deserialize(Object object); - /** * Deserialize object * @param object - object to deserialize * @return deserialized object */ + S deserialize(Object object); + + /** + * Serialize object + * @param object - object to serialize + * @return serialized object + */ V serialize(Object object); } diff --git a/src/main/java/world/bentobox/bentobox/database/objects/adapters/LogEntryListAdapter.java b/src/main/java/world/bentobox/bentobox/database/objects/adapters/LogEntryListAdapter.java index b687263c0..d3b38f358 100644 --- a/src/main/java/world/bentobox/bentobox/database/objects/adapters/LogEntryListAdapter.java +++ b/src/main/java/world/bentobox/bentobox/database/objects/adapters/LogEntryListAdapter.java @@ -65,7 +65,7 @@ public class LogEntryListAdapter implements AdapterInterface, Lis history.forEach(logEntry -> { Map value = new LinkedHashMap<>(); value.put(TIMESTAMP, logEntry.getTimestamp()); - value.put(TYPE, logEntry.getType()); + value.put(TYPE, logEntry.getType().name()); if (logEntry.getData() != null) { value.put(DATA, logEntry.getData()); diff --git a/src/test/java/world/bentobox/bentobox/database/objects/adapters/LogEntryListAdapterTest.java b/src/test/java/world/bentobox/bentobox/database/objects/adapters/LogEntryListAdapterTest.java index ce91f6469..d6620aec9 100644 --- a/src/test/java/world/bentobox/bentobox/database/objects/adapters/LogEntryListAdapterTest.java +++ b/src/test/java/world/bentobox/bentobox/database/objects/adapters/LogEntryListAdapterTest.java @@ -7,6 +7,7 @@ import java.util.LinkedList; import java.util.List; import java.util.UUID; +import org.bukkit.configuration.InvalidConfigurationException; import org.bukkit.configuration.file.YamlConfiguration; import org.junit.After; import org.junit.Before; @@ -14,6 +15,7 @@ import org.junit.Test; import org.mockito.Mockito; import world.bentobox.bentobox.api.logs.LogEntry; +import world.bentobox.bentobox.api.logs.LogEntry.LogType; /** * @author tastybento @@ -28,8 +30,6 @@ public class LogEntryListAdapterTest { private UUID issuer; private List toLog; - /** - */ @Before public void setUp() throws Exception { config = new YamlConfiguration(); @@ -38,9 +38,11 @@ public class LogEntryListAdapterTest { issuer = UUID.randomUUID(); toLog = new ArrayList<>(); - toLog.add(new LogEntry.Builder("BAN").data("player", target.toString()).data("issuer", issuer.toString()).build()); - toLog.add(new LogEntry.Builder("UNBAN").data("player", target.toString()).data("issuer", issuer.toString()).build()); - toLog.add(new LogEntry.Builder("UNOWNED").build()); + toLog.add(new LogEntry.Builder(LogType.BAN).data("player", target.toString()).data("issuer", issuer.toString()) + .build()); + toLog.add(new LogEntry.Builder(LogType.UNBAN).data("player", target.toString()) + .data("issuer", issuer.toString()).build()); + toLog.add(new LogEntry.Builder(LogType.UNOWNED).build()); history.addAll(toLog); } @@ -67,4 +69,28 @@ public class LogEntryListAdapterTest { } } + /** + * Test method for {@link world.bentobox.bentobox.database.objects.adapters.LogEntryListAdapter#serialize(java.lang.Object)} + * and {@link world.bentobox.bentobox.database.objects.adapters.LogEntryListAdapter#deserialize(java.lang.Object)}. + * @throws InvalidConfigurationException + */ + @Test + public void testSerializeDeserializeUnknownHistory() throws InvalidConfigurationException { + // Make entries using unknown types + String bad = "test:\n" + " history:\n" + " - timestamp: 1731359067207\n" + " type: WEIRD\n" + " data:\n" + + " player: 3f9d5634-331e-4598-9445-7449d56f7f74\n" + + " issuer: b366ba84-adec-42fe-b9dc-2c6a7b26f067\n" + " - timestamp: 1731359067207\n" + + " type: ENTRY\n" + " data:\n" + " player: 3f9d5634-331e-4598-9445-7449d56f7f74\n" + + " issuer: b366ba84-adec-42fe-b9dc-2c6a7b26f067\n" + " - timestamp: 1731359067207\n" + + " type: SUPER\n" + " data: {}"; + config.loadFromString(bad); + + // Verify + List historyCheck = a.deserialize(config.get("test.history")); + assertEquals(3, historyCheck.size()); + for (int i = 0; i < historyCheck.size(); i++) { + assertEquals(LogType.UNKNOWN, historyCheck.get(i).getType()); + } + } + }