Add UserRepository test

This commit is contained in:
cugurlu
2019-03-18 00:34:51 +01:00
parent 2546355eba
commit d7960103ee

View File

@@ -1,37 +1,24 @@
//package greenify.server.data.repository;
//
//import greenify.server.data.model.User;
//import org.junit.Test;
//import org.junit.runner.RunWith;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
//import org.springframework.boot.test.autoconfigure.orm.jpa.TestEntityManager;
//import org.springframework.test.context.junit4.SpringRunner;
//
//import static junit.framework.TestCase.assertTrue;
//import static org.junit.Assert.assertEquals;
//
//@RunWith(SpringRunner.class)
//@DataJpaTest
//public class UserRepositoryTest {
//
// @Autowired
// private TestEntityManager entityManager;
//
// @Autowired
// private UserRepository repository;
//
// @Test
// public void findByUsernameShouldReturnUser() throws Exception {
// this.entityManager.persist(new User(296L, "cugurlu", "password", 6));
// User user = this.repository.findByName("cugurlu");
// assertEquals(user.getName(), "cugurlu");
// }
//
// @Test
// public void findByUsernameWhenNoUserShouldReturnNull() throws Exception {
// this.entityManager.persist(new User(296L, "cugurlu", "password", 6));
// User user = this.repository.findByName("mouse");
// assertTrue(user == null);
// }
//}
package greenify.server.data.repository;
import static org.junit.Assert.assertEquals;
import greenify.server.data.model.User;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@DataJpaTest
public class UserRepositoryTest {
@Autowired
private UserRepository repository;
@Test
public void findByUsernameTest() throws Exception {
repository.save(new User(296L, "cugurlu", "password", 6));
User user = this.repository.findByName("cugurlu");
assertEquals(user.getName(), "cugurlu");
}
}