FIX::No longer use Mockito for AchievementService in AchievementServiceTest

This commit is contained in:
Merel Steenbergen
2019-04-05 20:30:31 +02:00
parent ccbe5968da
commit 82fd016590

View File

@@ -26,6 +26,14 @@ public class AchievementServiceTest {
} }
} }
@TestConfiguration
static class AchievementServiceConfiguration {
@Bean
public AchievementService achievementService() {
return new AchievementService();
}
}
@Autowired @Autowired
private UserService userService; private UserService userService;
@@ -35,7 +43,7 @@ public class AchievementServiceTest {
@MockBean @MockBean
private CalculatorService calculatorService; private CalculatorService calculatorService;
@MockBean @Autowired
private AchievementService achievementService; private AchievementService achievementService;
/** /**
@@ -46,30 +54,20 @@ public class AchievementServiceTest {
User alex = new User(1L, "alex", "password"); User alex = new User(1L, "alex", "password");
when(userRepository.findByName(alex.getName())) when(userRepository.findByName(alex.getName()))
.thenReturn(alex); .thenReturn(alex);
User lola = new User(2L, "lola", "password"); userService.setInput("alex","input_footprint_shopping_food_otherfood", "9.9");
when(userRepository.findByName(lola.getName()))
.thenReturn(lola);
} }
@Test @Test
public void updateAchievementsTest() { public void updateAchievementsTest() {
User alex = userRepository.findByName("alex"); User alex = userRepository.findByName("alex");
userService.setInput("alex","input_footprint_shopping_food_otherfood", "9.9"); achievementService.updateAchievements(alex);
// achievementService.updateAchievements(alex); assertEquals(true, userService.getAchievement("alex", "Starting off"));
//Shouldn't even have to call updateAchievements, since it's called in setInput.
// userService.setAchievement(alex.getName(), "Starting off", true);
// ^should not be here, does not work otherwise and I don't know why
System.out.println("\n\n"+ alex.getAchievements() + "\n\n" + alex.getFootPrintInputs().equals(InputValidator.getDefaultValues()));
// assertEquals(true, userService.getAchievement("alex", "Starting off"));
} }
@Test @Test
public void achieveGettingStartedTest() { public void achieveGettingStartedTest() {
User alex = userRepository.findByName("alex"); User alex = userRepository.findByName("alex");
userService.setInput("alex", "input_size", "5");
achievementService.achieveGettingStarted(alex); achievementService.achieveGettingStarted(alex);
userService.setAchievement(alex.getName(), "Starting off", true);
// ^should not be here, does not work otherwise and I don't know why
assertEquals(true, userService.getAchievement("alex", "Starting off")); assertEquals(true, userService.getAchievement("alex", "Starting off"));
} }
} }