/******************************************************************************************************************* * * {@inheritDoc} * ******************************************************************************************************************/ @Override @Nonnull public <T> T as (final @Nonnull Class<T> roleType) { return as(roleType, As.Defaults.throwAsException(roleType)); }
/******************************************************************************************************************* * ******************************************************************************************************************/ @Test(expectedExceptions = AsException.class) public void must_not_find_inexistent_role() { final DefaultPresentationModel fixture = new DefaultPresentationModel(ownerNoAs, localRole1); fixture.as(Role2.class); }
/******************************************************************************************************************* * ******************************************************************************************************************/ @Test(expectedExceptions = AsException.class) public void must_not_find_inexistent_role_bis() { final DefaultPresentationModel fixture = new DefaultPresentationModel(ownerAsWithRole2, localRole2); fixture.as(Role1.class); }
/******************************************************************************************************************* * ******************************************************************************************************************/ @Test public void must_find_local_roles() { final DefaultPresentationModel fixture1 = new DefaultPresentationModel(ownerNoAs, localRole1); final DefaultPresentationModel fixture2 = new DefaultPresentationModel(ownerNoAs, localRole1, localRole2); assertThat(fixture1.as(Role1.class), is(sameInstance(localRole1))); assertThat(fixture2.as(Role1.class), is(sameInstance(localRole1))); assertThat(fixture2.as(Role2.class), is(sameInstance(localRole2))); }
/******************************************************************************************************************* * ******************************************************************************************************************/ @Test public void must_give_priority_to_local_roles() { final DefaultPresentationModel fixture = new DefaultPresentationModel(ownerAsWithRole2, localRole2); assertThat(fixture.as(Role2.class), is(sameInstance(localRole2))); } }
/******************************************************************************************************************* * ******************************************************************************************************************/ @Test public void must_find_roles_in_owner() { final DefaultPresentationModel fixture = new DefaultPresentationModel(ownerAsWithRole2); assertThat(fixture.as(Role2.class), is(sameInstance(role2InOwner))); }
/******************************************************************************************************************* * * ******************************************************************************************************************/ protected void populateView() { log.info("populate() - presentation model: {}", presentationModel); try { if (presentationModel.as(Composite).findChildren().count() > 0) { view.populate(presentationModel); } else { view.notifyNoData(notification().withText(_, "noData")); } } catch (AsException e) { view.notifyNoData(notification().withText(_, "noData")); } view.unlock(); }