@Test public void happyPath() throws Exception { mockery.checking( new Expectations() { { allowing(dateFormat).format(with(any(LocalDate.class))); will(returnValue("::the date::")); allowing(categoryFormat).format(with(any(Category.class))); will(returnValue("::the category::")); allowing(amountFormat).format(with(any(Amount.class))); will(returnValue("::the amount::")); } }); final Transaction transaction = new Transaction(anyNonNullDate, anyNonNullCategory, anyNonNullAmount); final String rowText = transactionCsvFormat.format(transaction); assertThat( rowText, matches( Pattern.compile( "\\s*\"::the date::\"," + "\\s*\"::the category::\"," + "\\s*\"::the amount::\"\\s*"))); }
@Test public void nullTransaction() throws Exception { try { transactionCsvFormat.format(null); fail("How did you format a null transaction?!"); } catch (ProgrammerMistake success) { } }