Esempio n. 1
0
  @Test(expected = EmptyResultDataAccessException.class)
  public void getUserFailure() throws SQLException {
    dao.deleteAll();
    assertThat(dao.getCount(), is(0));

    dao.get("unknown_id");
  }
Esempio n. 2
0
  @Test
  public void mockUpgradeLevels() throws Exception {
    UserServiceImpl userServiceImpl = new UserServiceImpl();

    UserDao mockUserDao = mock(UserDao.class);
    when(mockUserDao.getAll()).thenReturn(this.users);
    userServiceImpl.setUserDao(mockUserDao);

    MailSender mockMailSender = mock(MailSender.class);
    userServiceImpl.setMailSender(mockMailSender);

    userServiceImpl.upgradeLevels();

    verify(mockUserDao, times(2)).update(any(User.class));
    verify(mockUserDao, times(2)).update(any(User.class));
    verify(mockUserDao).update(users.get(1));
    assertThat(users.get(1).getLevel(), is(Level.SILVER));
    verify(mockUserDao).update(users.get(3));
    assertThat(users.get(3).getLevel(), is(Level.GOLD));

    ArgumentCaptor<SimpleMailMessage> mailMessageArg =
        ArgumentCaptor.forClass(SimpleMailMessage.class);
    verify(mockMailSender, times(2)).send(mailMessageArg.capture());
    List<SimpleMailMessage> mailMessages = mailMessageArg.getAllValues();
    assertThat(mailMessages.get(0).getTo()[0], is(users.get(1).getEmail()));
    assertThat(mailMessages.get(1).getTo()[0], is(users.get(3).getEmail()));
  }
Esempio n. 3
0
  @Test
  public void upgradeAllOrNothing() {
    userDao.deleteAll();
    for (User user : users) userDao.add(user);

    try {
      testUserService.upgradeLevels();
      fail("TestUserServiceException expected");
    } catch (TestUserServiceException e) {
    }

    checkLevelUpgraded(users.get(1), false);
  }
Esempio n. 4
0
  @Test
  public void getAll() {
    dao.deleteAll();

    List<User> users0 = dao.getAll();
    assertThat(users0.size(), is(0));

    dao.add(user1); // Id: gyumee
    List<User> users1 = dao.getAll();
    assertThat(users1.size(), is(1));
    checkSameUser(user1, users1.get(0));

    dao.add(user2); // Id: leegw700
    List<User> users2 = dao.getAll();
    assertThat(users2.size(), is(2));
    checkSameUser(user1, users2.get(0));
    checkSameUser(user2, users2.get(1));

    dao.add(user3); // Id: bumjin
    List<User> users3 = dao.getAll();
    assertThat(users3.size(), is(3));
    checkSameUser(user3, users3.get(0));
    checkSameUser(user1, users3.get(1));
    checkSameUser(user2, users3.get(2));
  }
Esempio n. 5
0
  @Test
  public void add() {
    userDao.deleteAll();

    User userWithLevel = users.get(4); // GOLD 레벨
    User userWithoutLevel = users.get(0);
    userWithoutLevel.setLevel(null);

    userService.add(userWithLevel);
    userService.add(userWithoutLevel);

    User userWithLevelRead = userDao.get(userWithLevel.getId());
    User userWithoutLevelRead = userDao.get(userWithoutLevel.getId());

    assertThat(userWithLevelRead.getLevel(), is(userWithLevel.getLevel()));
    assertThat(userWithoutLevelRead.getLevel(), is(Level.BASIC));
  }
Esempio n. 6
0
 private void checkLevelUpgraded(User user, boolean upgraded) {
   User userUpdate = userDao.get(user.getId());
   if (upgraded) {
     assertThat(userUpdate.getLevel(), is(user.getLevel().nextLevel()));
   } else {
     assertThat(userUpdate.getLevel(), is(user.getLevel()));
   }
 }
Esempio n. 7
0
 public void upgradeLevels() {
   List<User> users = userDao.getAll();
   for (User user : users) {
     if (canUpgradeLevel(user)) {
       upgradeLevel(user);
     }
   }
 }
Esempio n. 8
0
  @Test
  public void count() throws SQLException {

    dao.deleteAll();
    assertThat(dao.getCount(), is(0));
    dao.add(user1);
    assertThat(dao.getCount(), is(1));
    dao.add(user2);
    assertThat(dao.getCount(), is(2));
    dao.add(user3);
    assertThat(dao.getCount(), is(3));
  }
Esempio n. 9
0
 public void upgradeLevels() {
   try {
     List<User> users = userDao.getAll();
     for (User user : users) {
       if (canUpgradeLevel(user)) {
         upgradeLevel(user);
       }
     }
   } catch (RuntimeException e) {
     throw e;
   }
 }
Esempio n. 10
0
  @Test
  public void andAndGet() {
    dao.deleteAll();
    assertThat(dao.getCount(), is(0));

    dao.add(user1);
    dao.add(user2);
    assertThat(dao.getCount(), is(2));

    User userget1 = dao.get(user1.getId());
    assertThat(userget1.getName(), is(user1.getName()));
    assertThat(userget1.getPassword(), is(user1.getPassword()));

    User userget2 = dao.get(user2.getId());
    assertThat(userget2.getName(), is(user2.getName()));
    assertThat(userget2.getPassword(), is(user2.getPassword()));
  }
Esempio n. 11
0
 public void add(User user) {
   if (user.getLevel() == null) {
     user.setLevel(Level.BASIC);
   }
   userDao.add(user);
 }
Esempio n. 12
0
 protected void upgradeLevel(User user) {
   user.upgradeLevel();
   userDao.update(user);
   sendUpgradeEMail(user);
 }
Esempio n. 13
0
 public void update(User user) {
   userDao.update(user);
 }
Esempio n. 14
0
 public void deleteAll() {
   userDao.deleteAll();
 }
Esempio n. 15
0
 public List<User> getAll() {
   return userDao.getAll();
 }
Esempio n. 16
0
 public User get(String id) {
   return userDao.get(id);
 }