首页 > 其他分享 >接口1

接口1

时间:2024-11-11 22:56:58浏览次数:1  
标签:ArrayList request actualResponse 接口 123 import new

import static org.mockito.Mockito.;
import static org.junit.jupiter.api.Assertions.
;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;

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

@ExtendWith(MockitoExtension.class)
public class DepartmentServiceTest {

@Mock
private DepartmentMapper departmentMapper;

@Mock
private UserDepartmentMapper userDepartmentMapper;

@Mock
private DepartmentPermissionMapper permissionMapper;

@Mock
private FinTechDataProviderService finTechDataProviderService;

@Mock
private DepartmentPermissionServiceImpl permissionService;

@Mock
private IndexPatternServiceImpl indexPatternService;

@InjectMocks
private DepartmentServiceImpl departmentService;

@BeforeEach
void setUp() {
    // 初始化 mock 对象和注入的 service
}

@Test
void testAddDepartmentPermission() {
    AddDepartmentPermissionRequest request = new AddDepartmentPermissionRequest();
    request.setDepartmentId("123");
    request.setDepartmentPermissionDTOList(new ArrayList<>());

    AddDepartmentPermissionResponse expectedResponse = new AddDepartmentPermissionResponse();
    when(permissionService.addPermissionForDepartment("123", new ArrayList<>())).thenReturn(true);

    AddDepartmentPermissionResponse actualResponse = departmentService.addDepartmentPermission(request);

    assertNotNull(actualResponse);
    verify(permissionService).addPermissionForDepartment("123", new ArrayList<>());
}

@Test
void testChangeGlobalQuery() {
    ChangeDepartmentGlobalQueryRequest request = new ChangeDepartmentGlobalQueryRequest();
    request.setDepartmentId("123");
    request.setGlobalQuery(true);
    request.setPermanentFlag(true);
    request.setEffectiveDate(new Date());

    ChangeDepartmentGlobalQueryResponse expectedResponse = new ChangeDepartmentGlobalQueryResponse();

    when(departmentMapper.selectByPrimaryKey("123")).thenReturn(null);

    ChangeDepartmentGlobalQueryResponse actualResponse = departmentService.changeGlobalQuery(request);

    assertNotNull(actualResponse);
    verify(departmentMapper).insert(any(Department.class));
}

@Test
void testDeleteDepartmentPermission() {
    DelDepartmentPermissionRequest request = new DelDepartmentPermissionRequest();
    request.setDepartmentId("123");
    request.setIndexPatternNameList(new ArrayList<>());

    DelDepartmentPermissionResponse expectedResponse = new DelDepartmentPermissionResponse();

    when(permissionService.deletePermissionForDepartment("123", new ArrayList<>())).thenReturn(true);

    DelDepartmentPermissionResponse actualResponse = departmentService.deleteDepartmentPermission(request);

    assertNotNull(actualResponse);
    verify(permissionService).deletePermissionForDepartment("123", new ArrayList<>());
}

@Test
void testIsGlobalQuery() {
    QueryDepartmentGlobalQueryRequest request = new QueryDepartmentGlobalQueryRequest();
    request.setDepartmentId("123");

    Department department = new Department();
    department.setDepartmentId("123");
    department.setGlobalQuery(true);
    department.setQueryEffectiveDate(new Date());
    department.setQueryPermanentFlag(true);

    when(departmentMapper.selectByPrimaryKey("123")).thenReturn(department);

    QueryDepartmentGlobalQueryResponse actualResponse = departmentService.isGlobalQuery(request);

    assertNotNull(actualResponse);
    assertTrue(actualResponse.getGlobalQueryFlag());
    assertEquals(new Date(), actualResponse.getEffectiveDate());
    assertTrue(actualResponse.getPermanentFlag());
}

@Test
void testQueryIndexPatternByDepartmentId() {
    QueryDepartmentIndexPatternRequest request = new QueryDepartmentIndexPatternRequest();
    request.setDepartmentId("123");

    List<UserDepartmentIndexPatternItem> indexPatternList = new ArrayList<>();
    when(indexPatternService.getDepartmentIndexPatternByDepartmentId("123")).thenReturn(indexPatternList);

    QueryDepartmentIndexPatternResponse actualResponse = departmentService.queryIndexPatternByDepartmentId(request);

    assertNotNull(actualResponse);
    assertEquals(indexPatternList, actualResponse.getIndexPatternItemList());
}

}

标签:ArrayList,request,actualResponse,接口,123,import,new
From: https://www.cnblogs.com/lmzzr24/p/18540773

相关文章

  • RL 基础 | 如何使用 OpenAI Gym 接口,搭建自定义 RL 环境(详细版)
    参考:官方链接:Gymdocumentation|Makeyourowncustomenvironment腾讯云|OpenAIGym中级教程——环境定制与创建知乎|如何在Gym中注册自定义环境?g,写完了才发现自己曾经写过一篇:RL基础|如何搭建自定义gym环境(这篇博客适用于gym的接口,gymnasium接口也差不......
  • Java Lambda表达式与函数式接口和Stream API的常用方法
    JavaLambda表达式常与函数式接口和流(StreamAPI)一起使用,提供了非常强大的方式来处理集合和其他数据结构。以下是一些常用的Lambda表达式方法和它们的用途,特别是在结合java.util.stream.Stream时:1.map()用途:用于将流中的每个元素转换成另一种形式。示例:List<String>name......
  • Spring学习笔记_30——事务接口PlatformTransactionManager
    PlatformTransactionManager是Spring框架中事务管理的核心接口,它负责管理事务的创建、提交和回滚等操作。源码/**Copyright2002-2020theoriginalauthororauthors.**LicensedundertheApacheLicense,Version2.0(the"License");*youmaynotusethis......
  • API接口精准获取商品详情信息案例
    在当今数字化时代,电子商务平台的蓬勃发展,使得商品信息的获取变得尤为重要。API(ApplicationProgrammingInterface,应用程序编程接口)作为连接前端用户界面与后端服务的桥梁,扮演着至关重要的角色。本文将通过一个实际案例,展示如何利用API接口精准获取商品详情信息,并提供相应的代......
  • 精准获取商品详情信息的API接口
    在这个数字化的时代,购物狂们不再满足于传统的购物方式,他们需要的是一种全新的、快速的、精准的购物体验。而这一切,都离不开一个强大的后盾——API接口。今天,就让我们跟随一位名叫“代码侠”的程序员,一起踏上这场幽默而精准的代码之旅,探索如何通过API接口获取商品详情信息。第......
  • PEF22554HTV3.1 英特尔intel 电信 IC 调帧器,线路接口单元(LIU) P-TQFP-144 在售20000PCS
    PEF22554HTV3.1是一款由英特尔(Intel)生产的电信IC调帧器,它可以与线路接口单元(LIU)一起使用。该调帧器的封装类型是P-TQFP-144。该调帧器适用于电信领域的应用,可以用于实现数据调制和解调功能,常见于传输和接收语音、数据和视频信号的通信设备中。型号:PEF22554HTV3.1类别:集成电路......
  • 发现一肉鸡接口,快来围攻啦~
    系统登录页面,为防止明文传输用户密码,开发者做了安全加固。服务端暴露一个loginEncryptKey的API,用来根据登录名username获取加密秘钥encryptKey。前端页面获取到encryptKey后,在请求login登录接口时,会对用户密码进行加密传输。这个loginEncryptKey接口的服务端怎么......
  • Java——接口
    一、接口是什么在Java中,接口(Interface)是一种引用数据类型,类似于类,然而它只能包含常量、方法签名和嵌套类型。接口不能包含实例变量或方法的实现(在Java8及之后的版本,可以在接口中定义默认方法和静态方法)。接口主要用于定义类的外部行为,并允许类实现这些行为。二、接口详细介......
  • Qualcomm SA8295P资源解析(一):驱动智能驾驶与车载娱乐的多接口技术先锋
    QualcommSA8295P的核心:多核CPU设计QualcommSA8295P的CPU采用了Kryo695架构,其分成了两种不同配置的核心组,分别是KryoGoldPrime和KryoGold核心。KryoGoldPrime核心带有1MB的L2缓存,最高频率可以达到2.38GHz,而KryoGold核心配备512KB的L2缓存,频率最高为2.09GHz。这......
  • Pyhthon实时行情接口WebSocket接入
    Python做量化,如果是日内策略,需要更实时的行情数据,不然策略滑点太大,容易跑偏结果。之前用行情网站提供的level1行情接口,实测平均更新延迟达到了6秒,超过10只股票并发请求频率过快很容易封IP。后面又尝试了买代理IP来请求,成本太高而且不稳定。在Github上看到一个可转债的Golang高频......