SSM开发笔记2-3验证SSM配置-验证Service

       service的验证和dao的验证类似,不过需要注意的是,当我们在测试类中编写service的测试类的时候,需要在基类中引入spring-service的配置,不然系统会报错service没有注入
@ContextConfiguration({“classpath:spring/spring-dao.xml”, “classpath:spring/spring-service.xml”})

       

AreaService.java

package com.imooc.o2o.service;

import java.io.IOException;
import java.util.List;

import com.imooc.o2o.entity.Area;

public interface AreaService {

	List<Area> getAreaList();

}

AreaServiceImpl.java

package com.imooc.o2o.service.impl;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.imooc.o2o.dao.AreaDao;
import com.imooc.o2o.entity.Area;
import com.imooc.o2o.service.AreaService;

@Service
public class AreaServiceImpl implements AreaService {

	@Autowired
	private AreaDao areaDao;
	
	@Override
	public List<Area> getAreaList(){
		return areaDao.queryArea();
	}

	
}

AreaServiceTest.java

package com.imooc.o2o.service;

import static org.junit.Assert.assertEquals;

import java.util.List;

import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;

import com.imooc.o2o.BaseTest;
import com.imooc.o2o.entity.Area;

public class AreaServiceTest extends BaseTest{
	
	@Autowired
	private AreaService areaService;
	
	@Test
	public void testGetAreaList() {
		List<Area> areaList = areaService.getAreaList();
		assertEquals("西苑", areaList.get(1).getAreaName());
	}

}

发布了24 篇原创文章 · 获赞 1 · 访问量 527

猜你喜欢

转载自blog.csdn.net/Kasey_L/article/details/104929935
今日推荐