Utilities { static void safelySetAttribute(Metacard metacard, Attribute attribute) { notNull(attribute, "Attribute cannot be null"); safelySetAttribute(metacard, attribute.getName(), attribute.getValues()); }  static boolean isBlankString(Serializable serializable); static boolean isNotBlankString(Serializable serializable); static boolean isAlphanumericString(Serializable serializable); static boolean isNotStringNone(Serializable serializable);  }
@Test public void testSafelySetCorrectAttribute() throws Exception { safelySetAttribute(metacard, ATTRIBUTE_KEY_POC, EXPECTED_POC); assertThat(metacard.getPointOfContact(), is(EXPECTED_POC)); }
@Test public void testSafelySetIncorrectAttribute() throws Exception { safelySetAttribute(metacard, ATTRIBUTE_KEY_POC, 899); assertThat(metacard.getPointOfContact(), is(nullValue())); }
@Test public void testSafelySetCorrectMultiValuedAttribute() throws Exception { safelySetAttribute(metacard, ATTRIBUTE_KEY_TAG, Arrays.asList("Tag-A", "Tag-B")); Set<String> tags = metacard.getTags(); assertThat(tags, is(notNullValue())); assertThat(tags, containsInAnyOrder("Tag-A", "Tag-B")); }
@Test public void testSafelySetIncorrectMultiValuedAttribute() throws Exception { safelySetAttribute(metacard, ATTRIBUTE_KEY_TAG, Arrays.asList("Tag-A", 899)); assertThat(metacard.getTags(), is(empty())); }
@Test public void testSafelySetCorrectlyUsingAttribute() throws Exception { AttributeImpl attribute = new AttributeImpl(ATTRIBUTE_KEY_POC, EXPECTED_POC); safelySetAttribute(metacard, attribute); assertThat(metacard.getPointOfContact(), is(EXPECTED_POC)); }
@Test public void testSafelySetIncorrectlyUsingAttribute() throws Exception { AttributeImpl attribute = new AttributeImpl(ATTRIBUTE_KEY_POC, 899); safelySetAttribute(metacard, attribute); assertThat(metacard.getPointOfContact(), is(nullValue())); }
@Test public void testNullDescriptorDoesNotSetAttribute() throws Exception { AttributeImpl attribute = new AttributeImpl(ATTRIBUTE_KEY_POC, EXPECTED_POC); Metacard mockedMetacard = setupMetacardWithNullDescriptor(); safelySetAttribute(mockedMetacard, attribute); assertThat(metacard.getPointOfContact(), is(nullValue())); }