### Question:
CommandEntity extends BaseEntity { public void setApplications( @Nullable final List<ApplicationEntity> applications ) throws PreconditionFailedException { if (applications != null && applications.stream().map(ApplicationEntity::getUniqueId).distinct().count() != applications.size()) { throw new PreconditionFailedException("List of applications to set cannot contain duplicates"); } for (final ApplicationEntity application : this.applications) { application.getCommands().remove(this); } this.applications.clear(); if (applications != null) { this.applications.addAll(applications); for (final ApplicationEntity application : this.applications) { application.getCommands().add(this); } } } CommandEntity(); void setExecutable(@NotEmpty final List<@NotBlank @Size(max = 1024) String> executable); void setConfigs(@Nullable final Set<FileEntity> configs); void setDependencies(@Nullable final Set<FileEntity> dependencies); void setTags(@Nullable final Set<TagEntity> tags); Optional<Integer> getMemory(); Optional<JsonNode> getLauncherExt(); void setLauncherExt(@Nullable final JsonNode launcherExt); void setApplications(
        @Nullable final List<ApplicationEntity> applications
    ); void addApplication(@NotNull final ApplicationEntity application); void removeApplication(@NotNull final ApplicationEntity application); void setClusterCriteria(@Nullable final List<CriterionEntity> clusterCriteria); void addClusterCriterion(final CriterionEntity criterion); void addClusterCriterion(final CriterionEntity criterion, final int priority); CriterionEntity removeClusterCriterion(final int priority); @Override boolean equals(final Object o); @Override int hashCode(); static final String APPLICATIONS_ENTITY_GRAPH; static final String APPLICATIONS_DTO_ENTITY_GRAPH; static final String CLUSTER_CRITERIA_ENTITY_GRAPH; static final String DTO_ENTITY_GRAPH; }### Answer:
@Test void testSetApplications() throws GenieCheckedException { Assertions.assertThat(this.c.getApplications()).isEmpty(); final ApplicationEntity one = new ApplicationEntity(); one.setUniqueId("one"); final ApplicationEntity two = new ApplicationEntity(); two.setUniqueId("two"); final List<ApplicationEntity> applicationEntities = Lists.newArrayList(one, two); this.c.setApplications(applicationEntities); Assertions.assertThat(this.c.getApplications()).isEqualTo(applicationEntities); Assertions.assertThat(one.getCommands()).contains(this.c); Assertions.assertThat(two.getCommands()).contains(this.c); applicationEntities.clear(); applicationEntities.add(two); this.c.setApplications(applicationEntities); Assertions.assertThat(this.c.getApplications()).isEqualTo(applicationEntities); Assertions.assertThat(one.getCommands()).doesNotContain(this.c); Assertions.assertThat(two.getCommands()).contains(this.c); this.c.setApplications(null); Assertions.assertThat(this.c.getApplications()).isEmpty(); Assertions.assertThat(one.getCommands()).isEmpty(); Assertions.assertThat(two.getCommands()).isEmpty(); }
@Test void cantSetApplicationsIfDuplicates() { final ApplicationEntity one = Mockito.mock(ApplicationEntity.class); Mockito.when(one.getUniqueId()).thenReturn(UUID.randomUUID().toString()); final ApplicationEntity two = Mockito.mock(ApplicationEntity.class); Mockito.when(two.getUniqueId()).thenReturn(UUID.randomUUID().toString()); Assertions .assertThatExceptionOfType(PreconditionFailedException.class) .isThrownBy(() -> this.c.setApplications(Lists.newArrayList(one, two, one))); }