@Test public void testTodoItemCommands() throws Exception { AddTodoItemCmd addTodoItemCmd = new AddTodoItemCmd().item("This is first item.").memo("create a todo item"); TodoItem item = gateway.send(addTodoItemCmd, TodoItem.class); String key = item.getAggregateID(); assertNotNull(key); // update TodoItem String newMessage = "This is first [updated] item."; EditTodoItemCmd editTodoItemCmd = new EditTodoItemCmd(key).item(newMessage); item = gateway.send(editTodoItemCmd, TodoItem.class); assertEquals(item.getItem(), newMessage); // mark complete MarkCompleteCmd markCompleteCmd = new MarkCompleteCmd(key); item = gateway.send(markCompleteCmd, TodoItem.class); assertTrue(item.getComplete()); // delete TodoItem DeleteTodoItemCmd deleteTodoItemCmd = new DeleteTodoItemCmd(key); item = gateway.send(deleteTodoItemCmd, TodoItem.class); assertTrue(item.isDeleted()); }
@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); }
public static void writeTodo(JsonWriter writer, TodoItem todo) throws IOException { writer.beginObject(); writer.name("key").value(todo.getKey()); writer.name("title").value(todo.getTitle()); writer.name("completed").value(todo.isCompleted()); writer.name("archived").value(todo.isArchived()); writer.endObject(); }
@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))); }
public List<TodoItem> searchExactString(List<TodoItem> todos, String toFind) { List<TodoItem> ret = new ArrayList<TodoItem>(); try { int i = 1; for (TodoItem tdi : todos) { if (tdi.getContents().equals(toFind)) { System.out.println(toFind + " found in line " + i + ". " + tdi.getContents()); ret.add(tdi); } i++; } } catch (Exception e) { e.printStackTrace(); LOGGER.severe("Error searching exact String"); } return ret; }
public List<TodoItem> searchString(List<TodoItem> todos, String toFind) { List<TodoItem> ret = new ArrayList<TodoItem>(); try { boolean stringFound = false; int i = 1; for (TodoItem tdi : todos) { if (tdi.getContents().contains(toFind)) { ret.add(tdi); System.out.println(toFind + " found in line " + i + ". " + tdi.getContents()); stringFound = true; } i++; } if (!stringFound) { System.out.println(toFind + " was not found in todos"); } } catch (Exception e) { e.printStackTrace(); LOGGER.severe("Error searching String"); } return ret; }
@Override public void onBindViewHolder(AppViewHolder holder, int position) { TodoItem todoitem = todoItemsArray.get(position); holder.itemView.setTag(position); holder.title.setText(todoitem.getName()); // holder.edittoolBarBtn.setTag(position); holder.priority.setTag(todoitem.getPriority().toString()); if (todoitem.getPriority().equals(Constants.Priority.High)) { holder.priority.setBackground(ctx.getResources().getDrawable(R.drawable.red_icon)); } else if (todoitem.getPriority().equals(Constants.Priority.Medium)) { holder.priority.setBackground(ctx.getResources().getDrawable(R.drawable.green_icon)); } else if (todoitem.getPriority().equals(Constants.Priority.Low)) { holder.priority.setBackground(ctx.getResources().getDrawable(R.drawable.blue_icon)); } if (todoitem.getStatus().equals(Constants.Status.Done)) { holder.iscompleted.setChecked(true); } else { holder.iscompleted.setChecked(false); } holder.iscompleted.setTag(todoitem.getName()); holder.dueDate.setText(todoitem.getDuedate()); holder.dueTime.setText(todoitem.getDuetime()); }
@Override public View getView(int position, View convertView, ViewGroup parent) { // Get the data item for this position TodoItem todoItem = getItem(position); // Check if an existing view is being reused, otherwise inflate the view if (convertView == null) { convertView = LayoutInflater.from(getContext()).inflate(R.layout.todo_item, parent, false); } // Lookup view for data population TextView tvName = (TextView) convertView.findViewById(R.id.tvName); TextView tvPriority = (TextView) convertView.findViewById(R.id.tvPriority); TextView tvDueDate = (TextView) convertView.findViewById(R.id.tvDueDate); tvName.setTextColor(Color.WHITE); tvPriority.setTextColor(Color.WHITE); tvDueDate.setTextColor(Color.WHITE); // Populate the data into the template view using the data object tvName.setText(todoItem.getName()); tvPriority.setText("P" + String.valueOf(todoItem.getPriority())); String dateString = todoItem.getDateDue(); if (dateString.length() > 0) { tvDueDate.setText(dateString); Date date = new Date(); int now = (int) (date.getTime() / 1000L); // Due in the next week if (todoItem.getTimeDue() <= (now + 604800) || todoItem.getTimeDue() < now) { convertView.setBackgroundColor(Color.RED); // Due in the next month } else if (todoItem.getTimeDue() <= (now + 2419200)) { convertView.setBackgroundColor(Color.BLUE); } else { convertView.setBackgroundColor(Color.BLACK); } } else { tvDueDate.setText("-"); convertView.setBackgroundColor(Color.GRAY); } // Return the completed view to render on screen return convertView; }
@Test public void testSetterGetterTitle() { underTest.setTitle("99l"); assertEquals("99l", underTest.getTitle()); }
@Test public void testSetterGetterId() { underTest.setId(99l); assertEquals(Long.valueOf(99l), underTest.getId()); }