@Test
public void testAchievementsSize(){
Player player = getPlayer();
List<Achievement> playerAchievements = achievementManager.checkForPlayerAchievements(preparePlayerStatistics(player));
assertEquals(3,playerAchievements.size());
assertThat(playerAchievements, containsInAnyOrder(new BruiserAward(),new SharpShooterAward(),new FastKillerAward()));
}
вызывает следующую ошибку:
java.lang.AssertionError:
Expected: iterable over [<Bruiser>, <Sharp shooter>, <Fast Killer>] in any order
but: Not matched: <Bruiser>
at org.hamcrest.MatcherAssert.assertThat(MatcherAssert.java:20)
at org.junit.Assert.assertThat(Assert.java:956)
at org.junit.Assert.assertThat(Assert.java:923)
Hashcode
и equals
переопределяется, как показано ниже:
@Override
public int hashCode() {
return this.getName().hashCode();
}
@Override
public boolean equals(Object obj) {
if(obj != null && obj instanceof Achievement){
Achievement achievement = (Achievement) obj;
achievement.getName().equals(this.getName());
}
return false;
}
Испытаны решения ArrayList равенство JUnitтестирование присутствует здесь с использованием assertTrue
и assertArrayEquals
, но не повезло
Я что-то упустил?
Обновление:
Попробовал ниже:
@Test
public void testAchievementsSize(){
Player player = getPlayer();
List<Achievement> playerAchievements = achievementManager.checkForPlayerAchievements(preparePlayerStatistics(player));
assertEquals(3,playerAchievements.size());
assertArrayEquals(playerAchievements.toArray(new Achievement[playerAchievements.size()]),
new Achievement[]{new BruiserAward(),new SharpShooterAward(),new FastKillerAward()} );
}
вызывает ошибку:
arrays first differed at element [0]; expected: com.techdisqus.achievement.BruiserAward<Bruiser> but was: com.techdisqus.achievement.BruiserAward<Bruiser>
Expected :com.techdisqus.achievement.BruiserAward<Bruiser>
Actual :com.techdisqus.achievement.BruiserAward<Bruiser>
и
@Test
public void testAchievementsSize(){
Player player = getPlayer();
List<Achievement> playerAchievements = achievementManager.checkForPlayerAchievements(preparePlayerStatistics(player));
assertEquals(3,playerAchievements.size());
assertArrayEquals(playerAchievements.toArray(),
new Achievement[]{new BruiserAward(),new SharpShooterAward(),new FastKillerAward()} );
}
вызывает
arrays first differed at element [0]; expected: com.techdisqus.achievement.BruiserAward<Bruiser> but was: com.techdisqus.achievement.BruiserAward<Bruiser>
Expected :com.techdisqus.achievement.BruiserAward<Bruiser>
Actual :com.techdisqus.achievement.BruiserAward<Bruiser>