Java tutorial
/** * Copyright 2016 REPLACE ME OWNER (REPLACE ME YEAR) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.homiefund.test.dao; import lombok.extern.log4j.Log4j2; import org.homiefund.api.dao.UserDAO; import org.homiefund.api.dao.domain.User; import org.homiefund.test.config.AbstractDAOTest; import org.homiefund.test.config.DAOTest; import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; /** * Created by Dominik Szalai - emptulik at gmail.com on 22.9.2016. */ @DAOTest @Log4j2 @RunWith(SpringJUnit4ClassRunner.class) public class UserDAOTest extends AbstractDAOTest { @BeforeClass public static void setUp() { checkMethods(UserDAOTest.class, UserDAO.class); } @Test public void create() { User user = new User(); user.setName("Google Googlovich"); user.setUsername("google"); user.setPassword("i am feeling lucky"); user.setEmail("google@example.com"); userDAO.create(user); Assert.assertNotNull(message(CREATE, User.class), user.getId()); } @Test public void delete() { userDAO.delete(2L); Assert.assertNull(message(DELETE, User.class), userDAO.getById(2L)); } @Test public void getAll() { Assert.assertEquals(4, userDAO.getAll().size()); } @Test public void update() { User user = userDAO.getById(2L); user.setPassword("pivojezdrave"); userDAO.update(user); Assert.assertEquals(user.getPassword(), userDAO.getById(user.getId()).getPassword()); } @Test public void getById() { Assert.assertEquals(Long.valueOf(1L), userDAO.getById(1L).getId()); } @Test public void getClassType() { Assert.assertEquals(User.class, userDAO.getClassType()); } @Test public void getByUsername() { Assert.assertEquals("emptak", userDAO.getByUsername("emptak").get().getUsername()); Assert.assertFalse(userDAO.getByUsername("borovicka").isPresent()); } @Test public void usernameExists() { Assert.assertTrue(userDAO.usernameExists("zoidby")); Assert.assertFalse(userDAO.usernameExists("borovicka")); } @Test public void emailExists() { Assert.assertTrue(userDAO.emailExists("emptulik@gmail.com")); Assert.assertFalse(userDAO.emailExists("good@example.com")); } }