@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 aDefaultItemMustReturnTheRightView() { final HItem item = fixture.createChild(). withDisplayName("My Item 1"). build(); assertThat(item, is(notNullValue())); assertThat(item.getView(), is(sameInstance(fixture.getView()))); }
@Test public void aChildItemMustHaveTheRightParent() throws NotFoundException { final HItem item = fixture.createChild(). withDisplayName("My Item 1"). build(); assertThat(item, is(notNullValue())); assertThat(item.getParent(), is(sameInstance(fixture))); } }
build(); HItem gallery1 = galleries.createChild().withDisplayName("Gallery 1").build(); 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(); for (HItem item : gallery1.findChildren().boundToType(Photo.class).results()) System.err.println(item.as(Photo.class));
@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")); }
@Test public void aDefaultItemMustReturnTheRightView() { final HItem item = fixture.createChild(). withDisplayName("My Item 1"). build(); assertThat(item, is(notNullValue())); assertThat(item.getView(), is(sameInstance(fixture))); }
@Test public void aDefaultItemMustBeInitiallyEmpty() { final HItem item = fixture.createChild(). withDisplayName("My Item 1"). build(); assertThat(item.findChildren().count(), is(0)); }
@Test(expected=NotFoundException.class) public void aRootItemMustHaveNoParent() throws NotFoundException { final HItem item = fixture.createChild(). withDisplayName("My Item 1"). build(); assertThat(item, is(notNullValue())); final HItem parent = item.getParent(); fail("Returned parent: " + parent); } }
@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 aRenamableItemMustReturnTheRightView() { final HItem item = fixture.createChild(). withDisplayName("My Item 1"). thatCanBeRenamed(). build(); assertThat(item, is(notNullValue())); assertThat(item.getView(), is(sameInstance(fixture))); }
@Test public void aRenamableItemMustBeInitiallyEmpty() { final HItem item = fixture.createChild(). withDisplayName("My Item 1"). thatCanBeRenamed(). build(); assertThat(item.findChildren().count(), is(0)); }
@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 aRenamableItemMustReturnTheRightView() { final HItem item = fixture.createChild(). withDisplayName("My Item 1"). thatCanBeRenamed(). build(); assertThat(item, is(notNullValue())); assertThat(item.getView(), is(sameInstance(fixture.getView()))); }
@Test public void aDefaultItemMustHaveAnId() { final HItem item = fixture.createChild(). withDisplayName("My Item 1"). build(); assertThat(item, is(notNullValue())); assertThat(item.getId(), is(notNullValue())); }
@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 aRenamableItemMustHaveAnId() { final HItem item = fixture.createChild(). withDisplayName("My Item 1"). thatCanBeRenamed(). build(); assertThat(item, is(notNullValue())); assertThat(item.getId(), is(notNullValue())); }
@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 testFindOrCreateItemWithNoItem() { final HItem item = fixture.findOrCreateChild().withId("id1"). withDisplayName("the name"). build(); assertThat(item.getId(), is(new Id("id1"))); }
@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")); }