Content of file GameMemoryCapacityTest.java
package de.fhdw.gaming.ipspiel23.memory; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; import org.junit.jupiter.api.Test; /** * Tests for the {@link GameMemoryCapacity} class. */ public class GameMemoryCapacityTest { /** * Tests the {@link GameMemoryCapacity#unlimited()} method. */ @Test void testUnlimited() { final IGameMemoryCapacity capacity = GameMemoryCapacity.unlimited(); assertTrue(capacity.isUnlimited()); assertFalse(capacity.isDefault()); assertEquals(-1, capacity.getCapacity()); } /** * Tests the {@link GameMemoryCapacity#of(int)} method. */ @Test void testOf() { final int customCapacity = 10; final IGameMemoryCapacity capacity = GameMemoryCapacity.of(customCapacity); assertFalse(capacity.isUnlimited()); assertFalse(capacity.isDefault()); assertEquals(customCapacity, capacity.getCapacity()); } /** * Tests the {@link GameMemoryCapacity#useDefault()} method. */ @Test void testUseDefault() { final IGameMemoryCapacity capacity = GameMemoryCapacity.useDefault(); assertFalse(capacity.isUnlimited()); assertTrue(capacity.isDefault()); assertEquals(5, capacity.getCapacity()); } /** * Tests that an {@link IllegalArgumentException} is thrown when passing an invalid capacity to the * {@link GameMemoryCapacity#of(int)} method. */ @Test void testInvalidCapacity() { final Integer invalidCapacity = -1;
IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> {
Since Checkstyle 3.2
Checks that local variables that never have their values changed are declared final. The check can be configured to also check that unchanged parameters are declared final.
GameMemoryCapacity.of(invalidCapacity); }); assertEquals("Capacity must be greater than or equal to 0", exception.getMessage()); } }