Volver al índice
src/main/java/ar/com/companeros/memory/PersistentMemoryTests.java
package ar.com.companeros.memory;
import ar.com.companeros.Companeros;
import java.nio.file.*;
import java.util.*;
import net.minecraft.core.*;
import net.minecraft.world.level.Level;
import net.minecraft.gametest.framework.*;
import net.minecraftforge.gametest.*;
@GameTestHolder(Companeros.ID)
@PrefixGameTestTemplate(false)
public final class PersistentMemoryTests {
@GameTest(template = "empty")
public void memoriesSurviveWorldReplacementWithoutImportingLocations(GameTestHelper helper) throws Exception {
Path root = Files.createTempDirectory("Raps-memory-test-"); UUID agent = UUID.randomUUID(), oldWorld = UUID.randomUUID(), newWorld = UUID.randomUUID();
try {
var position = GlobalPos.of(Level.OVERWORLD, new BlockPos(80, 60, 50));
var strategy = new MemoryRecord(UUID.randomUUID(), agent, oldWorld, position, 12345, 400,
MemoryType.STRATEGY, .9, .8, 12345, 400, MemoryOrigin.RESULT, "test", List.of(), "La defensa elevada funcionó", Set.of("defensa"), Set.of(), null, true);
var mine = new MemoryRecord(UUID.randomUUID(), agent, oldWorld, position, 12345, 400,
MemoryType.RESOURCE, .9, 1, 12345, 400, MemoryOrigin.OBSERVED, "test", List.of(), "Hierro aquí", Set.of("hierro"), Set.of(), null, true);
new PersistentMemoryArchive(root).sync(agent, List.of(strategy, mine));
PersistentMemoryArchive restarted = new PersistentMemoryArchive(root);
restarted.sync(agent, List.of());
helper.assertTrue(restarted.historical(agent, newWorld, "defensa").equals(List.of(strategy))
&& restarted.historical(agent, oldWorld, "defensa").isEmpty()
&& restarted.historical(UUID.randomUUID(), newWorld, "defensa").isEmpty(),
"Sobrevive al cambio de mundo y al reinicio, sin trasladar minas ni mezclar identidades");
helper.succeed();
} finally {
Files.deleteIfExists(root.resolve(agent + ".dat")); Files.deleteIfExists(root.resolve(agent + ".tmp")); Files.deleteIfExists(root);
}
}
}