Skip to content

Commit

Permalink
Refactor test assertions for better readability
Browse files Browse the repository at this point in the history
Replaced indexing with `getFirst()` method to improve readability and avoid potential IndexOutOfBoundsExceptions. Fixed an incorrect test case in `AaaregUtilityTest` by correcting the expected result in the CSV source.
  • Loading branch information
krharum committed Oct 25, 2024
1 parent 94aa505 commit 2bc7711
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import no.nav.dolly.bestilling.aareg.domain.ArbeidsforholdRespons;
import no.nav.dolly.elastic.BestillingElasticRepository;
import no.nav.testnav.libs.dto.aareg.v1.Arbeidsforhold;
import no.nav.testnav.libs.dto.aareg.v1.OrdinaerArbeidsavtale;
import no.nav.testnav.libs.dto.aareg.v1.Organisasjon;
Expand All @@ -17,7 +16,6 @@
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.cloud.contract.wiremock.AutoConfigureWireMock;
import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit.jupiter.SpringExtension;
Expand Down Expand Up @@ -59,12 +57,6 @@ class AaregConsumerTest {
@MockBean
private TokenExchange tokenService;

@MockBean
private BestillingElasticRepository bestillingElasticRepository;

@MockBean
private ElasticsearchOperations elasticsearchOperations;

private Arbeidsforhold opprettRequest;

private ArbeidsforholdRespons arbeidsforholdRespons;
Expand Down Expand Up @@ -106,8 +98,8 @@ void opprettArbeidsforhold() throws JsonProcessingException {
.collectList()
.block();

assertThat(response.get(0).getArbeidsforholdId(), is(equalTo("1")));
assertThat(response.get(0).getMiljo(), is(equalTo(MILJOE)));
assertThat(response.getFirst().getArbeidsforholdId(), is(equalTo("1")));
assertThat(response.getFirst().getMiljo(), is(equalTo(MILJOE)));
}

@Test
Expand All @@ -119,8 +111,8 @@ void oppdaterArbeidsforhold() throws JsonProcessingException {
.collectList()
.block();

assertThat(response.get(0).getArbeidsforholdId(), is(equalTo("1")));
assertThat(response.get(0).getMiljo(), is(equalTo(MILJOE)));
assertThat(response.getFirst().getArbeidsforholdId(), is(equalTo("1")));
assertThat(response.getFirst().getMiljo(), is(equalTo(MILJOE)));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ private static Arbeidsforhold getArbeidsforhold(String arbeidsforholdId, Boolean
@CsvSource({ "1, false, 1, 0, 1",
"1, true, 1, 1, 0",
"2, false, 1, 0, 1",
"2, true, 1, 1, 0" })
"2, true, 1, 0, 1" })
void arbeidsforholdEksistens_eksisterIkke(String reqArbForholdId, Boolean isOppdatering, String respArbForholdId,
int antallEksisterende, int antallNye) {

Expand Down

0 comments on commit 2bc7711

Please sign in to comment.