Package com.luxoft.dnepr.courses.regular.unit5.dao

Examples of com.luxoft.dnepr.courses.regular.unit5.dao.AbstractDaoImpl


        dao.save(emp);
    }

    @Test
    public void updateOkTest() throws UserNotFound {
        Employee emp = createEmployee(1L, 10);
        emp = dao.update(emp);
        Assert.assertEquals(new Long(1), emp.getId());
        Assert.assertEquals(10, emp.getSalary());
        emp = (Employee) EntityStorage.getEntities().get(1L);
        Assert.assertEquals(new Long(1), emp.getId());
        Assert.assertEquals(10, emp.getSalary());
    }
View Full Code Here


        Assert.assertEquals(10, emp.getSalary());
    }

    @Test(expected = UserNotFound.class)
    public void updateFail1Test() throws UserNotFound {
        Employee emp = createEmployee(null, 10);
        emp = dao.update(emp);
    }
View Full Code Here

        emp = dao.update(emp);
    }

    @Test(expected = UserNotFound.class)
    public void updateFail2Test() throws UserNotFound {
        Employee emp = createEmployee(6L, 10);
        emp = dao.update(emp);
    }
View Full Code Here

        emp = dao.update(emp);
    }

    @Test
    public void getTest() {
        Employee emp = dao.get(3);
        Assert.assertEquals(new Long(3), emp.getId());
        Assert.assertEquals(3, emp.getSalary());

        emp = dao.get(10);
        Assert.assertNull(emp);
    }
View Full Code Here

        Assert.assertFalse(dao.delete(1L));
        Assert.assertFalse(dao.delete(2L));
    }

    private static Employee createEmployee(Long id, int weight) {
        Employee emp = new Employee();
        emp.setId(id);
        emp.setSalary(weight);
        return emp;
    }
View Full Code Here

    }

    @Test
    public void testSave() {

        Employee worker1 = new Employee(50);
        Employee worker2 = new Employee(100);
        Employee worker4 = new Employee(200);
        Employee worker5 = null;
        worker4.setId(4L);
        try {
            worker1 = employeeDAO.save(worker1);
            worker2 = employeeDAO.save(worker2);
            worker4 = employeeDAO.save(worker4);
            worker5 = employeeDAO.save(worker5);
        } catch (UserAlreadyExist e) {
            fail();
        }

        assertEquals(50, worker1.getSalary());
        assertEquals(100, worker2.getSalary());
        assertEquals(200, worker4.getSalary());
        assertEquals(new Long(1), worker1.getId());
        assertEquals(new Long(2), worker2.getId());
        assertEquals(new Long(4), worker4.getId());

        Employee worker11 = employeeDAO.get(1L);
        Employee worker12 = employeeDAO.get(2L);
        Employee worker14 = employeeDAO.get(4L);
        assertEquals(50, worker11.getSalary());
        assertEquals(100, worker12.getSalary());
        assertEquals(200, worker14.getSalary());
        assertEquals(new Long(1), worker11.getId());
        assertEquals(new Long(2), worker12.getId());
        assertEquals(new Long(4), worker14.getId());
        assertTrue(worker5 == null);

        Employee worker3 = new Employee(75);
        worker3.setId(2L);

        try {
            employeeDAO.save(worker3);
            fail();
        } catch (UserAlreadyExist e) {
View Full Code Here

    }

    @Test
    public void testUpdate() {

        Employee worker1 = new Employee(50);
        Employee worker2 = new Employee(100);
        worker2.setId(1L);
        employeeDAO.save(worker1);
        Employee worker3 = employeeDAO.update(worker2);

        assertEquals(new Long(1), worker3.getId());
        assertEquals(100, worker3.getSalary());

        Employee worker4 = new Employee(200);
        try {
            employeeDAO.update(worker4);
            fail();
        } catch (UserNotFound e) {
            assertEquals("null not found!", e.getMessage());
        }

        Employee worker5 = new Employee(201);
        worker5.setId(5L);
        try {
            employeeDAO.update(worker5);
            fail();
        } catch (UserNotFound e) {
            assertEquals("5 not found!", e.getMessage());
View Full Code Here

        employeeDAO.delete(1L);
    }

    @Test
    public void testGet() {
        Employee worker1 = new Employee(50);
        Employee worker2 = new Employee(100);
        employeeDAO.save(worker1);
        employeeDAO.save(worker2);

        Employee worker3 = employeeDAO.get(0);
        assertTrue(worker3 == null);

        Employee worker4 = employeeDAO.get(1);
        assertEquals(new Long(1), worker4.getId());
        assertEquals(50, worker4.getSalary());

        Employee worker5 = employeeDAO.get(2);
        assertEquals(new Long(2), worker5.getId());
        assertEquals(100, worker5.getSalary());

        Employee worker6 = employeeDAO.get(3);
        assertTrue(worker6 == null);

        employeeDAO.delete(1);
        employeeDAO.delete(2);
    }
View Full Code Here

        employeeDAO.delete(2);
    }

    @Test
    public void testRemove() {
        Employee worker1 = new Employee(50);
        employeeDAO.save(worker1);

        assertFalse(employeeDAO.delete(0));
        assertTrue(employeeDAO.delete(1));
        assertFalse(employeeDAO.delete(2));
View Full Code Here

    }

    @Override
    public boolean delete(long id) {
        Map<Long, Entity> storage = EntityStorage.getEntities();
        Entity entity = storage.get(id);
        if (entity == null) {
            return false;
        }
        return storage.remove(id) != null;
    }
View Full Code Here

TOP

Related Classes of com.luxoft.dnepr.courses.regular.unit5.dao.AbstractDaoImpl

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.