Fix tests

This commit is contained in:
tastybento 2024-11-11 13:14:33 -08:00
parent 3870b200cd
commit 9fcee44888
3 changed files with 39 additions and 13 deletions

View File

@ -10,17 +10,17 @@ package world.bentobox.bentobox.database.objects.adapters;
*/ */
public interface AdapterInterface<S,V> { public interface AdapterInterface<S,V> {
/**
* Serialize object
* @param object - object to serialize
* @return serialized object
*/
S deserialize(Object object);
/** /**
* Deserialize object * Deserialize object
* @param object - object to deserialize * @param object - object to deserialize
* @return deserialized object * @return deserialized object
*/ */
S deserialize(Object object);
/**
* Serialize object
* @param object - object to serialize
* @return serialized object
*/
V serialize(Object object); V serialize(Object object);
} }

View File

@ -65,7 +65,7 @@ public class LogEntryListAdapter implements AdapterInterface<List<LogEntry>, Lis
history.forEach(logEntry -> { history.forEach(logEntry -> {
Map<String, Object> value = new LinkedHashMap<>(); Map<String, Object> value = new LinkedHashMap<>();
value.put(TIMESTAMP, logEntry.getTimestamp()); value.put(TIMESTAMP, logEntry.getTimestamp());
value.put(TYPE, logEntry.getType()); value.put(TYPE, logEntry.getType().name());
if (logEntry.getData() != null) { if (logEntry.getData() != null) {
value.put(DATA, logEntry.getData()); value.put(DATA, logEntry.getData());

View File

@ -7,6 +7,7 @@ import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
@ -14,6 +15,7 @@ import org.junit.Test;
import org.mockito.Mockito; import org.mockito.Mockito;
import world.bentobox.bentobox.api.logs.LogEntry; import world.bentobox.bentobox.api.logs.LogEntry;
import world.bentobox.bentobox.api.logs.LogEntry.LogType;
/** /**
* @author tastybento * @author tastybento
@ -28,8 +30,6 @@ public class LogEntryListAdapterTest {
private UUID issuer; private UUID issuer;
private List<LogEntry> toLog; private List<LogEntry> toLog;
/**
*/
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
config = new YamlConfiguration(); config = new YamlConfiguration();
@ -38,9 +38,11 @@ public class LogEntryListAdapterTest {
issuer = UUID.randomUUID(); issuer = UUID.randomUUID();
toLog = new ArrayList<>(); toLog = new ArrayList<>();
toLog.add(new LogEntry.Builder("BAN").data("player", target.toString()).data("issuer", issuer.toString()).build()); toLog.add(new LogEntry.Builder(LogType.BAN).data("player", target.toString()).data("issuer", issuer.toString())
toLog.add(new LogEntry.Builder("UNBAN").data("player", target.toString()).data("issuer", issuer.toString()).build()); .build());
toLog.add(new LogEntry.Builder("UNOWNED").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); 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<LogEntry> 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());
}
}
} }