@Before public void setUp() { final HViewManager hvManager = new SimpleHViewManager(); final HView view = hvManager.createView().withDisplayName("View 1").build(); fixture = view.createChild().withDisplayName("Parent").build(); } }
@Test(expected=AsException.class) public void aRenamableItemMustNotBeMovable() { final HItem item = fixture.createChild(). withDisplayName("My Item 1"). thatCanBeRenamed(). build(); item.as(Movable); }
/******************************************************************************************************************* * * Specifies the id of the object to build. * * @param object the id * @return itself * ******************************************************************************************************************/ @Nonnull public Builder<T> withId (final @Nonnull String id) { return withId(new Id(id)); }
@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 testFindOrCreateViewWithNoView() { final HView view = hvManager.findOrCreateView().withId("id1"). withDisplayName("the name"). build(); assertThat(view.getId(), is(new Id("id1"))); }
@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))); }
HView galleries = hvManager.findOrCreateView().withId("urn:Galleries"). withDisplayName("Galleries"). 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(); HView trips = hvManager.findOrCreateView().withId("urn:Trips"). withDisplayName("Trips"). build(); HItem trip1 = trips.createChild().withDisplayName("Trip 1").build(); trip1.createChild().boundTo(photo1).build(); trip1.createChild().boundTo(photo3).build();
@Test(expected=IllegalArgumentException.class) public void mustThrowExceptionWhenNoExplicitDisplayNameAndNoBoundObject() { fixture.createChild().build(); }
/******************************************************************************************************************* * * Specifies that the object to build can be renamed. * * @return itself * ******************************************************************************************************************/ @Nonnull public Builder<T> thatCanBeRenamed() { return thatCanBeRenamed(true); }
@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 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 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))); }
@Before public void setUp() { hViewManager = Locator.find(HViewManager); hViewManager.as(Resettable.class).reset(); hView = hViewManager.createView().withDisplayName("view 1").build(); hItems[0] = hView.createChild().withDisplayName("item 1").build(); hItems[1] = hView.createChild().withDisplayName("item 2").build(); hItems[2] = hView.createChild().withDisplayName("item 3").build(); }
@Test(expected=AsException.class) public void aRenamableItemMustNotBeCopiable() { final HItem item = fixture.createChild(). withDisplayName("My Item 1"). thatCanBeRenamed(). build(); item.as(Copiable); }
@Test public void testFindOrCreateViewWithExistingView() { final HView view1 = hvManager.createView().withDisplayName("a name").build(); final HView view2 = hvManager.findOrCreateView().withId(view1.getId()). withDisplayName("the name"). build(); assertThat(view2, is(sameInstance(view1))); assertThat(view1.as(Displayable).getDisplayName(), is("a name")); }
@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")); }
@Before public void setUp() { hViewManager = Locator.find(HViewManager); hViewManager.as(Resettable.class).reset(); assertThat(hViewManager.findViews().count(), is(0)); hViews[0] = hViewManager.createView().withDisplayName("view 1").build(); hViews[1] = hViewManager.createView().withDisplayName("view 2").build(); hViews[2] = hViewManager.createView().withDisplayName("view 3").build(); }
@Test(expected=AsException.class) public void aRenamableViewMustNotBeCopiable() { final HView view = hvManager.createView(). withDisplayName("My View 1"). thatCanBeRenamed(). build(); view.as(Copiable); }
@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(expected=AsException.class) public void aDefaultViewMustNotBeMovable() { final HView view = hvManager.createView(). withDisplayName("My View 1"). build(); view.as(Movable); }