spring-boot-realworld-examp.../src/test/java/io/spring/application/profile/ProfileQueryServiceTest.java

38 lines
1.4 KiB
Java
Raw Normal View History

2017-08-16 14:58:51 +07:00
package io.spring.application.profile;
2017-08-18 16:08:27 +07:00
import io.spring.application.ProfileQueryService;
import io.spring.application.data.ProfileData;
2017-08-16 14:58:51 +07:00
import io.spring.core.user.User;
import io.spring.core.user.UserRepository;
2017-08-18 16:08:27 +07:00
import io.spring.infrastructure.repository.MyBatisUserRepository;
2017-08-16 14:58:51 +07:00
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mybatis.spring.boot.test.autoconfigure.MybatisTest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Import;
import org.springframework.test.context.junit4.SpringRunner;
import java.util.Optional;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.*;
@RunWith(SpringRunner.class)
@MybatisTest
@Import({ProfileQueryService.class, MyBatisUserRepository.class})
public class ProfileQueryServiceTest {
@Autowired
private ProfileQueryService profileQueryService;
@Autowired
private UserRepository userRepository;
@Test
public void should_fetch_profile_success() throws Exception {
User currentUser = new User("a@test.com", "a", "123", "", "");
User profileUser = new User("p@test.com", "p", "123", "", "");
userRepository.save(profileUser);
Optional<ProfileData> optional = profileQueryService.findByUsername(profileUser.getUsername(), currentUser);
assertThat(optional.isPresent(), is(true));
}
}