Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagejava
@Test
public class FindingUserDataChooserTest
{
    FindingUserDataChooser component;

    @Mock
    UserFinder userFinder;

    @Before
    private void init()
    {
        MockitoAnnotations.initMocks( this );
        when( userFinder.findByCriteria( any( DetachedCriteria.class ) ) ).thenReturn( getSampleUserList() );
        component = new FindingUserDataChooser( userFinder );
    }

    private List<User> getSampleUserList()
    {
        User user1 = new User( "user1", "password" );
        User user2 = new User( "user2", "password" );
        return Lists.newArrayList( user1, user2 );
    }

    @Test
    private void componentTest()
    {
        // ...
    }
}
Warning

Pamiętać należy również, że do wywołania komponentów należy stworzyć specyficzne dla rodzaju komponentu obiekty. Przykładowo dla powyższego DataChoosera można zauważyć, iż metoda data przyjmuje obiekty ComponentQueryData oraz DataChooserResult, które w testach należy własnoręcznie stworzyć.