Skip to content
Snippets Groups Projects
Commit d9347cc4 authored by OZGCloud's avatar OZGCloud
Browse files

OZG-6867 Change order of methods

parent c53b2929
No related branches found
No related tags found
No related merge requests found
...@@ -23,15 +23,6 @@ abstract class GroupMapper { ...@@ -23,15 +23,6 @@ abstract class GroupMapper {
public abstract List<Group> fromGroupRepresentations(List<GroupRepresentation> groupRepresentations); public abstract List<Group> fromGroupRepresentations(List<GroupRepresentation> groupRepresentations);
@AfterMapping
protected void deleteGroupsWithoutOrganisationsEinheitId(@MappingTarget List<Group> groups) {
groups.removeIf(this::isMissingOrganisationsEinheitId);
}
protected boolean isMissingOrganisationsEinheitId(Group group) {
return StringUtils.isBlank(group.getOrganisationsEinheitId());
}
@Mapping(target = "organisationsEinheitId", source = "attributes") @Mapping(target = "organisationsEinheitId", source = "attributes")
public abstract Group fromGroupRepresentation(GroupRepresentation groupRepresentation); public abstract Group fromGroupRepresentation(GroupRepresentation groupRepresentation);
...@@ -49,6 +40,15 @@ abstract class GroupMapper { ...@@ -49,6 +40,15 @@ abstract class GroupMapper {
return values.getFirst(); return values.getFirst();
} }
@AfterMapping
protected void deleteGroupsWithoutOrganisationsEinheitId(@MappingTarget List<Group> groups) {
groups.removeIf(this::isMissingOrganisationsEinheitId);
}
protected boolean isMissingOrganisationsEinheitId(Group group) {
return StringUtils.isBlank(group.getOrganisationsEinheitId());
}
@Mapping(target = "attributes", expression = "java(buildGroupAttributes(groupToAdd))") @Mapping(target = "attributes", expression = "java(buildGroupAttributes(groupToAdd))")
public abstract GroupRepresentation toGroupRepresentation(AddGroupData groupToAdd); public abstract GroupRepresentation toGroupRepresentation(AddGroupData groupToAdd);
......
...@@ -93,65 +93,6 @@ class GroupMapperTest { ...@@ -93,65 +93,6 @@ class GroupMapperTest {
} }
} }
@Nested
class TestDeleteGroupsWithoutOrganisationsEinheitId {
private final Group group = GroupTestFactory.create();
private final List<Group> groups = new ArrayList<>();
@BeforeEach
void init() {
groups.add(group);
}
@Test
void shouldCheckIfGroupHasOrganisationsEinheitId() {
mapper.deleteGroupsWithoutOrganisationsEinheitId(groups);
verify(mapper).isMissingOrganisationsEinheitId(group);
}
@Test
void shouldKeepGroupsWithOrganisationsEinheitId() {
doReturn(false).when(mapper).isMissingOrganisationsEinheitId(group);
mapper.deleteGroupsWithoutOrganisationsEinheitId(groups);
assertThat(groups).containsExactly(group);
}
@Test
void shouldRemoveGroupsWithoutOrganisationsEinheitId() {
doReturn(true).when(mapper).isMissingOrganisationsEinheitId(group);
mapper.deleteGroupsWithoutOrganisationsEinheitId(groups);
assertThat(groups).isEmpty();
}
}
@Nested
class TestIsMissingOrganisationsEinheitId {
@ParameterizedTest
@ValueSource(strings = " ")
@NullAndEmptySource
void shouldReturnTrueIfIdIsBlank(String organisationsEinheitId) {
var group = GroupTestFactory.createBuilder().organisationsEinheitId(organisationsEinheitId).build();
var isMissing = mapper.isMissingOrganisationsEinheitId(group);
assertThat(isMissing).isTrue();
}
@Test
void shouldReturnFalseIfIdIsSet() {
var isMissing = mapper.isMissingOrganisationsEinheitId(GroupTestFactory.create());
assertThat(isMissing).isFalse();
}
}
@Nested @Nested
class TestFromGroupRepresentation { class TestFromGroupRepresentation {
...@@ -246,6 +187,65 @@ class GroupMapperTest { ...@@ -246,6 +187,65 @@ class GroupMapperTest {
} }
} }
@Nested
class TestDeleteGroupsWithoutOrganisationsEinheitId {
private final Group group = GroupTestFactory.create();
private final List<Group> groups = new ArrayList<>();
@BeforeEach
void init() {
groups.add(group);
}
@Test
void shouldCheckIfGroupHasOrganisationsEinheitId() {
mapper.deleteGroupsWithoutOrganisationsEinheitId(groups);
verify(mapper).isMissingOrganisationsEinheitId(group);
}
@Test
void shouldKeepGroupsWithOrganisationsEinheitId() {
doReturn(false).when(mapper).isMissingOrganisationsEinheitId(group);
mapper.deleteGroupsWithoutOrganisationsEinheitId(groups);
assertThat(groups).containsExactly(group);
}
@Test
void shouldRemoveGroupsWithoutOrganisationsEinheitId() {
doReturn(true).when(mapper).isMissingOrganisationsEinheitId(group);
mapper.deleteGroupsWithoutOrganisationsEinheitId(groups);
assertThat(groups).isEmpty();
}
}
@Nested
class TestIsMissingOrganisationsEinheitId {
@ParameterizedTest
@ValueSource(strings = " ")
@NullAndEmptySource
void shouldReturnTrueIfIdIsBlank(String organisationsEinheitId) {
var group = GroupTestFactory.createBuilder().organisationsEinheitId(organisationsEinheitId).build();
var isMissing = mapper.isMissingOrganisationsEinheitId(group);
assertThat(isMissing).isTrue();
}
@Test
void shouldReturnFalseIfIdIsSet() {
var isMissing = mapper.isMissingOrganisationsEinheitId(GroupTestFactory.create());
assertThat(isMissing).isFalse();
}
}
@Nested @Nested
class TestToGroupRepresentation { class TestToGroupRepresentation {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment