Hi Russell,
I think your tests are a bit "over-zealous", you can probably relax your test code
For example testCreate does seem pretty simple, here's how I would code it, and removing my comments makes it a 3 liner.
@Test
public void on_create_returns_same_instance() { // note the name of the test that identify a scenario
when( dao.create( ALABAMA ) ).thenReturn( ALABAMA );
State result = bo.create( ALABAMA );
// no need for verify, otherwise the tests won't pass, the verification in this context is implicit.
assertSame( ALABAMA, result ); // no need to check the properties your StateBo is a pass-through
// however if StateBo does something, you might want to replace that by an "assertStateProperties"
// but then you will give another name to your test, like "on_create_ensure_properties_do_have_<your expected values or meaning>"
}
And now with the deletion code :
@Test
public void should_invoke_Dao_on_delete_by_id() { // delete scenario
// mockito mocks do nothing by default, no need to mock that
when( this.dao.readById( ID_1 ) ).thenReturn( ALABAMA ); // ok this is needed
this.bo.delete( ID_1 );
verify( this.dao ).delete( ALABAMA ); // ok, you need to verify that the interaction happened
}
@Test
public void should_not_propate_on_second_delete_of_same_id() { // another delete scenario on successive delete of same ID
doNothing().doThrow( new IllegalStateException() ).when( this.dao ).delete( ALABAMA ); // needed here as part of the scenario
when( this.dao.readById( ID_1 ) ).thenReturn( ALABAMA ); // still needed
this.bo.delete( ID_1 );
this.bo.delete( ID_1 );
// verify of the interaction not needed, it has been in the previous test,
// here you are testing something else i.e. just that StateBo don't propagate the exception on the second delete call
}
Really if your code is a pass-through you don't really care about the properties of a State. If your code begins to do other things then you will document it in the test with identifiable scenarios. I invented them in the above examples, but you get the point.
How's that sound ?
Cheers,