Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
clean-coder committed Oct 1, 2024
1 parent f666f28 commit f9046c5
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ void tearDown() {
TenantContext.setCurrentTenant(null);
}

@DisplayName("findById() should return single entity if entity with id exists")
@Test
void findByIdShouldReturnSingleEntityIfEntityWithIdExists() {
User foundUser = persistenceBase.findById(ID_USER_PACO);
Expand All @@ -64,15 +65,17 @@ void findByIdShouldReturnSingleEntityIfEntityWithIdExists() {
assertUser("Paco", "Eggimann", "[email protected]", foundUser);
}

@DisplayName("findById() should throw exception if entity with id does not exists")
@Test
void findByIdShouldThrowExceptionIfEntityWithIdDoesNotExist() {
void findByIdShouldThrowExceptionIfEntityWithIdDoesNotExists() {
ResponseStatusException exception = assertThrows(ResponseStatusException.class,
() -> persistenceBase.findById(321L));

assertEquals(NOT_FOUND, exception.getStatusCode());
assertErrorKey("MODEL_WITH_ID_NOT_FOUND", exception);
}

@DisplayName("findById() should throw exception if id is null")
@Test
void findByIdShouldThrowExceptionIfIdIsNull() {
ResponseStatusException exception = assertThrows(ResponseStatusException.class,
Expand All @@ -82,13 +85,15 @@ void findByIdShouldThrowExceptionIfIdIsNull() {
assertErrorKey("ATTRIBUTE_NULL", exception);
}

@DisplayName("findAll() should return all entities as list")
@Test
void findAllShouldReturnAllEntitiesAsList() throws ResponseStatusException {
List<User> userList = persistenceBase.findAll();

assertThat(userList.size()).isGreaterThanOrEqualTo(7);
}

@DisplayName("save() should add new entity")
@Test
void saveShouldAddNewEntity() throws ResponseStatusException {
createdUser = persistenceBase.save(USER_WITHOUT_CONSTRAINTS);
Expand All @@ -97,6 +102,7 @@ void saveShouldAddNewEntity() throws ResponseStatusException {
assertUser("Hans", "Muster", "[email protected]", createdUser);
}

@DisplayName("save() existing entity with different data should update existing entity")
@Test
void saveExistingEntityWithDifferentDataShouldUpdateExistingEntity() throws ResponseStatusException {
// arrange
Expand All @@ -114,6 +120,7 @@ void saveExistingEntityWithDifferentDataShouldUpdateExistingEntity() throws Resp
assertEquals("Pekka", foundUser.getFirstname());
}

@DisplayName("deleteById() should delete entity")
@Test
void deleteByIdShouldDeleteEntity() throws ResponseStatusException {
// arrange
Expand Down

0 comments on commit f9046c5

Please sign in to comment.