我是mockito的新手,正在尝试测试一个场景,其中我将响应头设置为空,返回类型为void。我曾试图实现测试用例,但未能找到编写单元测试用例的逻辑
class App{
private String cookieName=""
public void removeTokens(ServerHttpRequest request, ServerHttpResponse response) {
if( StringUtils.isEmpty(cookieName)) {
cookieName = Utils.getCookieName(request);
}
String somePath = request.getPath().contextPath().value();
if (StringUtils.isEmpty(somePath)) {
somePath = "/";
}
response.getHeaders().add(HttpHeaders.SET_COOKIE,"","",somePath, cookieDomain,false));
}
公用事业
class Utils{
public string getcookieName{
return "test";
}
不涉及如何实现测试用例。
@ExtendWith({MockitoExtension.class})
@MockitoSettings(strictness = Strictness.LENIENT)
public class AppTest {
final App mockController = Mockito.mock(App.class);
@Test
public void testRevokeAccessToken(){
MockServerHttpRequest mockedRequest = new MockServerHttpRequest();
MockServerHttpResponse mockResponse= new MockServerHttpResponse();
String reqContextPath = mockedRequest .getPath().contextPath().value();
mockResponse.getHeaders().add(HttpHeaders."","",reqContextPath, "",false));
//MockServerHttpRequest mockedRequest1= new MockServerHttpRequest();
mockController.removeTokens(mockedRequest,mockResponse);
暂无答案!
目前还没有任何答案,快来回答吧!