@Test(expected=IllegalArgumentException.class) public void mustThrowExceptionWhenNoExplicitDisplayNameAndBoundObjectHasNoDisplayName() { final Lookup.Provider boundObject = mock(Lookup.Provider.class); when(boundObject.getLookup()).thenReturn(Lookup.EMPTY); fixture.createChild().boundTo(boundObject).build(); }
@Test public void mustUseTheDisplayableOfBoundObjectWhenNoExpicitDisplayableIsProvided() { final Displayable displayable = mock(Displayable.class); final Lookup lookup = Lookups.fixed(displayable); final Lookup.Provider boundObject = mock(Lookup.Provider.class); when(boundObject.getLookup()).thenReturn(lookup); final HItem item = fixture.createChild().boundTo(boundObject).build(); assertThat(item.as(Displayable), is(sameInstance(displayable))); }
@Test public void mustUseTheProvidedDisplayableEvenWhenTheBoundObjectHasGotExpicitDisplayable() { final Displayable displayable = mock(Displayable.class); final Lookup lookup = Lookups.fixed(displayable); final Lookup.Provider boundObject = mock(Lookup.Provider.class); when(boundObject.getLookup()).thenReturn(lookup); final HItem item = fixture.createChild().boundTo(boundObject).withDisplayName("new name").build(); assertThat(item.as(Displayable), is(not(sameInstance(displayable)))); assertThat(item.as(Displayable).getDisplayName(), is("new name")); }
@Test public void mustMakeTheBoundObjectAvailableInTheLookup() { final BoundObject boundObject = new BoundObject(); final HItem hItem = fixture.createChild().boundTo(boundObject).withDisplayName("name").build(); assertThat(hItem.getLookup().lookup(BoundObject.class), is(sameInstance(boundObject))); }
@Test public void mustMakeTheBoundObjectAvailableAsAPersonality() { final BoundObject boundObject = new BoundObject(); final HItem hItem = fixture.createChild().boundTo(boundObject).withDisplayName("name").build(); assertThat(hItem.as(BoundObject.class), is(sameInstance(boundObject))); }
HItem folder1 = gallery1.createChild().withDisplayName("Folder 1").build(); gallery1.createChild().boundTo(photo1).build(); folder1.createChild().boundTo(photo2).build(); folder1.createChild().boundTo(photo3).build(); build(); HItem trip1 = trips.createChild().withDisplayName("Trip 1").build(); trip1.createChild().boundTo(photo1).build(); trip1.createChild().boundTo(photo3).build();