Skip to content

Commit

Permalink
#1012: remove findX test (already covered by PersistenceBase tests)
Browse files Browse the repository at this point in the history
  • Loading branch information
clean-coder committed Oct 1, 2024
1 parent 1c9e98f commit a7908c4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ protected UserTeamPersistenceService(UserTeamRepository repository) {
super(repository);
}

// TODO implement Test
public void delete(UserTeam userTeam) {
getRepository().delete(userTeam);
}

// TODO implement Test
public void deleteAll(List<UserTeam> userTeamList) {
getRepository().deleteAll(userTeamList);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,13 @@
import ch.puzzle.okr.models.User;
import ch.puzzle.okr.multitenancy.TenantContext;
import ch.puzzle.okr.test.SpringIntegrationTest;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.server.ResponseStatusException;

import java.util.List;

import static org.junit.jupiter.api.Assertions.*;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;

@SpringIntegrationTest
class UserPersistenceServiceIT {
Expand All @@ -39,41 +35,6 @@ void tearDown() {
TenantContext.setCurrentTenant(null);
}

@Test
void shouldReturnAllUsersCorrect() throws ResponseStatusException {
List<User> userList = userPersistenceService.findAll();

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

@Test
void shouldReturnSingleUserWhenFindingOwnerByValidId() {
User returnedUser = userPersistenceService.findById(1L);

assertEquals(1L, returnedUser.getId());
assertEquals("Paco", returnedUser.getFirstname());
assertEquals("Eggimann", returnedUser.getLastname());
assertEquals("[email protected]", returnedUser.getEmail());
}

@Test
void shouldThrowExceptionWhenFindingOwnerNotFound() {
ResponseStatusException exception = assertThrows(ResponseStatusException.class,
() -> userPersistenceService.findById(321L));

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

@Test
void shouldThrowExceptionWhenFindingOwnerWithNullId() {
ResponseStatusException exception = assertThrows(ResponseStatusException.class,
() -> userPersistenceService.findById(null));

assertEquals(HttpStatus.BAD_REQUEST, exception.getStatusCode());
assertEquals("ATTRIBUTE_NULL", exception.getReason());
}

@Test
void getOrCreateUserShouldReturnSingleUserWhenUserFound() {
User existingUser = User.Builder.builder().withEmail(EMAIL_ALICE).build();
Expand All @@ -88,8 +49,12 @@ void getOrCreateUserShouldReturnSingleUserWhenUserFound() {

@Test
void getOrCreateUserShouldReturnSavedUserWhenUserNotFound() {
User newUser = User.Builder.builder().withId(null).withFirstname("firstname").withLastname("lastname")
.withEmail("[email protected]").build();
User newUser = User.Builder.builder() //
.withId(null) //
.withFirstname("firstname") //
.withLastname("lastname") //
.withEmail("[email protected]") //
.build();

createdUser = userPersistenceService.getOrCreateUser(newUser);

Expand Down

0 comments on commit a7908c4

Please sign in to comment.