@Test public void equals() { class TestCase extends GameEngineTestHelper.ComparisonTestCase<Contract> { TestCase(String name, Contract c1, Contract c2, boolean expected) { super(name, c1, c2, expected); } @Override protected void runAssertions() { assertThat(o1.equals(o2)).as("Check contract equality").isEqualTo(expected); } } List<TestCase> testCases = new ArrayList<>( List.of( new TestCase( "capot hearts - capot hearts", createCapotContract(Suit.HEARTS), createCapotContract(Suit.HEARTS), true), new TestCase( "generale clubs - generale clubs", createGeneraleContract(Suit.CLUBS), createGeneraleContract(Suit.CLUBS), true), new TestCase( "capot hearts - capot spades", createCapotContract(Suit.HEARTS), createCapotContract(Suit.SPADES), false), new TestCase( "capot hearts - generale hearts", createCapotContract(Suit.HEARTS), createGeneraleContract(Suit.HEARTS), false), new TestCase( "generale hearts - generale diamonds", createGeneraleContract(Suit.HEARTS), createGeneraleContract(Suit.DIAMONDS), false), new TestCase( "90 hearts - 90 hearts", createPointsContract(90, Suit.HEARTS), createPointsContract(90, Suit.HEARTS), true), new TestCase( "90 hearts - 130 hearts", createPointsContract(90, Suit.HEARTS), createPointsContract(130, Suit.HEARTS), false), new TestCase( "110 diamonds - 110 spades", createPointsContract(110, Suit.DIAMONDS), createPointsContract(110, Suit.SPADES), false), new TestCase( "capot hearts - 100 hearts", createCapotContract(Suit.HEARTS), createPointsContract(100, Suit.HEARTS), false), new TestCase( "generale hearts - 140 hearts", createGeneraleContract(Suit.HEARTS), createPointsContract(140, Suit.HEARTS), false))); testCases.forEach(TestCase::run); }
@Override public boolean equals(Object obj) { if (obj == null) { return false; } if (obj == this) { return true; } if (!(obj instanceof Contract)) { return false; } Contract otherContract = (Contract) obj; if (!this.suit.equals(otherContract.suit)) { return false; } return this.getEarnedPoints() == otherContract.getEarnedPoints(); }
Contract { @Override public boolean equals(Object obj) { if (obj == null) { return false; } if (obj == this) { return true; } if (!(obj instanceof Contract)) { return false; } Contract otherContract = (Contract) obj; if (!this.suit.equals(otherContract.suit)) { return false; } return this.getEarnedPoints() == otherContract.getEarnedPoints(); } }
Contract { @Override public boolean equals(Object obj) { if (obj == null) { return false; } if (obj == this) { return true; } if (!(obj instanceof Contract)) { return false; } Contract otherContract = (Contract) obj; if (!this.suit.equals(otherContract.suit)) { return false; } return this.getEarnedPoints() == otherContract.getEarnedPoints(); }  }
Contract { @Override public boolean equals(Object obj) { if (obj == null) { return false; } if (obj == this) { return true; } if (!(obj instanceof Contract)) { return false; } Contract otherContract = (Contract) obj; if (!this.suit.equals(otherContract.suit)) { return false; } return this.getEarnedPoints() == otherContract.getEarnedPoints(); }  abstract boolean isSuccessful(GameStatePlaying state); abstract int getEarnedPoints(); abstract String getValueShortName(); boolean isHigherThan(Contract other); @Override boolean equals(Object obj); Contract withPlayer(Player player); Suit getSuit(); Player getPlayer(); void setPlayer(Player player); String getShortName(); @Override String toString(); }
Contract { @Override public boolean equals(Object obj) { if (obj == null) { return false; } if (obj == this) { return true; } if (!(obj instanceof Contract)) { return false; } Contract otherContract = (Contract) obj; if (!this.suit.equals(otherContract.suit)) { return false; } return this.getEarnedPoints() == otherContract.getEarnedPoints(); }  abstract boolean isSuccessful(GameStatePlaying state); abstract int getEarnedPoints(); abstract String getValueShortName(); boolean isHigherThan(Contract other); @Override boolean equals(Object obj); Contract withPlayer(Player player); Suit getSuit(); Player getPlayer(); void setPlayer(Player player); String getShortName(); @Override String toString();  }