spring-boot-realworld-examp.../src/test/java/io/spring/infrastructure/favorite/MyBatisArticleFavoriteRepos...

41 lines
1.7 KiB
Java
Raw Normal View History

2017-08-16 10:51:20 +07:00
package io.spring.infrastructure.favorite;
import io.spring.core.favorite.ArticleFavorite;
import io.spring.core.favorite.ArticleFavoriteRepository;
2017-08-18 16:08:27 +07:00
import io.spring.infrastructure.repository.MyBatisArticleFavoriteRepository;
2017-08-16 10:51:20 +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 static org.hamcrest.CoreMatchers.is;
2017-08-16 14:58:51 +07:00
import static org.hamcrest.CoreMatchers.notNullValue;
2017-08-16 10:51:20 +07:00
import static org.junit.Assert.*;
@RunWith(SpringRunner.class)
@MybatisTest
@Import({MyBatisArticleFavoriteRepository.class})
public class MyBatisArticleFavoriteRepositoryTest {
@Autowired
private ArticleFavoriteRepository articleFavoriteRepository;
@Autowired
2017-08-18 16:08:27 +07:00
private io.spring.infrastructure.mybatis.mapper.ArticleFavoriteMapper articleFavoriteMapper;
2017-08-16 10:51:20 +07:00
@Test
public void should_save_and_fetch_articleFavorite_success() throws Exception {
ArticleFavorite articleFavorite = new ArticleFavorite("123", "456");
articleFavoriteRepository.save(articleFavorite);
2017-08-16 14:58:51 +07:00
assertThat(articleFavoriteMapper.find(articleFavorite.getArticleId(), articleFavorite.getUserId()), notNullValue());
2017-08-16 12:37:10 +07:00
}
@Test
public void should_remove_favorite_success() throws Exception {
ArticleFavorite articleFavorite = new ArticleFavorite("123", "456");
articleFavoriteRepository.save(articleFavorite);
articleFavoriteRepository.remove(articleFavorite);
assertThat(articleFavoriteRepository.find("123", "456").isPresent(), is(false));
2017-08-16 10:51:20 +07:00
}
}