我已经编写了一个FeignClient,我想使用单元测试来测试它是否有效。(就我而言,集成测试不是当前开发阶段的正确方法)。
在我的测试中,FeignClient 未初始化 ( null):NullPointerException运行测试时我收到一条消息。
如何成功自动装配 a FeignClient?
假冒客户:
package com.myapp.clients;
import com.myapp.model.StatusResponse;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@FeignClient(name="myClient", url="${feign.clients.my.url}")
public interface myClient {
@RequestMapping(method= RequestMethod.GET, value="/v1/users/{userId}")
StatusResponse getStatus(
@RequestHeader(value = "Auth", required = true) String authorizationHeader,
@RequestHeader(value = "my_tid", required = true) String tid,
@PathVariable("userId") String userId);
}
Run Code Online (Sandbox Code Playgroud)
测试:
package com.myapp.clients;
import com.intuit.secfraudshared.step.broker.model.StatusResponse;
import org.junit.Assert;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
public class MyClientTest {
@Autowired
MyClient myClient; …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用递归初始化二叉树。
@tailrec
def expressionToTreeNodeConversion(expression:String): TreeNode = {
var chars = expression.toCharArray
var operatorIndex = findIndexOfMiddleOperator(chars)
var isOperator = true
while(operatorIndex==(-1) & isOperator) {
if (!(chars.contains(OPEN_BRACKET_CHAR) | chars.contains(CLOSE_BRACKET_CHAR)))
isOperator = false
else {
chars = chars.slice(1, chars.length-1)
operatorIndex = findIndexOfMiddleOperator(chars)
}
}
//If this is an operand
if (!isOperator)
return new OperandNode(chars.mkString(""))
//If this is an operator, recursively call for sub nodes
val node = chars(operatorIndex).toString match {
case AND => new AndNode()
case OR => new OrNode()
}
node.left = …Run Code Online (Sandbox Code Playgroud)