Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tastybento committed Nov 11, 2024
1 parent 3870b20 commit 9fcee44
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@
public interface AdapterInterface<S,V> {

/**
* Serialize object
* @param object - object to serialize
* @return serialized object
* Deserialize object
* @param object - object to deserialize
* @return deserialized object
*/
S deserialize(Object object);

/**
* Deserialize object
* @param object - object to deserialize
* @return deserialized object
* Serialize object
* @param object - object to serialize
* @return serialized object
*/
V serialize(Object object);
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public List<Map<String, Object>> serialize(Object object) {
history.forEach(logEntry -> {
Map<String, Object> 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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
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;
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
Expand All @@ -28,8 +30,6 @@ public class LogEntryListAdapterTest {
private UUID issuer;
private List<LogEntry> toLog;

/**
*/
@Before
public void setUp() throws Exception {
config = new YamlConfiguration();
Expand All @@ -38,9 +38,11 @@ public void setUp() throws Exception {
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);
}

Expand All @@ -67,4 +69,28 @@ public void testSerializeDeserialize() {
}
}

/**
* 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());
}
}

}

0 comments on commit 9fcee44

Please sign in to comment.