您的位置:首页 > 游戏 > 手游 > 网站设计制作价钱低_个人简历模板范文手写_国外友链买卖平台_资源平台

网站设计制作价钱低_个人简历模板范文手写_国外友链买卖平台_资源平台

2024/11/14 2:06:48 来源:https://blog.csdn.net/qq398581645/article/details/142649279  浏览:    关键词:网站设计制作价钱低_个人简历模板范文手写_国外友链买卖平台_资源平台
网站设计制作价钱低_个人简历模板范文手写_国外友链买卖平台_资源平台

业务代码

package com.haier.configure.service.impl;import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.haier.common.util.RequestUtil;
import com.haier.configure.entity.LanguageTableDO;
import com.haier.configure.mapper.LanguageTableMapper;
import com.haier.configure.service.LanguageTableService;
import com.haier.configure.util.CheckDataUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;import java.util.List;/*** @author A2001111* @date 2024/4/3010:24*/
@Slf4j
@Service
public class LanguageTableServiceImpl extends ServiceImpl<LanguageTableMapper, LanguageTableDO> implements LanguageTableService {@Overridepublic void test1() {System.out.println("业务1...");String appId = RequestUtil.getAppId();System.out.println("appid:"+appId);System.out.println("第一次调用-----");List<LanguageTableDO> list = this.list(Wrappers.lambdaQuery(LanguageTableDO.class).eq(LanguageTableDO::getId, 1));for (LanguageTableDO languageTableDO : list) {System.out.println("循环结果1:"+languageTableDO.getChineseName());}System.out.println("第二次调用-----");List<LanguageTableDO> list2 = this.list(Wrappers.lambdaQuery(LanguageTableDO.class).eq(LanguageTableDO::getId, 1));for (LanguageTableDO languageTableDO : list2) {System.out.println("循环结果2:"+languageTableDO.getChineseName());}System.out.println("第3次调用-----");List<LanguageTableDO> list3 = this.list(Wrappers.lambdaQuery(LanguageTableDO.class).eq(LanguageTableDO::getId, 1));for (LanguageTableDO languageTableDO : list3) {System.out.println("循环结果3:"+languageTableDO.getChineseName());}System.out.println("业务2...");}}

需要mock静态方法RequestUtil.getAppId(),需要mock成员方法this.list(lambdaQuery);

/*** @author A2001111* @date 2024/9/30 9:07*/
package com.haier.configure.service.impl;import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.haier.common.util.RequestUtil;
import com.haier.configure.entity.LanguageTableDO;
import com.haier.configure.mapper.LanguageTableMapper;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.*;
import org.mockito.junit.jupiter.MockitoSettings;
import org.mockito.quality.Strictness;import java.util.ArrayList;
import java.util.List;import static org.mockito.Mockito.any;
import static org.mockito.Mockito.when;@MockitoSettings(strictness = Strictness.LENIENT)
class LanguageTableServiceImplTest<M extends LanguageTableMapper> {@InjectMocks@Spyprivate LanguageTableServiceImpl languageTableServiceImpl;@Mockprivate M mapper;private AutoCloseable mockitoCloseable;@BeforeEachvoid setUp() throws Exception {mockitoCloseable = MockitoAnnotations.openMocks(this);}@AfterEachvoid tearDown() throws Exception {mockitoCloseable.close();}@Testvoid test_getAllList_should_return_not_null_when_condition() throws Exception {// mock静态MockedStatic<RequestUtil> requestUtilMockedStatic = Mockito.mockStatic(RequestUtil.class);requestUtilMockedStatic.when(RequestUtil::getAppId).thenReturn("假数据哦");// setupLanguageTableDO languageTableDO = new LanguageTableDO();languageTableDO.setId(111L);languageTableDO.setCode("code");languageTableDO.setEnglishName("englishName111");languageTableDO.setChineseName("chineseName111");List<LanguageTableDO> list = new ArrayList<>();list.add(languageTableDO);LanguageTableDO languageTableDO2 = new LanguageTableDO();languageTableDO2.setId(222L);languageTableDO2.setCode("code");languageTableDO2.setEnglishName("englishName222");languageTableDO2.setChineseName("chineseName222");List<LanguageTableDO> list2 = new ArrayList<>();list2.add(languageTableDO2);// when(mapper.selectList(any(LambdaQueryWrapper.class))).thenReturn(list);// 也可以设置多次调用返回不同的结果,比如:第一次返回list,第二次返回list2,后续多次调用,都返回list2when(mapper.selectList(any(LambdaQueryWrapper.class))).thenReturn(list).thenReturn(list2);// run the testlanguageTableServiceImpl.test1();System.out.println("完毕");}}

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com