买家类目service

买家类目service接口

main--service--CategoryService.java

package com.tkft.sell.service;

import com.tkft.sell.dataobject.ProductCategory;

import java.util.List;

public interface CategoryService {
    ProductCategory findOne(Integer categoryId);
    List<ProductCategory> findAll();
    List<ProductCategory> findByCategoryTypeIn(List<Integer> categoryTypeList);
    ProductCategory save(ProductCategory productCategory);
}

买家类目service实现

main--service--impl--CategoryServiceImpl.java

package com.tkft.sell.service.impl;

import com.tkft.sell.dataobject.ProductCategory;
import com.tkft.sell.repository.ProductCategoryRepository;
import com.tkft.sell.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CategoryServiceImpl implements CategoryService {

    @Autowired
    private ProductCategoryRepository repository;

    @Override
    public ProductCategory findOne(Integer categoryId) {
        return repository.getOne(categoryId);
    }

    @Override
    public List<ProductCategory> findAll() {
        return repository.findAll();
    }

    @Override
    public List<ProductCategory> findByCategoryTypeIn(List<Integer> categoryTypeList) {
        return repository.findByCategoryTypeIn(categoryTypeList);
    }

    @Override
    public ProductCategory save(ProductCategory productCategory) {
        return repository.save(productCategory);
    }
}

买家类目service测试

test--service.impl--CategoryServiceImplTest.java

package com.tkft.sell.service.impl;

import com.tkft.sell.dataobject.ProductCategory;
import org.junit.Assert;
import org.junit.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.Assert.*;
@RunWith(SpringRunner.class)
@SpringBootTest
public class CategoryServiceImplTest {

    @Autowired
    private CategoryServiceImpl categoryService;
    @Test
    public void findOne() {
        ProductCategory productCategory = categoryService.findOne(1);
        Assert.assertEquals(new Integer(1),productCategory.getCategoryId());
    }

    @Test
    public void findAll() {
        List<ProductCategory> productCategoryList = categoryService.findAll();
        Assert.assertNotEquals(0,productCategoryList.size());
    }

    @Test
    public void findByCategoryTypeIn() {
        List<ProductCategory> productCategoryList = categoryService.findByCategoryTypeIn(Arrays.asList(1,2));
        Assert.assertNotEquals(0, productCategoryList.size());
    }

    @Test
    public void save() {
        ProductCategory productCategory = new ProductCategory("水果",53);
        ProductCategory result = categoryService.save(productCategory);
        Assert.assertNotNull(result);
    }
}
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 135,975评论 19 139
  • 早饭,煎蛋。平锅点入少许油。待油热打入鸡蛋。蛋清变白即可出锅。撒些黑胡椒,番茄酱。关键,别让蛋清煎得时间过长。那样...
    小老郑阅读 2,967评论 2 3
  • 想做一个社区网站,让教育连接起来 ktgtiytiut trhrtruruytreeeeeeeeeeeeeeee ...
    9e0edfd01e9a阅读 1,436评论 0 0
  • 再一次挑战自己 从一个艺术生到摄影行业,再到保险业,再到理财规划师,这一连串的转折,有辛酸,有泪水,更多的是收获,...
    李明Leou阅读 5,834评论 1 1

友情链接更多精彩内容