@Before public void testSetup() throws Exception { sender = new User(); sender.setName("bill"); receiver = new User(); receiver.setName("jack"); mail = new Mail(); mail.setRead(false); mail.setTitle("aa"); mail.setContent("bb"); userAPI = new UserAPI("localhost", "8888", "service"); mailAPI = new MailAPI("localhost", "8888", "service"); APIResponse response = userAPI.create(sender); if (response.isDone()) { sender = (User) response.getMessage(); assertEquals("bill", sender.getName()); } else { logger.log(Level.SEVERE, response.getMessage().toString()); } response = userAPI.create(receiver); if (response.isDone()) { receiver = (User) response.getMessage(); assertEquals("jack", receiver.getName()); } else { logger.log(Level.SEVERE, response.getMessage().toString()); } mail.setSender(sender); mail.setReceiver(receiver); }
@Test public void testCreate() { when(jdoTemplate.makePersistent(user)).thenReturn(user); User result = userService.create(user); verify(jdoTemplate).makePersistent(user); assertEquals("bill", result.getName()); }
@Test public void testUpdate() { when(jdoTemplate.getObjectById(User.class, user.getId())).thenReturn(user); when(jdoTemplate.makePersistent(user)).thenReturn(user); User result = userService.update(user); verify(jdoTemplate).getObjectById(User.class, user.getId()); verify(jdoTemplate).makePersistent(user); assertEquals("bill", result.getName()); }