Merge branch 'fix_userTest' into 'master'

FIX:: fixed the userTest

See merge request cse1105/2018-2019/oopp-group-43/template!20
This commit is contained in:
Sem van der Hoeven
2019-03-17 15:38:58 +00:00
2 changed files with 68 additions and 2 deletions

View File

@@ -5,6 +5,7 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
import java.util.Objects;
@EnableAutoConfiguration
@Entity
@@ -79,4 +80,57 @@ public class User {
}
public void setVeganMeal(int veganMeal) { this.veganMeal = veganMeal; }
/**
* checks if two users are equal.
* @param other the object to compare the user with
* @return a boolean value of true if the user is equal to the object
*/
@Override
public boolean equals(Object other) {
if (this == other) {
return true;
}
if (other == null) {
return false;
}
if (getClass() != other.getClass()) {
return false;
}
if (other instanceof User) {
User that = (User) other;
return this.getName().equals(that.getName())
&& this.getId().equals(that.getId())
&& this.getPassword().equals(that.getPassword())
&& this.getVeganMeal() == that.getVeganMeal();
}
return false;
}
/**
* creates a string of the user object.
* in the form of: User(id=, name=, password=, veganMeal=)
* @return a string of the user object
*/
@Override
public String toString() {
return "User(id="
+ this.id
+ ", name="
+ this.name
+ ", password="
+ this.password
+ ", veganMeal="
+ this.veganMeal + ")";
}
/**
* hashes the User object.
* @return a hashcode for the user object
*/
@Override
public int hashCode() {
return Objects.hash(id, name, password, veganMeal);
}
}

View File

@@ -16,13 +16,25 @@ public class UserTest {
assertEquals(user.getName(), "greenify");
assertEquals(user.getPassword(), "password");
assertEquals(user.getVeganMeal(), 3);
assertEquals(user, testUser);
}
@Test
public void equalsMethodTest() {
User user = new User(1L, "greenify", "password", 3);
User testUser = new User();
testUser.setId(1L);
testUser.setName("greenify");
testUser.setPassword("password");
testUser.setVeganMeal(3);
assertTrue(user.equals(testUser));
}
@Test
public void toStringTest() {
User user = new User(1L, "greenify", "password", 3);
assertEquals("User(id=1, name=greenify, password=password, veganMeal=3)", user.toString());
System.out.println("String is " + user.toString());
assertTrue("User(id=1, name=greenify, password=password, veganMeal=3)".equals(user.toString()));
}
@Test