Skip to content
Settlers Journal
Go back

Introducing ResourceBundle for Player Resources and Expanding Unit Test Coverage

Edit page

TLDR

Introducing ResourceBundle class to represent the set of resources that a player has. Updating business logic and JSON serialization to leverage new ResourceBundle. Refactoring RollResult logic to be more testable. Adding unit test coverage to existing code / logic.

alt text

Mocking static method calls.

public class CatanGameTest {

  // mock calls to the random number generator
  MockedStatic<RollResult> mockedRollResult;

  // TODO not needed for most tests
  @BeforeEach
  public void beforeEach() {
    mockedRollResult = Mockito.mockStatic(RollResult.class);
    mockedRollResult.when(RollResult::getRandomNumber)
        .thenReturn(3)
        .thenReturn(3)
        .thenReturn(2)
        .thenReturn(2)
        .thenReturn(1)
        .thenReturn(1);
  }

  @AfterEach
  public void afterEach() {
    mockedRollResult.close();
  }

  .
  .
  .
}

Main work

Challenges

Learnings


Edit page
Share this post on:

Previous Post
Improving CatanGraph Test Coverage and Catching a HashMap Overwrite Bug
Next Post
Refactoring Graph Data Structures and Loading Board Layout from Files