A long time ago, it was a good day to test.

Checking one's work is a good thing to do.[1]

But the testing never really ends.

If someone wanted to write a test looking for a library that receives public funding, or by its head librarian, he or she might use code like the following:

Java

 assertEqual(
     l.getHeadLibrarian()
         .getName().split(" ")[1]
     , "Smith")
 assertEqual( 
     l.getFunding().getType()
     , "public")

Ruby

 l.headLibrarian.name.split(/ +/).last.should == "Smith"
 l.funding.type.should == "public"

To mock up an object that matches the search result, they would have to have mocking code like what follows:

Java

 
HeadLibrarian h = mock(HeadLibrarian.class);
 when(h.getName()).thenReturn("Jane Smith");
 
 Funding f = mock(Funding.class);
 when(f.getType()).thenReturn("public");
 
 Library l = mock(Library.class);
 when(l.getHeadLibrarian()).thenReturn(h);
 when(l.getFunding()).thenReturn(f);

Ruby

 h = mock('HeadLibrarian', :name => 'Jane Smith')
 f = mock('Funding', :type => 'public')
 l = mock('Library', :HeadLibrarian => h, :Funding => f)

Notes

edit
  1. ^ Cite error: The named reference :0 was invoked but never defined (see the help page).

[1]

  1. ^ google.com