Skip to content
Settlers Journal
Go back

Improving CatanGraph Test Coverage and Catching a HashMap Overwrite Bug

Edit page

TLDR

Improving test coverage for CatanGraph. Actually found a pretty nice bug! Overriding equals and hashCode of ResourceBundle so tests can do easy equality checks. Hitting all branches of conditional logic so Jacoco is happy.

alt text alt text

Equals and Hash Code overrides.

@Override
public boolean equals(Object o) {
  if (this == o) {
    return true;
  }
  if (o instanceof ResourceBundle that) {
    return Objects.equals(resources, that.resources);
  } else {
    return false;
  }
}

@Override
public int hashCode() {
  return Objects.hash(
      ALL_RESOURCE_COLORS.stream().map(resources::get).toArray()
  );
}

Main work

Challenges

Learnings


Edit page
Share this post on:

Previous Post
Printing the FSM Definition at Startup and Discovering a Design Code Smell
Next Post
Introducing ResourceBundle for Player Resources and Expanding Unit Test Coverage