From fb91356b7777dfa5b6088bcc3a48b43924c1c0fd Mon Sep 17 00:00:00 2001 From: Paul-Christian Volkmer Date: Thu, 3 Sep 2026 14:35:10 +0200 Subject: build: apply Spotless plugin (#293) --- .../consent/ConsentManagerServiceFactoryTest.java | 56 +++---- .../consent/MrConsentManagerServiceTest.java | 64 ++++--- .../consent/UkwConsentManagerServiceTest.java | 185 +++++++++++---------- 3 files changed, 150 insertions(+), 155 deletions(-) (limited to 'src/test/java/dev/dnpm/oshelper/services/consent') diff --git a/src/test/java/dev/dnpm/oshelper/services/consent/ConsentManagerServiceFactoryTest.java b/src/test/java/dev/dnpm/oshelper/services/consent/ConsentManagerServiceFactoryTest.java index 57e505b..7d086de 100644 --- a/src/test/java/dev/dnpm/oshelper/services/consent/ConsentManagerServiceFactoryTest.java +++ b/src/test/java/dev/dnpm/oshelper/services/consent/ConsentManagerServiceFactoryTest.java @@ -19,7 +19,13 @@ package dev.dnpm.oshelper.services.consent; +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.Mockito.when; + import de.itc.onkostar.api.IOnkostarApi; +import java.util.Map; +import java.util.Set; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.params.ParameterizedTest; @@ -27,43 +33,33 @@ import org.junit.jupiter.params.provider.MethodSource; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; -import java.util.Map; -import java.util.Set; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.Mockito.when; - @ExtendWith(MockitoExtension.class) class ConsentManagerServiceFactoryTest { - private IOnkostarApi onkostarApi; - - private ConsentManagerServiceFactory consentManagerServiceFactory; + private IOnkostarApi onkostarApi; - @BeforeEach - void setup( - @Mock IOnkostarApi onkostarApi - ) { - this.onkostarApi = onkostarApi; - this.consentManagerServiceFactory = new ConsentManagerServiceFactory(onkostarApi); - } + private ConsentManagerServiceFactory consentManagerServiceFactory; - private static Set>> expectedMappings() { - return Map.ofEntries( - Map.entry("MR.Consent", MrConsentManagerService.class), - Map.entry("Excel-Formular", UkwConsentManagerService.class) - ).entrySet(); - } + @BeforeEach + void setup(@Mock IOnkostarApi onkostarApi) { + this.onkostarApi = onkostarApi; + this.consentManagerServiceFactory = new ConsentManagerServiceFactory(onkostarApi); + } - @ParameterizedTest - @MethodSource("expectedMappings") - void testShouldMapFormNameToService(Map.Entry> expectedMapping) { - when(onkostarApi.getGlobalSetting(anyString())).thenReturn(expectedMapping.getKey()); + private static Set>> expectedMappings() { + return Map.ofEntries( + Map.entry("MR.Consent", MrConsentManagerService.class), + Map.entry("Excel-Formular", UkwConsentManagerService.class)) + .entrySet(); + } - var actual = consentManagerServiceFactory.currentUsableInstance(); + @ParameterizedTest + @MethodSource("expectedMappings") + void testShouldMapFormNameToService(Map.Entry> expectedMapping) { + when(onkostarApi.getGlobalSetting(anyString())).thenReturn(expectedMapping.getKey()); - assertThat(actual).isExactlyInstanceOf(expectedMapping.getValue()); - } + var actual = consentManagerServiceFactory.currentUsableInstance(); + assertThat(actual).isExactlyInstanceOf(expectedMapping.getValue()); + } } diff --git a/src/test/java/dev/dnpm/oshelper/services/consent/MrConsentManagerServiceTest.java b/src/test/java/dev/dnpm/oshelper/services/consent/MrConsentManagerServiceTest.java index 12b9208..b747987 100644 --- a/src/test/java/dev/dnpm/oshelper/services/consent/MrConsentManagerServiceTest.java +++ b/src/test/java/dev/dnpm/oshelper/services/consent/MrConsentManagerServiceTest.java @@ -19,6 +19,9 @@ package dev.dnpm.oshelper.services.consent; +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.*; + import de.itc.onkostar.api.IOnkostarApi; import de.itc.onkostar.api.Procedure; import org.hibernate.SQLQuery; @@ -32,47 +35,42 @@ import org.mockito.ArgumentCaptor; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.*; - @ExtendWith(MockitoExtension.class) class MrConsentManagerServiceTest { - private IOnkostarApi onkostarApi; - - private MrConsentManagerService service; + private IOnkostarApi onkostarApi; - @BeforeEach - void setup( - @Mock IOnkostarApi onkostarApi - ) { - this.onkostarApi = onkostarApi; - this.service = new MrConsentManagerService(onkostarApi); - } + private MrConsentManagerService service; - @Test - void testShouldCreateSqlQueriesWithRelatedEntityIds() { - var sessionFactory = mock(SessionFactory.class); - var session = mock(Session.class); - var query = mock(SQLQuery.class); + @BeforeEach + void setup(@Mock IOnkostarApi onkostarApi) { + this.onkostarApi = onkostarApi; + this.service = new MrConsentManagerService(onkostarApi); + } - when(onkostarApi.getSessionFactory()).thenReturn(sessionFactory); - when(sessionFactory.getCurrentSession()).thenReturn(session); - when(session.createSQLQuery(anyString())).thenReturn(query); - when(query.addScalar(anyString(), any(Type.class))).thenReturn(query); - when(query.uniqueResult()).thenReturn(""); + @Test + void testShouldCreateSqlQueriesWithRelatedEntityIds() { + var sessionFactory = mock(SessionFactory.class); + var session = mock(Session.class); + var query = mock(SQLQuery.class); - var dummyProzedur = new Procedure(this.onkostarApi); - dummyProzedur.setId(111); - dummyProzedur.setPatientId(123); + when(onkostarApi.getSessionFactory()).thenReturn(sessionFactory); + when(sessionFactory.getCurrentSession()).thenReturn(session); + when(session.createSQLQuery(anyString())).thenReturn(query); + when(query.addScalar(anyString(), any(Type.class))).thenReturn(query); + when(query.uniqueResult()).thenReturn(""); - this.service.applyConsent(dummyProzedur); + var dummyProzedur = new Procedure(this.onkostarApi); + dummyProzedur.setId(111); + dummyProzedur.setPatientId(123); - var argumentCaptor = ArgumentCaptor.forClass(String.class); - verify(session, times(2)).createSQLQuery(argumentCaptor.capture()); - assertThat(argumentCaptor.getAllValues()).hasSize(2); - assertThat(argumentCaptor.getAllValues().get(0)).contains("where entity_id = '111'"); - assertThat(argumentCaptor.getAllValues().get(1)).contains("WHERE patient_id = 123 AND geloescht = 0"); - } + this.service.applyConsent(dummyProzedur); + var argumentCaptor = ArgumentCaptor.forClass(String.class); + verify(session, times(2)).createSQLQuery(argumentCaptor.capture()); + assertThat(argumentCaptor.getAllValues()).hasSize(2); + assertThat(argumentCaptor.getAllValues().get(0)).contains("where entity_id = '111'"); + assertThat(argumentCaptor.getAllValues().get(1)) + .contains("WHERE patient_id = 123 AND geloescht = 0"); + } } diff --git a/src/test/java/dev/dnpm/oshelper/services/consent/UkwConsentManagerServiceTest.java b/src/test/java/dev/dnpm/oshelper/services/consent/UkwConsentManagerServiceTest.java index f21492d..e28dd64 100644 --- a/src/test/java/dev/dnpm/oshelper/services/consent/UkwConsentManagerServiceTest.java +++ b/src/test/java/dev/dnpm/oshelper/services/consent/UkwConsentManagerServiceTest.java @@ -19,9 +19,14 @@ package dev.dnpm.oshelper.services.consent; +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.*; + import de.itc.onkostar.api.IOnkostarApi; import de.itc.onkostar.api.Item; import de.itc.onkostar.api.Procedure; +import java.sql.Date; +import java.time.Instant; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -29,129 +34,125 @@ import org.mockito.ArgumentCaptor; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; -import java.sql.Date; -import java.time.Instant; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.*; - @ExtendWith(MockitoExtension.class) class UkwConsentManagerServiceTest { - private IOnkostarApi onkostarApi; - - private UkwConsentManagerService service; - - @BeforeEach - void setup( - @Mock IOnkostarApi onkostarApi - ) { - this.onkostarApi = onkostarApi; - this.service = new UkwConsentManagerService(onkostarApi); - } + private IOnkostarApi onkostarApi; - @Test - void testShouldSkipUpdateRelatedDnpmKlinikAnamneseFormIfNoConsentAvailable() throws Exception { + private UkwConsentManagerService service; - var excelForm = new Procedure(this.onkostarApi); - excelForm.setId(111); - excelForm.setPatientId(123); - excelForm.setValue("refdnpmklinikanamnese", new Item("refdnpmklinikanamnese", 2)); + @BeforeEach + void setup(@Mock IOnkostarApi onkostarApi) { + this.onkostarApi = onkostarApi; + this.service = new UkwConsentManagerService(onkostarApi); + } - var dnpmKlinikAnamneseForm = new Procedure(this.onkostarApi); - dnpmKlinikAnamneseForm.setId(2); - dnpmKlinikAnamneseForm.setPatientId(123); + @Test + void testShouldSkipUpdateRelatedDnpmKlinikAnamneseFormIfNoConsentAvailable() throws Exception { - when(onkostarApi.getProcedure(anyInt())).thenReturn(dnpmKlinikAnamneseForm); + var excelForm = new Procedure(this.onkostarApi); + excelForm.setId(111); + excelForm.setPatientId(123); + excelForm.setValue("refdnpmklinikanamnese", new Item("refdnpmklinikanamnese", 2)); - this.service.applyConsent(excelForm); + var dnpmKlinikAnamneseForm = new Procedure(this.onkostarApi); + dnpmKlinikAnamneseForm.setId(2); + dnpmKlinikAnamneseForm.setPatientId(123); - verify(onkostarApi, times(0)).saveProcedure(any(Procedure.class), anyBoolean()); - } + when(onkostarApi.getProcedure(anyInt())).thenReturn(dnpmKlinikAnamneseForm); - @Test - void testShouldSkipUpdateRelatedDnpmKlinikAnamneseFormIfNoConsentDateAvailable() throws Exception { + this.service.applyConsent(excelForm); - var consentSubForm = new Procedure(this.onkostarApi); - consentSubForm.setId(1); - consentSubForm.setPatientId(123); - consentSubForm.setValue("status", new Item("status", "accepted")); + verify(onkostarApi, times(0)).saveProcedure(any(Procedure.class), anyBoolean()); + } + @Test + void testShouldSkipUpdateRelatedDnpmKlinikAnamneseFormIfNoConsentDateAvailable() + throws Exception { - var excelForm = new Procedure(this.onkostarApi); - excelForm.setId(111); - excelForm.setPatientId(123); - excelForm.setValue("refdnpmklinikanamnese", new Item("refdnpmklinikanamnese", 2)); - excelForm.addSubProcedure("ufdnpmconsent", consentSubForm); + var consentSubForm = new Procedure(this.onkostarApi); + consentSubForm.setId(1); + consentSubForm.setPatientId(123); + consentSubForm.setValue("status", new Item("status", "accepted")); - var dnpmKlinikAnamneseForm = new Procedure(this.onkostarApi); - dnpmKlinikAnamneseForm.setId(2); - dnpmKlinikAnamneseForm.setPatientId(123); + var excelForm = new Procedure(this.onkostarApi); + excelForm.setId(111); + excelForm.setPatientId(123); + excelForm.setValue("refdnpmklinikanamnese", new Item("refdnpmklinikanamnese", 2)); + excelForm.addSubProcedure("ufdnpmconsent", consentSubForm); - when(onkostarApi.getProcedure(anyInt())).thenReturn(dnpmKlinikAnamneseForm); + var dnpmKlinikAnamneseForm = new Procedure(this.onkostarApi); + dnpmKlinikAnamneseForm.setId(2); + dnpmKlinikAnamneseForm.setPatientId(123); - this.service.applyConsent(excelForm); + when(onkostarApi.getProcedure(anyInt())).thenReturn(dnpmKlinikAnamneseForm); - verify(onkostarApi, times(0)).saveProcedure(any(Procedure.class), anyBoolean()); - } + this.service.applyConsent(excelForm); - @Test - void testShouldSkipUpdateRelatedDnpmKlinikAnamneseFormIfNoConsentValueAvailable() throws Exception { + verify(onkostarApi, times(0)).saveProcedure(any(Procedure.class), anyBoolean()); + } - var consentSubForm = new Procedure(this.onkostarApi); - consentSubForm.setId(1); - consentSubForm.setPatientId(123); - consentSubForm.setStartDate(Date.from(Instant.parse("2023-04-03T12:00:00Z"))); - consentSubForm.setValue("datum", new Item("datum", Date.from(Instant.parse("2023-04-03T12:00:00Z")))); + @Test + void testShouldSkipUpdateRelatedDnpmKlinikAnamneseFormIfNoConsentValueAvailable() + throws Exception { - var excelForm = new Procedure(this.onkostarApi); - excelForm.setId(111); - excelForm.setPatientId(123); - excelForm.setValue("refdnpmklinikanamnese", new Item("refdnpmklinikanamnese", 2)); - excelForm.addSubProcedure("ufdnpmconsent", consentSubForm); + var consentSubForm = new Procedure(this.onkostarApi); + consentSubForm.setId(1); + consentSubForm.setPatientId(123); + consentSubForm.setStartDate(Date.from(Instant.parse("2023-04-03T12:00:00Z"))); + consentSubForm.setValue( + "datum", new Item("datum", Date.from(Instant.parse("2023-04-03T12:00:00Z")))); - var dnpmKlinikAnamneseForm = new Procedure(this.onkostarApi); - dnpmKlinikAnamneseForm.setId(2); - dnpmKlinikAnamneseForm.setPatientId(123); + var excelForm = new Procedure(this.onkostarApi); + excelForm.setId(111); + excelForm.setPatientId(123); + excelForm.setValue("refdnpmklinikanamnese", new Item("refdnpmklinikanamnese", 2)); + excelForm.addSubProcedure("ufdnpmconsent", consentSubForm); - when(onkostarApi.getProcedure(anyInt())).thenReturn(dnpmKlinikAnamneseForm); + var dnpmKlinikAnamneseForm = new Procedure(this.onkostarApi); + dnpmKlinikAnamneseForm.setId(2); + dnpmKlinikAnamneseForm.setPatientId(123); - this.service.applyConsent(excelForm); + when(onkostarApi.getProcedure(anyInt())).thenReturn(dnpmKlinikAnamneseForm); - verify(onkostarApi, times(0)).saveProcedure(any(Procedure.class), anyBoolean()); - } + this.service.applyConsent(excelForm); - @Test - void testShouldUpdateRelatedDnpmKlinikAnamneseFormOnFormSave() throws Exception { + verify(onkostarApi, times(0)).saveProcedure(any(Procedure.class), anyBoolean()); + } - var consentSubForm = new Procedure(this.onkostarApi); - consentSubForm.setId(1); - consentSubForm.setPatientId(123); - consentSubForm.setStartDate(Date.from(Instant.parse("2023-04-03T12:00:00Z"))); - consentSubForm.setValue("datum", new Item("datum", Date.from(Instant.parse("2023-04-03T12:00:00Z")))); - consentSubForm.setValue("status", new Item("status", "accepted")); + @Test + void testShouldUpdateRelatedDnpmKlinikAnamneseFormOnFormSave() throws Exception { - var excelForm = new Procedure(this.onkostarApi); - excelForm.setId(111); - excelForm.setPatientId(123); - excelForm.setValue("refdnpmklinikanamnese", new Item("refdnpmklinikanamnese", 2)); - excelForm.addSubProcedure("ufdnpmconsent", consentSubForm); + var consentSubForm = new Procedure(this.onkostarApi); + consentSubForm.setId(1); + consentSubForm.setPatientId(123); + consentSubForm.setStartDate(Date.from(Instant.parse("2023-04-03T12:00:00Z"))); + consentSubForm.setValue( + "datum", new Item("datum", Date.from(Instant.parse("2023-04-03T12:00:00Z")))); + consentSubForm.setValue("status", new Item("status", "accepted")); - var dnpmKlinikAnamneseForm = new Procedure(this.onkostarApi); - dnpmKlinikAnamneseForm.setId(2); - dnpmKlinikAnamneseForm.setPatientId(123); + var excelForm = new Procedure(this.onkostarApi); + excelForm.setId(111); + excelForm.setPatientId(123); + excelForm.setValue("refdnpmklinikanamnese", new Item("refdnpmklinikanamnese", 2)); + excelForm.addSubProcedure("ufdnpmconsent", consentSubForm); - when(onkostarApi.getProcedure(anyInt())).thenReturn(dnpmKlinikAnamneseForm); + var dnpmKlinikAnamneseForm = new Procedure(this.onkostarApi); + dnpmKlinikAnamneseForm.setId(2); + dnpmKlinikAnamneseForm.setPatientId(123); - this.service.applyConsent(excelForm); + when(onkostarApi.getProcedure(anyInt())).thenReturn(dnpmKlinikAnamneseForm); - var argumentCaptor = ArgumentCaptor.forClass(Procedure.class); - verify(onkostarApi, times(1)).saveProcedure(argumentCaptor.capture(), anyBoolean()); + this.service.applyConsent(excelForm); - var savedForm = argumentCaptor.getValue(); - assertThat(savedForm).isExactlyInstanceOf(Procedure.class); - assertThat(savedForm.getValue("ConsentStatusEinwilligungDNPM").getString()).isEqualTo("accepted"); - assertThat(savedForm.getValue("ConsentDatumEinwilligungDNPM").getDate()).isEqualTo("2023-04-03T12:00:00Z"); - } + var argumentCaptor = ArgumentCaptor.forClass(Procedure.class); + verify(onkostarApi, times(1)).saveProcedure(argumentCaptor.capture(), anyBoolean()); + var savedForm = argumentCaptor.getValue(); + assertThat(savedForm).isExactlyInstanceOf(Procedure.class); + assertThat(savedForm.getValue("ConsentStatusEinwilligungDNPM").getString()) + .isEqualTo("accepted"); + assertThat(savedForm.getValue("ConsentDatumEinwilligungDNPM").getDate()) + .isEqualTo("2023-04-03T12:00:00Z"); + } } -- cgit v1.2.3