Skip to content

Commit

Permalink
Merge pull request #413 from it-at-m/405-falsche-exception-wird-geworfen
Browse files Browse the repository at this point in the history
fix bug throw correct exception
  • Loading branch information
vjohnslhm authored Sep 18, 2024
2 parents f61f68c + 7f1b6e8 commit b74ca56
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public void postWahlen(final WahlenWriteModel wahlenWriteModel) {
wahlRepository.saveAll(wahlModelMapper.fromListOfWahlModeltoListOfWahlEntities(wahlenWriteModel.wahlen()));
} catch (Exception e) {
log.error("#postWahlen: Die Wahlen konnten aufgrund eines Fehlers nicht gespeichert werden:", e);
throw exceptionFactory.createFachlicheWlsException(ExceptionConstants.POSTWAHLEN_UNSAVEABLE);
throw exceptionFactory.createTechnischeWlsException(ExceptionConstants.POSTWAHLEN_UNSAVEABLE);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,14 @@ void accessDeniedWhenServiceAuthorityIsMissing() {
}

@Test
void fachlicheWlsExceptionWhenRepoAuthorityIsMissing() {
void technischeWlsExceptionWhenRepoAuthorityIsMissing() {
SecurityUtils.runWith(Authorities.SERVICE_POST_WAHLEN);
val wahltagID = "wahltagID";
List<WahlModel> mockedListOfModels = createWahlModels();
val wahlenToWrite = new WahlenWriteModel(wahltagID, mockedListOfModels);

Assertions.assertThatThrownBy(() -> wahlenService.postWahlen(wahlenToWrite)).isInstanceOf(
FachlicheWlsException.class);
TechnischeWlsException.class);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import de.muenchen.oss.wahllokalsystem.basisdatenservice.exception.ExceptionConstants;
import de.muenchen.oss.wahllokalsystem.basisdatenservice.services.wahltag.WahltagModel;
import de.muenchen.oss.wahllokalsystem.basisdatenservice.services.wahltag.WahltageService;
import de.muenchen.oss.wahllokalsystem.wls.common.exception.FachlicheWlsException;
import de.muenchen.oss.wahllokalsystem.wls.common.exception.TechnischeWlsException;
import de.muenchen.oss.wahllokalsystem.wls.common.exception.util.ExceptionFactory;
import java.time.LocalDate;
import java.util.ArrayList;
Expand Down Expand Up @@ -116,11 +116,11 @@ void wlsExceptionWhenSavingFailed() {
val wahlenToWrite = new WahlenWriteModel(wahltagID, mockedListOfModels);

val mockedRepoSaveException = new RuntimeException("saving failed");
val mockedWlsException = FachlicheWlsException.withCode("").buildWithMessage("");
val mockedWlsException = TechnischeWlsException.withCode("").buildWithMessage("");

Mockito.when(wahlModelMapper.fromListOfWahlModeltoListOfWahlEntities(mockedListOfModels)).thenReturn(mockedListOfEntities);
Mockito.doThrow(mockedRepoSaveException).when(wahlRepository).saveAll(mockedListOfEntities);
Mockito.when(exceptionFactory.createFachlicheWlsException(ExceptionConstants.POSTWAHLEN_UNSAVEABLE))
Mockito.when(exceptionFactory.createTechnischeWlsException(ExceptionConstants.POSTWAHLEN_UNSAVEABLE))
.thenReturn(mockedWlsException);

Assertions.assertThatThrownBy(() -> unitUnderTest.postWahlen(wahlenToWrite)).isSameAs(mockedWlsException);
Expand Down

0 comments on commit b74ca56

Please sign in to comment.