RepositoryCleanupAttributesUtil { public static void initializeCleanupAttributes(final RepositoryXO repositoryXO) { checkNotNull(repositoryXO); Map<String, Map<String, Object>> attributes = checkNotNull(repositoryXO.getAttributes()); Map<String, Object> cleanup = attributes.get(CLEANUP_ATTRIBUTES_KEY); if (nonNull(cleanup)) { @SuppressWarnings("unchecked") Collection<String> policyNames = (Collection<String>) cleanup.get(CLEANUP_NAME_KEY); if(isNull(policyNames) || policyNames.isEmpty()) { attributes.remove(CLEANUP_ATTRIBUTES_KEY); } else { cleanup.put(CLEANUP_NAME_KEY, newLinkedHashSet(policyNames)); } } } private  RepositoryCleanupAttributesUtil(); static void initializeCleanupAttributes(final RepositoryXO repositoryXO);  }
@Test(expected = NullPointerException.class) public void when_No_RepositoryXO_Provided_Should_Fail() { initializeCleanupAttributes(null); }
@Test public void when_Policies_Provided_Should_Convert_Into_Set() { initializeCleanupAttributes(repositoryXO); assertThat(getCleanupPolicyNames(), is(instanceOf(Set.class))); }
@Test public void when_CleanupPolicies_Provided_Should_Return_Same_Policies_In_Order() { List<String> listPolicyNames = getCleanupPolicyNamesAsList(); initializeCleanupAttributes(repositoryXO); Set<String> setPolicyNames = getCleanupPolicyNamesAsSet(); assertThat(setPolicyNames, is(not(empty()))); int index = 0; for (String policyName : getCleanupPolicyNamesAsSet()) { assertThat(listPolicyNames.get(index), is(equalTo(policyName))); index++; } }
@Test public void when_Null_Policies_Provided_Should_Remove_Cleanup_Attribute() { cleanup.put(CLEANUP_NAME_KEY, null); initializeCleanupAttributes(repositoryXO); assertThat(getCleanupAttribute(), is(nullValue())); }
@Test public void when_Empty_Policies_Provided_Should_Remove_Cleanup_Attribute() { cleanup.put(CLEANUP_NAME_KEY, emptyList()); initializeCleanupAttributes(repositoryXO); assertThat(getCleanupAttribute(), is(nullValue())); }
@Test public void when_No_CleanupAttribute_Provided_Should_Not_Add_It() { attributes.put(CLEANUP_ATTRIBUTES_KEY, null); initializeCleanupAttributes(repositoryXO); assertThat(getCleanupAttribute(), is(nullValue())); }