@Test(expected = NotFoundException.class) public void shouldFailRetrievingNonexistentTodoItem() throws Exception { final String todoItemId = TodoItemId.generate(); given(todoItems.getTodoItem(todoItemId)).willReturn(Optional.empty()); todoItemsResource.getTodoItem(todoItemId); }
@Test(expected = NotFoundException.class) public void shouldFailUpdateNonexistentTodoItemIs() throws Exception { final TodoItem todoItem = createTodoItem(); given(todoItems.updateTodoItem(todoItem.getId(), todoItem.getTitle(), todoItem.getCompleted())) .willReturn(Optional.empty()); todoItemsResource.updateTodoItem(todoItem.getId(), todoItem); }
@Test public void shouldRetrieveTodoItems() throws Exception { given(todoItems.getAllTodoItems()).willReturn(new ArrayList<>()); final Response response = todoItemsResource.getTodoItems(); assertThat(response.getStatus(), is(equalTo(Status.OK))); }
@Test public void shouldRetrieveTodoItem() throws Exception { final TodoItem todoItem = createTodoItem(); given(todoItems.getTodoItem(todoItem.getId())).willReturn(Optional.of(todoItem)); final Response response = todoItemsResource.getTodoItem(todoItem.getId()); assertThat(response.getStatus(), is(equalTo(Status.OK))); }
@Test public void shouldCreateTodoItem() throws Exception { final TodoItem todoItem = createTodoItem(); final UriInfo uriInfo = mock(UriInfo.class); final UriBuilder uriBuilder = mock(UriBuilder.class); final URI todoUri = new URI(baseUri + todoItem.getId()); given(todoItems.createTodoItem(todoItem.getTitle(), todoItem.getCompleted())) .willReturn(todoItem); given(uriInfo.getAbsolutePathBuilder()).willReturn(uriBuilder); given(uriBuilder.path("/" + todoItem.getId())).willReturn(uriBuilder); given(uriBuilder.build()).willReturn(todoUri); final Response response = todoItemsResource.createTodoItem(todoItem, uriInfo); assertThat(response.getStatus(), is(equalTo(Status.CREATED))); }