Merge branch 'master' into 'update/achievements'
# Conflicts: # src/Server/src/main/java/greenify/server/service/AchievementService.java
This commit is contained in:
@@ -86,6 +86,9 @@ public class Achievement {
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
if(other == null){
|
||||
return false;
|
||||
}
|
||||
if (other instanceof Achievement) {
|
||||
Achievement that = (Achievement) other;
|
||||
return achieved == that.achieved
|
||||
|
||||
@@ -28,7 +28,8 @@ public class AchievementService {
|
||||
}
|
||||
|
||||
/**
|
||||
* This method changes achiev1 when this is the case.
|
||||
* This method makes sure the user gets an achievement
|
||||
* upon calculating their footprint for the first time.
|
||||
* @param user user for whom achiev1 changes
|
||||
*/
|
||||
public void achieveGettingStarted(User user) {
|
||||
|
||||
@@ -114,8 +114,8 @@ public class UserService {
|
||||
if (InputValidator.isValidItem(inputName)
|
||||
&& InputValidator.isValidItemValue(inputName, value)) {
|
||||
user.getFootPrintInputs().put(inputName, value);
|
||||
userRepository.save(user);
|
||||
achievementService.updateAchievements(user);
|
||||
userRepository.save(user);
|
||||
} else {
|
||||
throw new ApplicationException("Invalid input");
|
||||
}
|
||||
@@ -242,14 +242,14 @@ public class UserService {
|
||||
User user = userRepository.findByName(name);
|
||||
if (user == null) {
|
||||
throw new ApplicationException("User does not exist");
|
||||
} else {
|
||||
if (AllAchievements.isValidAchievement(achievement)) {
|
||||
user.getAchievements().put(achievement, achieved);
|
||||
userRepository.save(user);
|
||||
} else {
|
||||
throw new ApplicationException("Invalid achievement");
|
||||
}
|
||||
}
|
||||
if (!AllAchievements.isValidAchievement(achievement)) {
|
||||
throw new ApplicationException("Invalid achievement");
|
||||
}
|
||||
Map<String, Boolean> temp = user.getAchievements();
|
||||
temp.put(achievement, achieved);
|
||||
user.setAchievements(temp);
|
||||
userRepository.save(user);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package greenify.server.data.model;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -38,6 +39,17 @@ class AchievementTest {
|
||||
assertEquals(achievement, other);
|
||||
}
|
||||
|
||||
@Test
|
||||
void notEqualsTest() {
|
||||
Achievement test = new Achievement("Starting off",
|
||||
"You did your first green activity", false);
|
||||
assertFalse(achievement.equals(test));
|
||||
}
|
||||
|
||||
@Test
|
||||
void equalsNullTest() {
|
||||
assertFalse(achievement.equals(null));
|
||||
}
|
||||
@Test
|
||||
void hashCodeTest() {
|
||||
assertEquals(achievement, other);
|
||||
|
||||
@@ -3,6 +3,7 @@ package greenify.server.service;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import greenify.server.InputValidator;
|
||||
import greenify.server.data.model.User;
|
||||
import greenify.server.data.repository.UserRepository;
|
||||
import org.junit.Before;
|
||||
@@ -68,6 +69,8 @@ public class AchievementServiceTest {
|
||||
User alex = userRepository.findByName("alex");
|
||||
achievementService.achieveGettingStarted(alex);
|
||||
assertEquals(true, userService.getAchievement("alex", "Starting off"));
|
||||
assertEquals(false, userService.getAchievement("alex", "Social butterfly"));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user