From 64d826292203bf9ebb44fb9acd85d05b604a62bf Mon Sep 17 00:00:00 2001 From: megli2 Date: Fri, 17 Nov 2023 14:45:41 +0100 Subject: [PATCH] rename method and write tests to see if it works --- .../ch/puzzle/okr/mapper/OverviewMapper.java | 2 +- .../business/OrganisationBusinessService.java | 2 +- .../OrganisationBusinessServiceTest.java | 19 +++++++++++++++++++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/backend/src/main/java/ch/puzzle/okr/mapper/OverviewMapper.java b/backend/src/main/java/ch/puzzle/okr/mapper/OverviewMapper.java index d03f7fc995..bc01cf187c 100644 --- a/backend/src/main/java/ch/puzzle/okr/mapper/OverviewMapper.java +++ b/backend/src/main/java/ch/puzzle/okr/mapper/OverviewMapper.java @@ -69,7 +69,7 @@ private OverviewDto createOverviewDto(Overview overview) { return new OverviewDto( new OverviewTeamDto(overview.getOverviewId().getTeamId(), overview.getTeamName(), overview.isWriteable(), - organisationBusinessService.teamHasInactiveOrganisations(overview.getOverviewId().getTeamId())), + organisationBusinessService.teamHasInActiveOrganisations(overview.getOverviewId().getTeamId())), objectives); } diff --git a/backend/src/main/java/ch/puzzle/okr/service/business/OrganisationBusinessService.java b/backend/src/main/java/ch/puzzle/okr/service/business/OrganisationBusinessService.java index f8d4467caa..d73e39e4d4 100644 --- a/backend/src/main/java/ch/puzzle/okr/service/business/OrganisationBusinessService.java +++ b/backend/src/main/java/ch/puzzle/okr/service/business/OrganisationBusinessService.java @@ -54,7 +54,7 @@ public List getActiveOrganisations() { return persistenceService.getActiveOrganisations(); } - public boolean teamHasInactiveOrganisations(Long teamId) { + public boolean teamHasInActiveOrganisations(Long teamId) { return !getOrganisationsByTeam(teamId).stream() .filter(organisation -> organisation.getState() == OrganisationState.INACTIVE).toList().isEmpty(); } diff --git a/backend/src/test/java/ch/puzzle/okr/service/business/OrganisationBusinessServiceTest.java b/backend/src/test/java/ch/puzzle/okr/service/business/OrganisationBusinessServiceTest.java index 9eadc5730a..6ef6969e60 100644 --- a/backend/src/test/java/ch/puzzle/okr/service/business/OrganisationBusinessServiceTest.java +++ b/backend/src/test/java/ch/puzzle/okr/service/business/OrganisationBusinessServiceTest.java @@ -17,6 +17,8 @@ import java.util.ArrayList; import java.util.List; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; @@ -34,6 +36,9 @@ class OrganisationBusinessServiceTest { private static final Organisation organisationThree = Organisation.Builder.builder().withId(2L) .withOrgName("org_three").withState(OrganisationState.ACTIVE).build(); + private static final Organisation organisationInActive = Organisation.Builder.builder().withId(2L) + .withOrgName("org_in_active").withState(OrganisationState.INACTIVE).build(); + @Mock LdapTemplate ldapTemplate; @@ -78,4 +83,18 @@ void getOrganisationsByTeamId() { organisationBusinessService.getOrganisationsByTeam(1L); verify(organisationPersistenceService, times(1)).getOrganisationsByTeamId(1L); } + + @Test + void teamHasInActiveOrganisations() { + when(organisationPersistenceService.getOrganisationsByTeamId(anyLong())) + .thenReturn(List.of(organisationInActive, organisationOne, organisationTwo)); + assertTrue(organisationBusinessService.teamHasInActiveOrganisations(1L)); + } + + @Test + void teamHasNoInActiveOrganisations() { + when(organisationPersistenceService.getOrganisationsByTeamId(anyLong())) + .thenReturn(List.of(organisationOne, organisationTwo, organisationThree)); + assertFalse(organisationBusinessService.teamHasInActiveOrganisations(1L)); + } }