/** * Create hello. * * @return */ public String createHello() { if (newHello.getEmail() != null && newHello.getEmail().isEmpty()) { newHello.setEmail(null); } helloWorldService.create(newHello); return "welcome?faces-redirect=true"; }
/** * Display ajax message. * * @return ajax message */ public String displayHelloAjax() { StringBuilder response = new StringBuilder(); String firstName = ajaxHello.getFirstName(); if (firstName != null && firstName.length() > 0) { response.append(firstName); } String lastName = ajaxHello.getLastName(); if (lastName != null && lastName.length() > 0) { response.append(" "); response.append(lastName); } if (response.length() > 0) { response.insert(0, "Hello "); response.append(" !"); } return response.toString(); }
/** Test of method {@link HelloWorldService#retrieveAll()}. */ @Test public void testRetrieveAll() { // Mock result List<HelloWorld> mockResult = new ArrayList<HelloWorld>(); HelloWorld mockHello = new HelloWorld(); mockHello.setFirstName("first name"); mockHello.setLastName("last name"); mockResult.add(mockHello); // Mock call method Mockito.when(mockHelloWorldDao.retrieveAll()).thenReturn(mockResult); // Call service List<HelloWorld> result = helloWorldService.retrieveAll(); Assert.assertNotNull(result); Assert.assertEquals(1, result.size()); Assert.assertEquals("first name", result.get(0).getFirstName()); Assert.assertEquals("last name", result.get(0).getLastName()); }