mock 的独立使用
2024-08-22 23:35:44
public class Air21QueryMileStoneJobTest{
@InjectMocks
Air21QueryMileStoneJob air21QueryMileStoneJob ;
@InjectMocks
Air21OrderStatusHandler air21OrderStatusHandler;
@org.mockito.Mock
private LocationDAO locationDAO;
@Before
public void setup() {
locationDAO= new LocationDAO();
air21OrderStatusHandler = new Air21OrderStatusHandler();
air21OrderStatusHandler.setLocationDAO(locationDAO); /*Map<String, String> criteriaMap = new HashMap<String, String>();
criteriaMap.put("location", "AA");
Mockito.when(locationDAO.query(criteriaMap)).thenReturn("GTM+8");*/
MockitoAnnotations.initMocks(this);
} @Test
public void testQueryActionDateTzName() throws Exception { Map<String, String> criteriaMap = new HashMap<String, String>();
criteriaMap.put("location", "AA");
ArrayList<LocationDO> arrayList = new ArrayList<LocationDO>();
LocationDO locationDO = new LocationDO();locationDO.setTimezone("AAAA");
arrayList.add(locationDO);
Mockito.when(locationDAO.query(criteriaMap)).thenReturn(arrayList); // Air21OrderStatusHandler air21OrderStatusHandler = new Air21OrderStatusHandler();
String queryActionDateTz = air21OrderStatusHandler.queryActionDateTz("AA");
System.out.println(queryActionDateTz);
}
元代码:
public class Air21OrderStatusHandler {
/********************************
* 1.convert bean step1 get comment data step2 loop scan_details step3 convert
* data to order_status step4 collect order_status
*
* 2.if status is DDL or DL1 ,update edi_history isOverMileStone="true"
*
* 3.delete old milestone info
*
* 4.save new milestone to orderstatus table
***************************************/
@Autowired
private LocationDAO locationDAO; public String queryActionDateTz(String postLocation) {
LOGGER.info("start get timezone by location");
String fTimeZone = "";
Map<String, String> criteriaMap = new HashMap<String, String>();
criteriaMap.put("location", postLocation);
@SuppressWarnings("unchecked")
List<LocationDO> locationDOlist = (List<LocationDO>) locationDAO.query(criteriaMap);
if (!locationDOlist.isEmpty() && locationDOlist.size() > ) {
fTimeZone = locationDOlist.get().getTimezone();
} else {
fTimeZone = MilestoneConstant.TIME_ZONE;
}
LOGGER.info("end get timezone by location");
LOGGER.info("TimeZone is :{}", fTimeZone);
return fTimeZone;
}
最新文章
- JS判断网页是否在微信中打开/
- 项目中如何GB2312转UTF-8
- EF架构~DefaultValue让我的UnitOfWork更可读
- 聊一下C#开发者如何过渡到JAVA 开发者
- 添加事件及Event对象的兼容写法
- 关于Windows下的文件后缀名问题
- 简单的计算最值的MapReduce程序
- Python 基础语法(三)
- 初识 Asp.Net内置对象之Session对象
- chkconfig用法
- poj 3304(直线与线段相交)
- ubuntu server 12.04 源
- Windwos下 php mysql apache 环境配置
- Fliptile 翻格子游戏
- MTK如何烧录IMEI码(俗称串号)
- vue.js 列表追加项写法
- hdu6396(思维+输入挂)
- 微信小程序-转发
- 洗礼灵魂,修炼python(28)--异常处理(2)—>;运用异常
- Quantum Computation and Quantum Information
热门文章
- Android------个人项目(歆语气象通)
- 最短路径求解(Dijkstra)
- bzoj1143: [CTSC2008]祭祀river 最长反链
- LTE空口协议——是空口3GPP协议 不是网络IP协议
- 【hive】求日期是星期几
- SPOJ COMPANYS Two Famous Companies 最小生成树,二分,思路 难度:2
- 网络编程I/O函数介绍
- Shell 命令行,写一个自动整理 ~/Downloads/ 文件夹下文件的脚本
- “之”字形输出二叉树 python
- angularJS指令动态加载template