Am working with Spring Boot, and one of my main methods is as below.
@Autowired
private AerospikeClient asClient;
public String readOTPFromCache(String input) {
Policy policy = new Policy();
JSONObject jsonObject = new JSONObject(input);
Key readKey = new Key(nameserver, otp, jsonObject.getString(PHONENUMBER));
Record record = asClient.get(policy, readKey);
/* No OTP in cache for this phoneNumber */
if (record==null) {
return null;
}
else {
return new JSONObject(record.bins).toString();
}
}
How do I mock the client ? I have seen a couple of discussions on this forum, but couldn’t make out. Any help on this would be greatly appreciated.
Hi,
You have two “client” variables. One inside testAerospike() and the other at the class level. Mockito.when is initializing the one inside testAerospike(). The class level one is not being initialized.