Added tests and method to make sure you cannot add yourself as a friend
This commit is contained in:
@@ -2,8 +2,10 @@ 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.Assert.assertFalse;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
|
import greenify.common.ApplicationException;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -90,7 +92,7 @@ public class UserTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void addFriend(){
|
public void addFriendTest(){
|
||||||
User first = new User(1L, "greenify", "password");
|
User first = new User(1L, "greenify", "password");
|
||||||
User second = new User(1L, "merel", "password");
|
User second = new User(1L, "merel", "password");
|
||||||
assertEquals(first.getFriends(), second.getFriends());
|
assertEquals(first.getFriends(), second.getFriends());
|
||||||
@@ -100,5 +102,13 @@ public class UserTest {
|
|||||||
test.add(second);
|
test.add(second);
|
||||||
assertEquals(first.getFriends(), test);
|
assertEquals(first.getFriends(), test);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void addYourselfTest(){
|
||||||
|
User test = new User(1L, "greenify", "password");
|
||||||
|
assertEquals(test.getFriends(), new ArrayList<User>());
|
||||||
|
assertThrows(ApplicationException.class, () -> {
|
||||||
|
test.addFriend(test);
|
||||||
|
}); }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,6 +18,8 @@ import org.springframework.boot.test.mock.mockito.MockBean;
|
|||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.test.context.junit4.SpringRunner;
|
import org.springframework.test.context.junit4.SpringRunner;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
@RunWith(SpringRunner.class)
|
@RunWith(SpringRunner.class)
|
||||||
public class UserServiceTest {
|
public class UserServiceTest {
|
||||||
@TestConfiguration
|
@TestConfiguration
|
||||||
@@ -45,7 +47,9 @@ public class UserServiceTest {
|
|||||||
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");
|
||||||
|
when(userRepository.findByName(lola.getName()))
|
||||||
|
.thenReturn(lola); }
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void validLoginTest() {
|
public void validLoginTest() {
|
||||||
@@ -157,4 +161,16 @@ public class UserServiceTest {
|
|||||||
userService.loginUser(null, null);
|
userService.loginUser(null, null);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void addFriendTest() {
|
||||||
|
User alex = userRepository.findByName("alex");
|
||||||
|
User lola = userRepository.findByName("lola");
|
||||||
|
assertEquals(lola.getFriends(), alex.getFriends());
|
||||||
|
userService.addFriend("alex", "lola");
|
||||||
|
ArrayList<User> test = new ArrayList<User>();
|
||||||
|
test.add(lola);
|
||||||
|
assertEquals(alex.getFriends(), test);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user