Skip to content

Commit eb8c1d8

Browse files
Add tests for arena revocation controller
1 parent e758799 commit eb8c1d8

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package io.github.legendaryforge.legendary.core.internal.legendary.arena;
2+
3+
import static org.junit.jupiter.api.Assertions.assertFalse;
4+
import static org.junit.jupiter.api.Assertions.assertTrue;
5+
6+
import io.github.legendaryforge.legendary.core.api.event.EventBus;
7+
import io.github.legendaryforge.legendary.core.api.event.Subscription;
8+
import io.github.legendaryforge.legendary.core.api.id.ResourceId;
9+
import io.github.legendaryforge.legendary.core.internal.event.SimpleEventBus;
10+
import io.github.legendaryforge.legendary.core.internal.legendary.arena.event.ParticipationRevokedEvent;
11+
import java.util.UUID;
12+
import java.util.concurrent.atomic.AtomicBoolean;
13+
import org.junit.jupiter.api.Test;
14+
15+
final class ArenaRevocationControllerTest {
16+
17+
@Test
18+
void revokeMarksTrackerAndEmitsEventForLegendaryInstances() {
19+
EventBus bus = new SimpleEventBus();
20+
ArenaRevocationTracker tracker = new ArenaRevocationTracker();
21+
22+
AtomicBoolean seen = new AtomicBoolean(false);
23+
Subscription sub = bus.subscribe(ParticipationRevokedEvent.class, e -> seen.set(true));
24+
25+
ArenaRevocationController controller = new ArenaRevocationController(tracker, bus, id -> true);
26+
27+
UUID instanceId = UUID.randomUUID();
28+
UUID playerId = UUID.randomUUID();
29+
controller.revoke(instanceId, playerId, new ResourceId("legendary", "rule_violation"));
30+
31+
assertTrue(tracker.isRevoked(instanceId, playerId), "tracker should mark revoked");
32+
assertTrue(seen.get(), "should emit ParticipationRevokedEvent");
33+
34+
sub.unsubscribe();
35+
}
36+
37+
@Test
38+
void revokeNoopsForNonLegendaryInstances() {
39+
EventBus bus = new SimpleEventBus();
40+
ArenaRevocationTracker tracker = new ArenaRevocationTracker();
41+
42+
AtomicBoolean seen = new AtomicBoolean(false);
43+
Subscription sub = bus.subscribe(ParticipationRevokedEvent.class, e -> seen.set(true));
44+
45+
ArenaRevocationController controller = new ArenaRevocationController(tracker, bus, id -> false);
46+
47+
UUID instanceId = UUID.randomUUID();
48+
UUID playerId = UUID.randomUUID();
49+
controller.revoke(instanceId, playerId, new ResourceId("legendary", "rule_violation"));
50+
51+
assertFalse(tracker.isRevoked(instanceId, playerId), "tracker should not mark revoked");
52+
assertFalse(seen.get(), "should not emit ParticipationRevokedEvent");
53+
54+
sub.unsubscribe();
55+
}
56+
}

0 commit comments

Comments
 (0)