package com.plannaplan.services; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner; import static org.junit.jupiter.api.Assertions.assertTrue; import com.plannaplan.entities.User; import com.plannaplan.exceptions.UserNotFoundException; import com.plannaplan.types.UserRoles; import org.junit.Before; import org.junit.Test; import org.junit.jupiter.api.TestMethodOrder; import org.junit.jupiter.api.MethodOrderer.OrderAnnotation; import org.junit.runner.RunWith; @RunWith(SpringRunner.class) @SpringBootTest @ContextConfiguration @TestMethodOrder(OrderAnnotation.class) public class UserServiceTest { public static String TEST_USER_MAIL = "noteexisitingmail@notexistingdomain.com"; public static String TEST_USER_NAME = "Tom"; public static String TEST_USER_SUERNAME = "Kovalsky"; @Autowired UserService userService; @Before public void initialize() { User testUser = new User(); testUser.setEmail(TEST_USER_MAIL); testUser.setName(TEST_USER_NAME); testUser.setSurname(TEST_USER_SUERNAME); testUser.setRole(UserRoles.TEST_USER); this.userService.save(testUser); } @Test public void shouldReturnToken() { try { String token = this.userService.login(TEST_USER_MAIL); System.out.println("Returned token: " + token); assertTrue(token != null); } catch (UserNotFoundException e) { e.printStackTrace(); assertTrue(false); } } @Test public void shouldThrowException() { try { this.userService.login("thiseamilisnotindatabase@gmail.com"); assertTrue(false); } catch (UserNotFoundException e) { assertTrue(true); } } }