Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
cjburkey01 committed Jun 19, 2024
1 parent e916c13 commit 0f6b0fb
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
6 changes: 6 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ tasks {
relocate("org.osgi", "claimchunk.dependency.org.osgi")
}

register<Delete>("cleanTests") {
delete(fileTree(mainDir).include("*.tmp.sqlite3"))
}

test {
useJUnitPlatform()

Expand All @@ -124,6 +128,8 @@ tasks {
"junit.jupiter.extensions.autodetection.enabled" to "true",
"junit.jupiter.testinstance.lifecycle.default" to "per_class"
)

finalizedBy("cleanTests")
}

clean {
Expand Down
46 changes: 46 additions & 0 deletions src/test/java/com/cjburkey/claimchunk/TestSQLPlease.java
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,52 @@ void insertOrUpdatePermission() {
}
}

@Test
void removeClaims() {
try (TestQlWrap wrapper = new TestQlWrap()) {
// Add random players
UUID ply1Uuid = UUID.randomUUID();
UUID ply2Uuid = UUID.randomUUID();
wrapper.sql.addPlayer(
new FullPlayerData(
ply1Uuid,
"SomeGuysName",
null,
System.currentTimeMillis(),
true,
0,
new ChunkPlayerPermissions(0)));
wrapper.sql.addPlayer(
new FullPlayerData(
ply2Uuid,
"OtherPersonsName",
"queenshit",
System.currentTimeMillis(),
false,
0,
new ChunkPlayerPermissions(0)));

// Add chunks
ChunkPos chunk1 = new ChunkPos("world", 824, -29);
ChunkPos chunk2 = new ChunkPos("world_nether", -4, 29);
wrapper.sql.addClaimedChunk(new DataChunk(chunk1, ply1Uuid, new HashMap<>(), null));
wrapper.sql.addClaimedChunk(new DataChunk(chunk2, ply2Uuid, new HashMap<>(), null));

// Delete one chunk
wrapper.sql.removeClaimedChunk(chunk2);

// Make sure chunk2 still exists but chunk1 doesn't.
Collection<DataChunk> chunks = wrapper.sql.getAllChunks();
assert chunks.stream().noneMatch(chunk -> chunk.chunk.equals(chunk2));

// Delete the other chunk
wrapper.sql.removeClaimedChunk(chunk1);

// Make sure no chunks are left.
assert wrapper.sql.getAllChunks().isEmpty();
}
}

protected static File randomDbFile() {
return new File(UUID.randomUUID() + ".tmp.sqlite3");
}
Expand Down

0 comments on commit 0f6b0fb

Please sign in to comment.