为什么使用时缓存会被值填满
@Autowired
ServiceXY serviceXY
@TestConfiguration
static class AppDefCachingTestConfiguration {
@Bean
public ServiceXY ServiceXYMock() {
return mock(ServiceXY.class);
}
}
Run Code Online (Sandbox Code Playgroud)
但不与
@MockBean
ServiceXY serviceXY
Run Code Online (Sandbox Code Playgroud)
使用 @MockBean 时,在访问缓存值时会出现 NullPointerException,如我的测试中所示:
@Autowired
ConcurrentMapCacheManager cmcm;
@Test
void anTest(){
when(serviceXY.methodThatFillsCache(anyString()).thenReturn("ABC");
serviceXY.methodThatFillsCache("TEST1");
cmcm.getCache("Cachename").get("TEST1",String.class).equals("ABC");
...
}
Run Code Online (Sandbox Code Playgroud) mockito spring-bean spring-boot spring-cache spring-boot-test
public void createNewUser(String name, String passwort) {
try {
br = new BufferedReader(new FileReader("Data.txt"));
} catch (FileNotFoundException brCreateError) {
brCreateError.printStackTrace();
}
try {
br.mark(1);
System.out.println(br.readLine());
try {
if(br.readLine()==null) {
noUser=true;
}else {
noUser=false;
}
} catch (IOException e) {
e.printStackTrace();
}
br.reset();
} catch (IOException brMarkError) {
brMarkError.printStackTrace();
} ...
Run Code Online (Sandbox Code Playgroud)
为什么通过 if 语句后,markedChar 值会变为 -2?
谢谢尼科的每一个回答。
ioexception ×1
java ×1
markers ×1
mockito ×1
reset ×1
spring-bean ×1
spring-boot ×1
spring-cache ×1