FIX:: checkstyle 'server', things with user
This commit is contained in:
committed by
Merel Steenbergen
parent
61e31df157
commit
71ea1e3a4b
@@ -34,7 +34,7 @@ public class User {
|
|||||||
private Float footPrint = 0.0f;
|
private Float footPrint = 0.0f;
|
||||||
|
|
||||||
@ElementCollection
|
@ElementCollection
|
||||||
private Map<String,String> footPrintInputs = new HashMap<>();
|
private Map<String, String> footPrintInputs = new HashMap<>();
|
||||||
|
|
||||||
@ManyToMany
|
@ManyToMany
|
||||||
@JoinColumn
|
@JoinColumn
|
||||||
@@ -43,7 +43,7 @@ public class User {
|
|||||||
public User() {}
|
public User() {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* makes a user object.
|
* This method makes a user object.
|
||||||
* @param id the id of the user.
|
* @param id the id of the user.
|
||||||
* @param name the supplied username
|
* @param name the supplied username
|
||||||
* @param password the supplied password
|
* @param password the supplied password
|
||||||
@@ -57,53 +57,81 @@ public class User {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* gets the id.
|
* This method returns the ID of the user.
|
||||||
* @return the id
|
* @return the id of the user
|
||||||
*/
|
*/
|
||||||
public Long getId() {
|
public Long getId() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setId(Long id) {
|
/**
|
||||||
|
* This method sets the ID of the user.
|
||||||
|
* @param id the id of the user
|
||||||
|
*/
|
||||||
|
void setId(Long id) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* gets the name.
|
* This method returns the name of the user.
|
||||||
* @return the name
|
* @return the name of the user
|
||||||
*/
|
*/
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method sets the name of the user.
|
||||||
|
* @param name the name of the user
|
||||||
|
*/
|
||||||
public void setName(String name) {
|
public void setName(String name) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* gets the password.
|
* This method returns the password of the user.
|
||||||
* @return the password
|
* @return the password of the user
|
||||||
*/
|
*/
|
||||||
public String getPassword() {
|
public String getPassword() {
|
||||||
return password;
|
return password;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPassword(String password) {
|
/**
|
||||||
|
* This method sets the password of the user.
|
||||||
|
* @param password the password of the user
|
||||||
|
*/
|
||||||
|
void setPassword(String password) {
|
||||||
this.password = password;
|
this.password = password;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* gets the footPrint of user.
|
* This method returns the footPrint of user.
|
||||||
* @return the footPrint
|
* @return the footprint of the user
|
||||||
*/
|
*/
|
||||||
public Float getFootPrint() {
|
public Float getFootPrint() {
|
||||||
return footPrint;
|
return footPrint;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method sets the footprint of a user.
|
||||||
|
* @param footPrint footprint of a user
|
||||||
|
*/
|
||||||
|
public void setFootPrint(Float footPrint) {
|
||||||
|
this.footPrint = footPrint;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method returns the footprint inputs of the user.
|
||||||
|
* @return footprint inputs of the user
|
||||||
|
*/
|
||||||
public Map<String, String> getFootPrintInputs() {
|
public Map<String, String> getFootPrintInputs() {
|
||||||
return footPrintInputs;
|
return footPrintInputs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method sets the footprint inputs of the user.
|
||||||
|
* @param footPrintInputs footprint inputs of the user
|
||||||
|
*/
|
||||||
public void setFootPrintInputs(Map<String, String> footPrintInputs) {
|
public void setFootPrintInputs(Map<String, String> footPrintInputs) {
|
||||||
this.footPrintInputs = footPrintInputs;
|
this.footPrintInputs = footPrintInputs;
|
||||||
}
|
}
|
||||||
@@ -126,13 +154,8 @@ public class User {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setFootPrint(Float footPrint) {
|
|
||||||
this.footPrint = footPrint;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a human readable object. It's in JSON.
|
* This method returns a human readable (JSON) object.
|
||||||
* @return the JSON form of the object.
|
* @return the JSON form of the object.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@@ -142,6 +165,7 @@ public class User {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
<<<<<<< HEAD
|
||||||
* Returns the name and score of the friends in JSON. Needed for the leaderboard.
|
* Returns the name and score of the friends in JSON. Needed for the leaderboard.
|
||||||
* @return a JSON object of the friendlist with only names and scores.
|
* @return a JSON object of the friendlist with only names and scores.
|
||||||
*/
|
*/
|
||||||
@@ -156,18 +180,24 @@ public class User {
|
|||||||
return result + "]";
|
return result + "]";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** This method checks whether two users are equal or not.
|
||||||
|
* @param other an other user
|
||||||
|
* @return users are (not) equal
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object other) {
|
public boolean equals(Object other) {
|
||||||
if (other instanceof User) {
|
if (other instanceof User) {
|
||||||
User that = (User)other;
|
User that = (User) other;
|
||||||
if (that.id == this.id && that.name.equals(this.name)
|
return that.id.equals(this.id) && that.name.equals(this.name)
|
||||||
&& that.password.equals(this.password)) {
|
&& that.password.equals(this.password);
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method returns the hashcode of a user.
|
||||||
|
* @return hashcode of a user
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return Objects.hash(id, name, password);
|
return Objects.hash(id, name, password);
|
||||||
|
|||||||
@@ -3,10 +3,17 @@ package greenify.server.data.repository;
|
|||||||
import greenify.server.data.model.User;
|
import greenify.server.data.model.User;
|
||||||
import org.springframework.data.repository.CrudRepository;
|
import org.springframework.data.repository.CrudRepository;
|
||||||
|
|
||||||
//userRepository that saves all the user and talks to the database
|
/**
|
||||||
|
* UserRepository that saves all the users and talks to the database.
|
||||||
|
*/
|
||||||
public interface UserRepository extends CrudRepository<User, Integer> {
|
public interface UserRepository extends CrudRepository<User, Integer> {
|
||||||
User findByName(String name);
|
User findByName(String name);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method saves a user in the database.
|
||||||
|
* @param user the user you want saved
|
||||||
|
* @param <T> always a user
|
||||||
|
* @return the user
|
||||||
|
*/
|
||||||
<T extends User> T save(T user);
|
<T extends User> T save(T user);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,24 +10,43 @@ import org.springframework.web.bind.annotation.RestController;
|
|||||||
@RestController
|
@RestController
|
||||||
public class UserController {
|
public class UserController {
|
||||||
@Autowired
|
@Autowired
|
||||||
|
private
|
||||||
UserService userService;
|
UserService userService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method registers the user.
|
||||||
|
* @param name name of the user
|
||||||
|
* @param password password of the user
|
||||||
|
* @return the userDto of the user
|
||||||
|
*/
|
||||||
@RequestMapping("/registerUser")
|
@RequestMapping("/registerUser")
|
||||||
public UserDto registerUser(@RequestParam(value = "name") String name,
|
public UserDto registerUser(@RequestParam(value = "name") String name,
|
||||||
@RequestParam(value = "password") String password) {
|
@RequestParam(value = "password") String password) {
|
||||||
return userService.registerUser(name, password);
|
return userService.registerUser(name, password);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method logs in the user.
|
||||||
|
* @param name name of the user
|
||||||
|
* @param password password of the user
|
||||||
|
* @return the userDto of the user
|
||||||
|
*/
|
||||||
@RequestMapping("/loginUser")
|
@RequestMapping("/loginUser")
|
||||||
public UserDto loginUser(@RequestParam(value = "name") String name,
|
public UserDto loginUser(@RequestParam(value = "name") String name,
|
||||||
@RequestParam(value = "password") String password) {
|
@RequestParam(value = "password") String password) {
|
||||||
return userService.loginUser(name, password);
|
return userService.loginUser(name, password);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method sets input for a user.
|
||||||
|
* @param name name of the user
|
||||||
|
* @param inputName name of the input of the user
|
||||||
|
* @param value value of the input
|
||||||
|
*/
|
||||||
@RequestMapping("/setInput")
|
@RequestMapping("/setInput")
|
||||||
public void setInput(@RequestParam(value = "name") String name,
|
public void setInput(@RequestParam(value = "name") String name,
|
||||||
@RequestParam(value = "inputName") String inputName,
|
@RequestParam(value = "inputName") String inputName,
|
||||||
@RequestParam(value = "value") String value) {
|
@RequestParam(value = "value") String value) {
|
||||||
userService.setInput(name, inputName, value);
|
userService.setInput(name, inputName, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import org.springframework.web.bind.annotation.ResponseBody;
|
|||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class UserService {
|
public class UserService {
|
||||||
Logger logger = LoggerFactory.getLogger(UserService.class);
|
private Logger logger = LoggerFactory.getLogger(UserService.class);
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
UserRepository userRepository;
|
UserRepository userRepository;
|
||||||
@@ -23,10 +23,10 @@ public class UserService {
|
|||||||
CalculatorService calculatorService;
|
CalculatorService calculatorService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* registers the user.
|
* This method registers the user.
|
||||||
* @param name the username of the user
|
* @param name name of the user
|
||||||
* @param password the password of the user
|
* @param password password of the user
|
||||||
* @return a userDTO of the registered user
|
* @return the userDto of the user
|
||||||
*/
|
*/
|
||||||
public UserDto registerUser(String name, String password) {
|
public UserDto registerUser(String name, String password) {
|
||||||
User user = userRepository.findByName(name);
|
User user = userRepository.findByName(name);
|
||||||
@@ -42,10 +42,10 @@ public class UserService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* logs the user in.
|
* This method logs in the user.
|
||||||
* @param name the username of the user
|
* @param name name of the user
|
||||||
* @param password the password of the user
|
* @param password password of the user
|
||||||
* @return a userDTO of the logged in user
|
* @return the userDto of the user
|
||||||
*/
|
*/
|
||||||
public UserDto loginUser(String name, String password) {
|
public UserDto loginUser(String name, String password) {
|
||||||
User user = userRepository.findByName(name);
|
User user = userRepository.findByName(name);
|
||||||
@@ -60,6 +60,7 @@ public class UserService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
<<<<<<< HEAD
|
||||||
* Adds a friend to the friendlist of the user.
|
* Adds a friend to the friendlist of the user.
|
||||||
* @param name the username of the user
|
* @param name the username of the user
|
||||||
* @param friend the name of the friend you want to add.
|
* @param friend the name of the friend you want to add.
|
||||||
@@ -85,10 +86,10 @@ public class UserService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The method sets input value.
|
* This method sets input for a user.
|
||||||
* @param name of the user
|
* @param name name of the user
|
||||||
* @param inputName is the name of the setting input
|
* @param inputName name of the input of the user
|
||||||
* @param value of the input
|
* @param value value of the input
|
||||||
*/
|
*/
|
||||||
public void setInput(String name, String inputName, String value) {
|
public void setInput(String name, String inputName, String value) {
|
||||||
User user = userRepository.findByName(name);
|
User user = userRepository.findByName(name);
|
||||||
@@ -106,31 +107,37 @@ public class UserService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the input value of an input.
|
* This method returns the input value of an input.
|
||||||
* @param name of the user
|
* @param name of the user
|
||||||
* @param inputName name of the input
|
* @param inputName name of the input
|
||||||
* @return input value
|
* @return input value
|
||||||
*/
|
*/
|
||||||
public String getInput(String name, String inputName) {
|
String getInput(String name, String inputName) {
|
||||||
User user = userRepository.findByName(name);
|
User user = userRepository.findByName(name);
|
||||||
if (InputValidator.isValidItem(inputName)) {
|
if (InputValidator.isValidItem(inputName)) {
|
||||||
String item = user.getFootPrintInputs().get(inputName);
|
return user.getFootPrintInputs().get(inputName);
|
||||||
return item;
|
|
||||||
} else {
|
} else {
|
||||||
throw new ApplicationException("Invalid input");
|
throw new ApplicationException("Invalid input");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Float getFootprint(String name) {
|
/**
|
||||||
|
* This method returns the footprint of a user.
|
||||||
|
* @param name name of the user
|
||||||
|
* @return footprint of the user
|
||||||
|
*/
|
||||||
|
Float getFootprint(String name) {
|
||||||
User user = userRepository.findByName(name);
|
User user = userRepository.findByName(name);
|
||||||
return calculatorService.calculateFootprint(user);
|
return calculatorService.calculateFootprint(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method returns a JSON of XML with all users.
|
||||||
|
* @return JSON/XML of all users
|
||||||
|
*/
|
||||||
@GetMapping(path = "/all")
|
@GetMapping(path = "/all")
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public Iterable<User> getAllUsers() {
|
Iterable<User> getAllUsers() {
|
||||||
// This returns a JSON or XML with the users
|
|
||||||
return userRepository.findAll();
|
return userRepository.findAll();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,16 +1,15 @@
|
|||||||
package greenify.server.data.model;
|
package greenify.server.data.model;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
|
||||||
|
|
||||||
import greenify.common.ApplicationException;
|
import greenify.common.ApplicationException;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
public class UserTest {
|
public class UserTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void setAndGetTest() {
|
public void setAndGetTest() {
|
||||||
User testUser = new User();
|
User testUser = new User();
|
||||||
@@ -18,7 +17,7 @@ public class UserTest {
|
|||||||
testUser.setName("greenify");
|
testUser.setName("greenify");
|
||||||
testUser.setPassword("password");
|
testUser.setPassword("password");
|
||||||
User user = new User(1L, "greenify", "password");
|
User user = new User(1L, "greenify", "password");
|
||||||
assertTrue(user.getId().equals(1L));
|
assertEquals(1L, (long) user.getId());
|
||||||
assertEquals(user.getName(), "greenify");
|
assertEquals(user.getName(), "greenify");
|
||||||
assertEquals(user.getPassword(), "password");
|
assertEquals(user.getPassword(), "password");
|
||||||
assertEquals(user, testUser);
|
assertEquals(user, testUser);
|
||||||
@@ -32,47 +31,47 @@ public class UserTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void equalsTest() {
|
public void equalsTest() {
|
||||||
User first = new User(1L, "greenify", "password");
|
User first = new User(2L, "greenify", "12345");
|
||||||
User second = new User(1L, "greenify", "password");
|
User second = new User(2L, "greenify", "12345");
|
||||||
assertEquals(first.getId(), second.getId());
|
assertEquals(first.getId(), second.getId());
|
||||||
assertEquals(first.getName(), second.getName());
|
assertEquals(first.getName(), second.getName());
|
||||||
assertEquals(first.getPassword(), second.getPassword());
|
assertEquals(first.getPassword(), second.getPassword());
|
||||||
assertTrue(first.equals(second));
|
assertEquals(first, second);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void equalsDifferentId() {
|
public void equalsDifferentId() {
|
||||||
User first = new User(1L, "greenify", "password");
|
User first = new User(1L, "greenify", "password");
|
||||||
User second = new User(2L, "greenify", "password");
|
User second = new User(2L, "greenify", "password");
|
||||||
assertFalse(first.equals(second));
|
assertNotEquals(first, second);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void equalsDifferentName() {
|
public void equalsDifferentName() {
|
||||||
User first = new User(1L, "greenify", "password");
|
User first = new User(5L, "greenify", "password");
|
||||||
User second = new User(1L, "hello", "password");
|
User second = new User(5L, "hello", "password");
|
||||||
assertFalse(first.equals(second));
|
assertNotEquals(first, second);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void equalsDifferentPassword() {
|
public void equalsDifferentPassword() {
|
||||||
User first = new User(1L, "greenify", "password");
|
User first = new User(1L, "greenify", "password");
|
||||||
User second = new User(1L, "greenify", "hi");
|
User second = new User(1L, "greenify", "hi");
|
||||||
assertFalse(first.equals(second));
|
assertNotEquals(first, second);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void notEqualsTest() {
|
public void notEqualsTest() {
|
||||||
User first = new User(1L, "greenify", "password");
|
User first = new User(1L, "greenify", "password");
|
||||||
User second = new User(2L, "greenify", "password");
|
User second = new User(2L, "greenify", "password");
|
||||||
assertFalse(first.equals(second));
|
assertNotEquals(first, second);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void instanceOfTest() {
|
public void instanceOfTest() {
|
||||||
User first = new User();
|
User first = new User();
|
||||||
Object second = new Object();
|
Object second = new Object();
|
||||||
assertFalse(first.equals(second));
|
assertNotEquals(first, second);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -120,4 +119,3 @@ public class UserTest {
|
|||||||
assertEquals(first.friendsToString(), "friends=[{name=merel, footprint=0.0}]");
|
assertEquals(first.friendsToString(), "friends=[{name=merel, footprint=0.0}]");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package greenify.server.data.repository;
|
package greenify.server.data.repository;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
import greenify.server.data.model.User;
|
import greenify.server.data.model.User;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
@@ -16,9 +15,10 @@ public class UserRepositoryTest {
|
|||||||
private UserRepository repository;
|
private UserRepository repository;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void findByUsernameTest() throws Exception {
|
public void findByUsernameTest() {
|
||||||
repository.save(new User(296L, "cugurlu", "password"));
|
repository.save(new User(296L, "cugurlu", "password"));
|
||||||
User user = this.repository.findByName("cugurlu");
|
User user = this.repository.findByName("cugurlu");
|
||||||
assertEquals(user.getName(), "cugurlu");
|
assertEquals(user.getName(), "cugurlu");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -56,7 +56,6 @@ public class UserControllerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void setInputTest() throws Exception {
|
public void setInputTest() {
|
||||||
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package greenify.server.service;
|
package greenify.server.service;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
@@ -62,9 +61,7 @@ public class UserServiceTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void loginExceptionTest() {
|
public void loginExceptionTest() {
|
||||||
assertThrows(ApplicationException.class, () -> {
|
assertThrows(ApplicationException.class, () -> userService.loginUser("alex", "greenify"));
|
||||||
userService.loginUser("alex", "greenify");
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -76,9 +73,7 @@ public class UserServiceTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void registerExceptionTest() {
|
public void registerExceptionTest() {
|
||||||
assertThrows(ApplicationException.class, () -> {
|
assertThrows(ApplicationException.class, () -> userService.registerUser("alex", "password"));
|
||||||
userService.registerUser("alex", "password");
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -92,26 +87,19 @@ public class UserServiceTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void setInputNullTest() {
|
public void setInputNullTest() {
|
||||||
assertThrows(ApplicationException.class, () -> {
|
assertThrows(ApplicationException.class, () -> userService.setInput(null, "hello", "5.5"));
|
||||||
userService.setInput(null, "hello", "5.5");
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void setInputApplicationTestItem() {
|
public void setInputApplicationTestItem() {
|
||||||
assertThrows(ApplicationException.class, () -> {
|
assertThrows(ApplicationException.class, () -> userService.setInput("tom", "hello", "3.5"));
|
||||||
userService.setInput("alex", "hello", "3.5");
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void setInputApplicationTestValue() {
|
public void setInputApplicationTestValue() {
|
||||||
assertThrows(ApplicationException.class, () -> {
|
assertThrows(ApplicationException.class, () -> userService.setInput("tom", "transportation_num_vehicles", "5.5"));
|
||||||
userService.setInput("alex", "transportation_num_vehicles", "5.5");
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void setInputFootprintTest() {
|
public void setInputFootprintTest() {
|
||||||
User alex = new User(1L, "alex", "password");
|
User alex = new User(1L, "alex", "password");
|
||||||
@@ -120,7 +108,7 @@ public class UserServiceTest {
|
|||||||
when(calculatorService.calculateFootprint(alex))
|
when(calculatorService.calculateFootprint(alex))
|
||||||
.thenReturn(15f);
|
.thenReturn(15f);
|
||||||
userService.setInput("alex", "food_grains", "6.5");
|
userService.setInput("alex", "food_grains", "6.5");
|
||||||
assertTrue(15f == alex.getFootPrint());
|
assertEquals(15f, alex.getFootPrint(), 0.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -134,9 +122,7 @@ public class UserServiceTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getInputExceptionTest() {
|
public void getInputExceptionTest() {
|
||||||
assertThrows(ApplicationException.class, () -> {
|
assertThrows(ApplicationException.class, () -> userService.getInput("alex", "hello"));
|
||||||
userService.getInput("alex", "hello");
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -147,7 +133,7 @@ public class UserServiceTest {
|
|||||||
when(calculatorService.calculateFootprint(alex))
|
when(calculatorService.calculateFootprint(alex))
|
||||||
.thenReturn(15f);
|
.thenReturn(15f);
|
||||||
userService.setInput("alex", "food_grains", "6.5");
|
userService.setInput("alex", "food_grains", "6.5");
|
||||||
assertTrue(15f == userService.getFootprint("alex"));
|
assertEquals(15f, userService.getFootprint("alex"), 0.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -157,10 +143,7 @@ public class UserServiceTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void invalidLoginTest() {
|
public void invalidLoginTest() {
|
||||||
User user = null;
|
assertThrows(ApplicationException.class, () -> userService.loginUser(null, null));
|
||||||
assertThrows(ApplicationException.class, () -> {
|
|
||||||
userService.loginUser(null, null);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -182,5 +165,4 @@ public class UserServiceTest {
|
|||||||
assertEquals(userService.getLeaderboard("alex"), "friends=[{name=lola, footprint=0.0}]");
|
assertEquals(userService.getLeaderboard("alex"), "friends=[{name=lola, footprint=0.0}]");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user