Package com.luxoft.dnepr.courses.regular.unit17.exception

Examples of com.luxoft.dnepr.courses.regular.unit17.exception.UserNotFound


        if (id == null) {
            id = EntityStorageUtils.getNextToMaxId(storage, clazz);
            e.setId(id);
        }
        if (get(id) != null) {
            throw new UserAlreadyExist(id);
        }
        return (E) storage.save(e);
    }
View Full Code Here


        if (e == null) {
            throw new IllegalArgumentException("Argument 'e' can't be a null reference!");
        }
        Integer id = e.getId();
        if (id == null) {
            throw new UserNotFound(id);
        }
        if (get(id) == null) {
            throw new UserNotFound(id);
        }
        return (E) storage.update(e);
    }
View Full Code Here

    private IDao<Redis> redisDao = new RedisDaoImpl(storage);

    @Test
    public void employeeDaoTest() {
        //Create 2 employees
        Employee employee1 = new Employee(350);
        Employee employee2 = new Employee(700);
        //Save employees in database
        employee1 = employeeDao.save(employee1);
        employee2 = employeeDao.save(employee2);
        //Get it from database
        Employee get1 = employeeDao.get(employee1.getId());
        Employee get2 = employeeDao.get(employee2.getId());
        //Assert employees
        Assert.assertEquals(employee1, get1);
        Assert.assertEquals(employee2, get2);
        //Change salary of employee1
        employee1.setSalary(1000);
        employeeDao.update(employee1);
        //Check update state
        Employee updated = employeeDao.get(employee1.getId());
        Assert.assertEquals(1000, updated.getSalary());
        //Delete changed employee
        boolean success = employeeDao.delete(updated);
        Assert.assertTrue(success);
        Employee mustBeDeleted = employeeDao.get(updated.getId());
        Assert.assertNull(mustBeDeleted);
    }
View Full Code Here

    }

    @Test
    public void redisDaoTest() {
        //Create 2 redis
        Redis redis1 = new Redis(35);
        Redis redis2 = new Redis(70);
        //Save redis in database
        redis1 = redisDao.save(redis1);
        redis2 = redisDao.save(redis2);
        //Get it from database
        Redis get1 = redisDao.get(redis1.getId());
        Redis get2 = redisDao.get(redis2.getId());
        //Assert redis
        Assert.assertEquals(redis1, get1);
        Assert.assertEquals(redis2, get2);
        //Change salary of employee1
        redis1.setWeight(100);
        redisDao.update(redis1);
        //Check update state
        Redis updated = redisDao.get(redis1.getId());
        Assert.assertEquals(100, updated.getWeight());
    }
View Full Code Here

        if (e == null) {
            throw new IllegalArgumentException("Argument 'e' can't be a null reference!");
        }
        Long id = e.getId();
        if (id == null) {
            throw new UserNotFound(id);
        }
        Map<Long, Entity> storage = EntityStorage.getEntities();
        if (!storage.containsKey(id)) {
            throw new UserNotFound(id);
        }
        storage.put(id, e);
        return e;
    }
View Full Code Here

        if (element == null) {
            return null;
        }
        Long elementId = element.getId();
        if (elementId == null || getEntities().get(elementId) == null) {
            throw new UserNotFound(elementId + " not found!");
        }
        getEntities().put(elementId, element);
        return element;
    }
View Full Code Here

TOP

Related Classes of com.luxoft.dnepr.courses.regular.unit17.exception.UserNotFound

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.