@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 aDefaultItemCannotBeRenamed() { final HItem item = fixture.createChild(). withDisplayName("My Item 1"). build(); assertThat(item, is(notNullValue())); assertThat(item.as(Displayable), is(not(instanceOf(MutableDisplayable.class)))); }
@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 aRenamableItemCanBeRenamed() { final HItem item = fixture.createChild(). withDisplayName("My Item 1"). thatCanBeRenamed(). build(); assertThat(item, is(notNullValue())); item.as(MutableDisplayable.class).setDisplayName("New Item Name"); assertThat(item.as(Displayable).getDisplayName(), is("New Item Name")); }
@Test public void aDefaultItemMustHaveTheCorrectName() { final HItem item = fixture.createChild(). withDisplayName("My Item 1"). build(); assertThat(item, is(notNullValue())); assertThat(item.as(Displayable).getDisplayName(), is("My Item 1")); }
@Test public void aRenamableItemMustHaveTheCorrectName() { final HItem item = fixture.createChild(). withDisplayName("My Item 1"). thatCanBeRenamed(). build(); assertThat(item, is(notNullValue())); assertThat(item.as(Displayable).getDisplayName(), is("My Item 1")); }
@Test(expected=AsException.class) public void aDefaultItemMustNotBeMovable() { final HItem item = fixture.createChild(). withDisplayName("My Item 1"). build(); item.as(Movable); }
@Test(expected=AsException.class) public void aDefaultItemMustNotBeCopiable() { final HItem item = fixture.createChild(). withDisplayName("My Item 1"). build(); item.as(Copiable); }
@Test(expected=AsException.class) public void aRenamableItemMustNotBeMovable() { final HItem item = fixture.createChild(). withDisplayName("My Item 1"). thatCanBeRenamed(). build(); item.as(Movable); }
@Test(expected=AsException.class) public void aRenamableItemMustNotBeCopiable() { final HItem item = fixture.createChild(). withDisplayName("My Item 1"). thatCanBeRenamed(). build(); item.as(Copiable); }
@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))); }
@Test public void testFindOrCreateItemWithExistingItem() { final HItem item1 = fixture.createChild().withDisplayName("a name").build(); final HItem item2 = fixture.findOrCreateChild().withId(item1.getId()). withDisplayName("the name"). build(); assertThat(item2, is(sameInstance(item1))); assertThat(item1.as(Displayable).getDisplayName(), is("a name")); }
System.err.println(item.as(Photo.class));