|
12 | 12 |
|
13 | 13 | import org.junit.jupiter.api.BeforeEach; |
14 | 14 | import org.junit.jupiter.api.Test; |
| 15 | +import org.mockito.MockedStatic; |
15 | 16 |
|
16 | 17 | import net.tfminecraft.simplefactions.Cache; |
17 | 18 | import net.tfminecraft.simplefactions.objects.Faction; |
| 19 | +import net.tfminecraft.simplefactions.managers.RelationManager; |
18 | 20 | import net.tfminecraft.simplefactions.war.core.War; |
19 | 21 | import net.tfminecraft.simplefactions.war.enums.WarGoalType; |
20 | 22 | import net.tfminecraft.simplefactions.war.enums.WarType; |
@@ -78,6 +80,36 @@ void applyFromWar_attackerPaysDefenderWithCacheValues() { |
78 | 80 | assertEquals(10, obligations.get(0).getDaysRemaining()); |
79 | 81 | } |
80 | 82 |
|
| 83 | + @Test |
| 84 | + void apply_recursivelyAddsObligationToEveryVassalOnce() { |
| 85 | + Faction child = mockFaction("child"); |
| 86 | + Faction grandchild = mockFaction("grandchild"); |
| 87 | + List<WarReparationsObligation> childObligations = new ArrayList<>(); |
| 88 | + List<WarReparationsObligation> grandchildObligations = new ArrayList<>(); |
| 89 | + when(child.getWarReparationsObligations()).thenReturn(childObligations); |
| 90 | + when(grandchild.getWarReparationsObligations()).thenReturn(grandchildObligations); |
| 91 | + doAnswer(invocation -> { |
| 92 | + childObligations.add(invocation.getArgument(0)); |
| 93 | + return null; |
| 94 | + }).when(child).addWarReparationsObligation(org.mockito.ArgumentMatchers.any()); |
| 95 | + doAnswer(invocation -> { |
| 96 | + grandchildObligations.add(invocation.getArgument(0)); |
| 97 | + return null; |
| 98 | + }).when(grandchild).addWarReparationsObligation(org.mockito.ArgumentMatchers.any()); |
| 99 | + |
| 100 | + try (MockedStatic<RelationManager> relations = org.mockito.Mockito.mockStatic(RelationManager.class)) { |
| 101 | + relations.when(() -> RelationManager.getSubjects(payer)).thenReturn(List.of(child)); |
| 102 | + relations.when(() -> RelationManager.getSubjects(child)).thenReturn(List.of(grandchild)); |
| 103 | + relations.when(() -> RelationManager.getSubjects(grandchild)).thenReturn(List.of(payer)); |
| 104 | + assertTrue(WarReparationsService.apply(payer, payee)); |
| 105 | + } |
| 106 | + |
| 107 | + assertEquals(1, obligations.size()); |
| 108 | + assertEquals(1, childObligations.size()); |
| 109 | + assertEquals(1, grandchildObligations.size()); |
| 110 | + assertEquals("def", grandchildObligations.get(0).getPayeeFactionId()); |
| 111 | + } |
| 112 | + |
81 | 113 | private static Faction mockFaction(String id) { |
82 | 114 | Faction faction = mock(Faction.class); |
83 | 115 | when(faction.getId()).thenReturn(id); |
|
0 commit comments