第四讲 service接口的实现
2019-09-29 本文已影响0人
张三爱的歌
package com.example.demo.service.Impl;
import com.example.demo.dataobject.ProductCategory;
import org.junit.Assert;
import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import java.util.Arrays;
import java.util.List;
import static org.junit.jupiter.api.Assertions.*;
@RunWith(SpringRunner.class)
@SpringBootTest
class CategoryServiceImplTest {
@Autowired
private CategoryServiceImpl categoryService;
@Test
void findOne() throws Exception{
ProductCategory productCategory= categoryService.findOne(1);
Assert.assertEquals(new Integer(1), productCategory.getCategoryId());
}
@Test
void findAll() {
List<ProductCategory> list= categoryService.findAll();
Assert.assertNotEquals(0, list.size());
}
@Test
void findByCategoryTypeIn() {
List<ProductCategory> productCategoryList= categoryService.findByCategoryTypeIn(Arrays.asList(0,3));
Assert.assertNotEquals(0, productCategoryList.size());
}
@Test
void save() {
ProductCategory productCategory=new ProductCategory("男生专享受",10);
categoryService.save(productCategory);
}
}