1
0
mirror of https://github.com/pcvolkmer/mv64e-onkostar-data.git synced 2025-07-02 02:22:54 +00:00

test: cleanup test code

This commit is contained in:
2025-06-20 22:56:27 +02:00
parent dd67d86d31
commit 60ff180973
3 changed files with 5 additions and 36 deletions

View File

@ -1,6 +1,5 @@
package dev.pcvolkmer.onco.datamapper;
import dev.pcvolkmer.mv64e.mtb.Mtb;
import dev.pcvolkmer.onco.datamapper.exceptions.DataAccessException;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@ -8,16 +7,11 @@ import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import javax.sql.DataSource;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.doAnswer;
@ExtendWith(MockitoExtension.class)
class MtbDataMapperTest {
@ -37,34 +31,10 @@ class MtbDataMapperTest {
assertThat(MtbDataMapper.create(dataSource)).isNotNull();
}
@Test
void shouldUseKpaProcedureId() {
doAnswer(invocationOnMock -> List.of(1))
.when(jdbcTemplate)
.query(anyString(), any(RowMapper.class), anyString());
var actual = this.mtbDataMapper.getByCaseId("16000123");
assertThat(actual).isInstanceOf(Mtb.class);
}
@Test
void shouldThrowExceptionIfNoKpaProcedureFound() {
var ex = assertThrows(DataAccessException.class, () -> {
this.mtbDataMapper.getByCaseId("16000123");
});
var ex = assertThrows(DataAccessException.class, () -> this.mtbDataMapper.getByCaseId("16000123"));
assertThat(ex).hasMessage("No record found for case: 16000123");
}
@Test
void shouldThrowExceptionIfMultipleKpaProceduresFound() {
doAnswer(invocationOnMock -> List.of(1, 2))
.when(jdbcTemplate)
.query(anyString(), any(RowMapper.class), anyString());
var ex = assertThrows(DataAccessException.class, () -> {
this.mtbDataMapper.getByCaseId("16000123");
});
assertThat(ex).hasMessage("Multiple records found for case: 16000123");
}
}

View File

@ -41,7 +41,7 @@ class PatientDataMapperTest {
}
@Test
void shouldCreatePatientAlive(@Mock Map<String, Object> resultSet) throws SQLException {
void shouldCreatePatientAlive(@Mock Map<String, Object> resultSet) {
var testData = Map.of(
"id", "1",
"geschlecht", "M",
@ -69,7 +69,7 @@ class PatientDataMapperTest {
}
@Test
void shouldCreatePatientDead(@Mock Map<String, Object> resultSet) throws SQLException {
void shouldCreatePatientDead(@Mock Map<String, Object> resultSet) {
var testData = Map.of(
"id", "1",
"geschlecht", "M",

View File

@ -7,14 +7,13 @@ import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import java.sql.ResultSet;
import java.util.List;
import java.util.Map;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.verify;