@BeforeMethod public void setup() { doReturn(new File(TEST_CACHE_FILE)).when(fileResolver).getClassHashCacheFile(); when(prototypesProvider.createSerializer()).thenReturn(serializationManager); }
@Test public void cacheFileExists() throws Exception { when(configurationStorage.isClassCacheExistsOnCmr()).thenReturn(true); new File(TEST_CACHE_FILE).createNewFile(); Object javaRuntimeVersion = UnderlyingSystemInfo.JAVA_RUNTIME_VERSION; Object hashes = Collections.singletonMap("fqn", Collections.singleton("hash")); when(serializationManager.deserialize(Matchers.<Input> any())).thenReturn(javaRuntimeVersion).thenReturn(hashes); helper.afterPropertiesSet(); verify(prototypesProvider, times(1)).createSerializer(); verify(serializationManager, times(2)).deserialize(Matchers.<Input> any()); verify(executorService, times(1)).scheduleAtFixedRate(Matchers.<Runnable> any(), anyLong(), anyLong(), Matchers.<TimeUnit> any()); assertThat(helper.isEmpty(), is(false)); }
@Test public void cacheFileExistsException() throws Exception { when(configurationStorage.isClassCacheExistsOnCmr()).thenReturn(true); new File(TEST_CACHE_FILE).createNewFile(); when(serializationManager.deserialize(Matchers.<Input> any())).thenThrow(new SerializationException()); helper.afterPropertiesSet(); verify(prototypesProvider, times(1)).createSerializer(); verify(executorService, times(1)).scheduleAtFixedRate(Matchers.<Runnable> any(), anyLong(), anyLong(), Matchers.<TimeUnit> any()); assertThat(helper.isEmpty(), is(true)); }
@Test public void noCacheFileExists() throws Exception { when(configurationStorage.isClassCacheExistsOnCmr()).thenReturn(true); helper.afterPropertiesSet(); verify(prototypesProvider, times(1)).createSerializer(); verify(executorService, times(1)).scheduleAtFixedRate(Matchers.<Runnable> any(), anyLong(), anyLong(), Matchers.<TimeUnit> any()); verifyZeroInteractions(serializationManager); assertThat(helper.isEmpty(), is(true)); }
@Test public void cacheFileExistsJavaCached() throws Exception { when(configurationStorage.isClassCacheExistsOnCmr()).thenReturn(true); new File(TEST_CACHE_FILE).createNewFile(); Object javaRuntimeVersion = UnderlyingSystemInfo.JAVA_RUNTIME_VERSION; Object hashes = Collections.singletonMap("java.lang.String", Collections.singleton("hash")); when(serializationManager.deserialize(Matchers.<Input> any())).thenReturn(javaRuntimeVersion).thenReturn(hashes); helper.afterPropertiesSet(); verify(prototypesProvider, times(1)).createSerializer(); verify(serializationManager, times(2)).deserialize(Matchers.<Input> any()); verify(executorService, times(1)).scheduleAtFixedRate(Matchers.<Runnable> any(), anyLong(), anyLong(), Matchers.<TimeUnit> any()); assertThat(helper.isEmpty(), is(false)); }
@Test public void cacheFileExistsJavaNotCached() throws Exception { when(configurationStorage.isClassCacheExistsOnCmr()).thenReturn(true); new File(TEST_CACHE_FILE).createNewFile(); Object javaRuntimeVersion = "some_other_version"; Object hashes = Collections.singletonMap("java.lang.String", Collections.singleton("hash")); when(serializationManager.deserialize(Matchers.<Input> any())).thenReturn(javaRuntimeVersion).thenReturn(hashes); helper.afterPropertiesSet(); verify(prototypesProvider, times(1)).createSerializer(); verify(serializationManager, times(2)).deserialize(Matchers.<Input> any()); verify(executorService, times(1)).scheduleAtFixedRate(Matchers.<Runnable> any(), anyLong(), anyLong(), Matchers.<TimeUnit> any()); assertThat(helper.isEmpty(), is(true)); }
serializationManager = prototypesProvider.createSerializer();