### Question:
CaptionAspectDefinition extends ModelToUiAspectDefinition<String> { @Override public Aspect<String> createAspect() { switch (captionType) { case AUTO: return StringUtils.isEmpty(staticCaption) ? Aspect.of(NAME) : Aspect.of(NAME, staticCaption); case DYNAMIC: return Aspect.of(NAME); case STATIC: return Aspect.of(NAME, staticCaption); case NONE: return Aspect.of(NAME, null); default: throw new IllegalArgumentException("CaptionType " + captionType + " is not supported."); } } CaptionAspectDefinition(CaptionType captionType, String staticCaption); @Override Aspect<String> createAspect(); @Override Consumer<String> createComponentValueSetter(ComponentWrapper componentWrapper); @Override boolean supports(WrapperType type); static final String NAME; }### Answer:
@Test public void testCreateAspect_Static() { CaptionAspectDefinition captionAspectDefinition = new CaptionAspectDefinition(CaptionType.STATIC, "foo"); Aspect<String> aspect = captionAspectDefinition.createAspect(); assertThat(aspect.getName(), is(CaptionAspectDefinition.NAME)); assertThat(aspect.getValue(), is("foo")); }
@Test public void testCreateAspect_Auto_WithValue() { CaptionAspectDefinition captionAspectDefinition = new CaptionAspectDefinition(CaptionType.AUTO, "foo"); Aspect<String> aspect = captionAspectDefinition.createAspect(); assertThat(aspect.getName(), is(CaptionAspectDefinition.NAME)); assertThat(aspect.getValue(), is("foo")); }
@Test public void testCreateAspect_Auto_WithoutValue() { CaptionAspectDefinition captionAspectDefinition = new CaptionAspectDefinition(CaptionType.AUTO, ""); Aspect<String> aspect = captionAspectDefinition.createAspect(); assertThat(aspect.getName(), is(CaptionAspectDefinition.NAME)); assertThat(aspect.isValuePresent(), is(false)); }
@Test public void testCreateAspect_Dynamic() { CaptionAspectDefinition captionAspectDefinition = new CaptionAspectDefinition(CaptionType.DYNAMIC, "foo"); Aspect<String> aspect = captionAspectDefinition.createAspect(); assertThat(aspect.getName(), is(CaptionAspectDefinition.NAME)); assertThat(aspect.isValuePresent(), is(false)); }
@Test public void testCreateAspect_None() { CaptionAspectDefinition captionAspectDefinition = new CaptionAspectDefinition(CaptionType.NONE, "foo"); Aspect<String> aspect = captionAspectDefinition.createAspect(); assertThat(aspect.getName(), is(CaptionAspectDefinition.NAME)); assertThat(aspect.getValue(), is(nullValue())); }