Skip to content

Commit

Permalink
Add target law service test
Browse files Browse the repository at this point in the history
RISDEV-0000
  • Loading branch information
VictorDelCampo committed Mar 5, 2024
1 parent 86eb43a commit 9b202e2
Showing 1 changed file with 65 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package de.bund.digitalservice.ris.norms.application.service;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.argThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import de.bund.digitalservice.ris.norms.application.port.input.LoadTargetLawUseCase;
import de.bund.digitalservice.ris.norms.application.port.input.LoadTargetLawXmlUseCase;
import de.bund.digitalservice.ris.norms.application.port.output.LoadTargetLawPort;
import de.bund.digitalservice.ris.norms.application.port.output.LoadTargetLawXmlPort;
import de.bund.digitalservice.ris.norms.domain.entity.TargetLaw;
import java.util.Optional;
import org.junit.jupiter.api.Test;

class TargetLawServiceTest {

final LoadTargetLawPort loadTargetLawAdapter = mock(LoadTargetLawPort.class);
final LoadTargetLawXmlPort loadTargetLawXmlAdapter = mock(LoadTargetLawXmlPort.class);

final TargetLawService service =
new TargetLawService(loadTargetLawAdapter, loadTargetLawXmlAdapter);

@Test
void canLoadTargetLawByEli() {
// Given
final String eli = "someEli";
final LoadTargetLawUseCase.Query query = new LoadTargetLawUseCase.Query(eli);

final String title = "Target Law Title";
final String xml = "<targetLaw>Test target law</targetLaw>";
final TargetLaw targetLaw = TargetLaw.builder().eli(eli).title(title).xml(xml).build();

when(loadTargetLawAdapter.loadTargetLawByEli(any())).thenReturn(Optional.of(targetLaw));

// When
final Optional<TargetLaw> loadedTargetLaw = service.loadTargetLaw(query);

// Then
assertThat(loadedTargetLaw).isPresent().contains(targetLaw);
verify(loadTargetLawAdapter, times(1))
.loadTargetLawByEli(argThat(command -> command.eli().equals(eli)));
}

@Test
void canLoadTargetLawXmlByEli() {
// Given
final String eli = "someEli";
final LoadTargetLawXmlUseCase.Query query = new LoadTargetLawXmlUseCase.Query(eli);

final String xmlContent = "<targetLaw>Test content</targetLaw>";
when(loadTargetLawXmlAdapter.loadTargetLawXmlByEli(any())).thenReturn(Optional.of(xmlContent));

// When
final Optional<String> loadedXml = service.loadTargetLawXml(query);

// Then
assertThat(loadedXml).isPresent().contains(xmlContent);
verify(loadTargetLawXmlAdapter, times(1))
.loadTargetLawXmlByEli(argThat(command -> command.eli().equals(eli)));
}
}

0 comments on commit 9b202e2

Please sign in to comment.