Wednesday, 31 January 2024

Unit test cases for private method

 

@Test
@DisplayName("player should get game trophy if he/she meet game trophy criteria")
void testCalculateGameTrophy() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
TrophyCalculationServiceImpl trophyCalculationService = new TrophyCalculationServiceImpl(trophyCalculationDao, oneHuddleMilestoneService);
Method calculateGameTrophyMethod = TrophyCalculationServiceImpl.class.getDeclaredMethod("hasGameTrophyAchievedByPlayer", PlayerReport.class, GameTrophy.class);
calculateGameTrophyMethod.setAccessible(true);
PlayerReport playerReport = PlayerReport.builder().playerId(1).attempt(10).build();
GameTrophy gameTrophy = GameTrophy.builder().gameTrophiesId(1).gameId(1).attempts(9).build();
assertTrue((boolean) calculateGameTrophyMethod.invoke(trophyCalculationService, playerReport, gameTrophy));
}

No comments:

Post a Comment