我正在用redis缓存实现spring启动应用程序。我正在寻找有关如何为缓存实现编写junit测试用例的输入。下面是示例代码。
代码参照链接:https://www.programmersought.com/article/70971116182/
class UserServiceImpl{
...
@Cacheable(value = "usercache",keyGenerator = "wiselyKeyGenerator", unless="#result==null")
public Object findUser(){
//business logic
...
//return the value
}
@Cacheable(value = "usercache",keyGenerator = "wiselyKeyGenerator")
public User findUser(Long id,String firstName,String lastName){
System.out.println("Call here when there is no cache");
return new User(id,firstName,lastName);
}
}
缓存的示例代码(keygenerator)
@Bean
public KeyGenerator wiselyKeyGenerator(){
return new KeyGenerator() {
@Override
public Object generate(Object target, Method method, Object... params) {
StringBuilder sb = new StringBuilder();
sb.append(target.getClass().getName());
sb.append(method.getName());
for (Object obj : params) {
sb.append(obj.toString());
}
return sb.toString();
}
};
}
关于如何使用junitjupiter为上面的userserviceinpl编写junit测试用例,有什么建议吗?
暂无答案!
目前还没有任何答案,快来回答吧!