mirror of
https://github.com/magefree/mage.git
synced 2026-01-10 04:42:07 -08:00
Merge pull request #11411 from tirth1/refactor-gameController
This commit is contained in:
commit
892b4ebd95
4 changed files with 191 additions and 77 deletions
|
|
@ -7,6 +7,7 @@ import com.google.common.collect.ImmutableSortedSet;
|
|||
import mage.constants.WatcherScope;
|
||||
import mage.game.Game;
|
||||
import mage.game.events.GameEvent;
|
||||
import mage.players.PlayerList;
|
||||
import mage.watchers.Watcher;
|
||||
import org.junit.Test;
|
||||
|
||||
|
|
@ -187,6 +188,8 @@ public class WatcherTest {
|
|||
|
||||
private Map<String, SortedSet<String>> sortedSetInMapField = new HashMap<>();
|
||||
|
||||
private Map<String, PlayerList> playerListInMapField = new HashMap<>();
|
||||
|
||||
public TestWatcher(WatcherScope scope) {
|
||||
super(scope);
|
||||
}
|
||||
|
|
@ -248,8 +251,41 @@ public class WatcherTest {
|
|||
return sortedSetInMapField;
|
||||
}
|
||||
|
||||
public Map<String, PlayerList> getPlayerListInMapField() {
|
||||
return playerListInMapField;
|
||||
}
|
||||
|
||||
public void setSortedSetInMapField(Map<String, SortedSet<String>> sortedSetInMapField) {
|
||||
this.sortedSetInMapField = sortedSetInMapField;
|
||||
}
|
||||
|
||||
public void setPlayerListInMapField(Map<String, PlayerList> playerListInMapField) {
|
||||
this.playerListInMapField = playerListInMapField;
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeepCopyMapOfPlayerList() {
|
||||
// Given
|
||||
Map<String, PlayerList> playerListInMapField = new HashMap<>();
|
||||
playerListInMapField.put("pl1", new PlayerList());
|
||||
playerListInMapField.put("pl2", new PlayerList());
|
||||
|
||||
TestWatcher testWatcher = new TestWatcher(GAME);
|
||||
testWatcher.setPlayerListInMapField(playerListInMapField);
|
||||
|
||||
// When
|
||||
TestWatcher copy = testWatcher.copy();
|
||||
|
||||
// And
|
||||
testWatcher.getPlayerListInMapField().put("pl3", new PlayerList());
|
||||
|
||||
// Then
|
||||
Map<String, PlayerList> copyPlayerListInMapField = copy.getPlayerListInMapField();
|
||||
assertEquals(2, copyPlayerListInMapField.size());
|
||||
assertTrue(copyPlayerListInMapField.containsKey("pl1"));
|
||||
assertTrue(copyPlayerListInMapField.containsKey("pl2"));
|
||||
assertFalse(copyPlayerListInMapField.containsKey("pl3"));
|
||||
assertEquals(copyPlayerListInMapField.get("pl1").getClass(), playerListInMapField.get("pl1").getClass());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -85,4 +85,27 @@ public class CounterTest {
|
|||
assertEquals(1, defaultCounter.getCount());
|
||||
assertEquals("default", defaultCounter.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHashCodeConsistency() {
|
||||
// given
|
||||
|
||||
// when
|
||||
Counter copy = new Counter(counter);
|
||||
|
||||
//then
|
||||
assertEquals(counter.hashCode(), copy.hashCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEqualsReturnsFalse() {
|
||||
// given
|
||||
Counter testCounter = new Counter("default", 1);
|
||||
|
||||
// when
|
||||
|
||||
//then
|
||||
assertFalse(counter.equals(testCounter));
|
||||
assertFalse(counter.equals(null));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
98
Mage/src/test/java/mage/counters/CountersTest.java
Normal file
98
Mage/src/test/java/mage/counters/CountersTest.java
Normal file
|
|
@ -0,0 +1,98 @@
|
|||
package mage.counters;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class CountersTest {
|
||||
private Counters counters;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
counters = new Counters();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCopyCounter() {
|
||||
// given
|
||||
counters.addCounter("test", 4);
|
||||
|
||||
// when
|
||||
Counters copy = counters.copy();
|
||||
|
||||
// then
|
||||
int amount = copy.getCount("test");
|
||||
assertEquals(5, amount);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemoveCounter() {
|
||||
// given
|
||||
counters.addCounter("test1", 5);
|
||||
counters.addCounter("test2", 5);
|
||||
|
||||
// when
|
||||
|
||||
//then
|
||||
assertTrue(counters.removeCounter("test1", 6));
|
||||
assertFalse(counters.containsKey("test1"));
|
||||
assertTrue(counters.removeCounter("test2", 2));
|
||||
assertTrue(counters.containsKey("test2"));
|
||||
assertFalse(counters.removeCounter("test3", 5));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddCounterWithNewCounter() {
|
||||
// given
|
||||
counters.addCounter("test1", 5);
|
||||
|
||||
// when
|
||||
counters.addCounter("test1", 10);
|
||||
counters.addCounter("test2", 5);
|
||||
|
||||
// then
|
||||
assertNotEquals(15, counters.getCount("test1"));
|
||||
assertEquals(16, counters.getCount("test1"));
|
||||
assertTrue(counters.containsKey("test2"));
|
||||
assertEquals(6, counters.getCount("test2"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemoveAllCounter() {
|
||||
// given
|
||||
counters.addCounter("test", 10);
|
||||
|
||||
// when
|
||||
counters.removeAllCounters("test");
|
||||
|
||||
// then
|
||||
assertFalse(counters.containsKey("test"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetCount() {
|
||||
// given
|
||||
counters.addCounter("test1", 5);
|
||||
|
||||
// when
|
||||
int count1 = counters.getCount("test1");
|
||||
int count2 = counters.getCount("test2");
|
||||
|
||||
// then
|
||||
assertEquals(0, count2);
|
||||
assertEquals(6, count1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testContainsKey() {
|
||||
// given
|
||||
counters.addCounter("test1", 5);
|
||||
|
||||
// when
|
||||
|
||||
// then
|
||||
assertTrue(counters.containsKey("test1"));
|
||||
assertFalse(counters.containsKey("test2"));
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue