Add tests for server

This commit is contained in:
cugurlu
2019-03-12 10:22:07 +01:00
parent a9827b8573
commit 7548df160d
3 changed files with 58 additions and 2 deletions

View File

@@ -0,0 +1,16 @@
import gogreen.server.Application;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
public class ApplicationTest {
@Test
public void applicationContextLoaded() {
}
@Test
public void applicationContextTest() {
Application.main(new String[] {});
}
}

View File

@@ -1,5 +1,3 @@
package gogreen.server.rest;
import gogreen.common.UserDTO;
import gogreen.server.Application;
import org.junit.Assert;

View File

@@ -0,0 +1,42 @@
import gogreen.server.data.model.User;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class UserTest {
@Test
public void setAndGetTest() {
User user = new User(1L, "greenify", "password");
User testUser = new User();
testUser.setId(1L);
testUser.setName("greenify");
testUser.setPassword("password");
assertTrue(user.getId().equals(1L));
assertEquals(user.getName(), "greenify");
assertEquals(user.getPassword(), "password");
assertEquals(user, testUser);
}
@Test
public void toStringTest() {
User user = new User(1L, "greenify", "password");
assertEquals("User(id=1, name=greenify, password=password)", user.toString());
}
@Test
public void equalsTest() {
User first = new User(1L, "greenify", "password");
User second = new User(1L, "greenify", "password");
assertEquals(first.getId(), second.getId());
assertEquals(first.getName(), second.getName());
assertEquals(first.getPassword(), second.getPassword());
}
@Test
public void hashCodeTest() {
User first = new User(1L, "greenify", "password");
User second = new User(1L, "greenify", "password");
assertTrue(first.equals(second) && second.equals(first));
assertTrue(first.hashCode() == second.hashCode());
}
}