TransactionsWebService { @PUT @Path("{transactionId}/category") public void putCategory(@PathParam("transactionId") String transactionId, CategoryModel category) { validateRequired(transactionId, "Transaction id"); validateNotNull(category, "Category must be provided."); validateRequired(category.getName(), "Category name"); Transactions transactions = transactionsService.retrieve(); Transaction transaction = transactions.byId(transactionId); validate(transaction != null, format("Transaction with id \"{0}\" not found.", transactionId)); Transaction categorized = transaction.withCategoryName(category.getName()); transactionsService.update(transactions.copyWithReplacement(categorized)); } @Inject  TransactionsWebService(TransactionsService transactionsService); @PUT @Path("{transactionId}/category") void putCategory(@PathParam("transactionId") String transactionId, CategoryModel category);  }
@Test public void putCategory() { webService.putCategory(transaction1.getId(), new CategoryModel("a category")); ArgumentCaptor<Transactions> transactionsCaptor = ArgumentCaptor.forClass(Transactions.class); verify(transactionsService).update(transactionsCaptor.capture()); Transactions updated = transactionsCaptor.getValue(); Transaction transaction = updated.getTransactions().get(0); assertEquals(transaction1, transaction); assertEquals(transaction1.getId(), transaction.getId()); assertEquals("a category", transaction.getCategoryName()); }