/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.ocelotds.core;

import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import org.junit.Test;
import static org.assertj.core.api.Assertions.*;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.slf4j.Logger;

/**
 *
 * @author hhfrancois
 */
@RunWith(MockitoJUnitRunner.class)
public class UpdatedCacheManagerTest {
	
	private static final long DELAY = 1000;
	
	@Mock
	private Logger logger;

	@InjectMocks
	private UpdatedCacheManager updatedCacheManager;
	/**
	 * Test of receiveCacheRemoveEvent method, of class UpdatedCacheManager.
	 */
	@Test
	public void testGetOutDatedCache() {
		System.out.println("getOutDatedCache");
		String cachekey = UUID.randomUUID().toString();
		Map<String, Long> map = new HashMap<>();
		Date now = new Date();
		map.put(cachekey, now.getTime()-DELAY);
		updatedCacheManager.receiveCacheRemoveEvent(cachekey);
		Collection<String> result = updatedCacheManager.getOutDatedCache(map);
		assertThat(result).isNotNull();
		assertThat(result).contains(cachekey);
		result = updatedCacheManager.getOutDatedCache(null);
		assertThat(result).isNotNull();
		assertThat(result).isEmpty();
	}

	/**
	 * Test of receiveCacheRemoveEvent method, of class UpdatedCacheManager.
	 */
	@Test
	public void testGetNoOutDatedCache() {
		System.out.println("getNoOutDatedCache");
		String cachekey = UUID.randomUUID().toString();
		Map<String, Long> map = new HashMap<>();
		Date now = new Date();
		map.put(cachekey, now.getTime()+DELAY);
		updatedCacheManager.receiveCacheRemoveEvent(cachekey);
		Collection<String> result = updatedCacheManager.getOutDatedCache(map);
		assertThat(result).doesNotContain(cachekey);
	}
}

@@ -864,16 +864,18 @@
 nager;%0D%0A
+%0D%0A
 %09/**%0D%0A%09 
@@ -884,39 +884,32 @@
 Test of 
-receiveCacheRemoveEvent
+getOutDatedCache
  method,
@@ -1149,32 +1149,60 @@
  = new Date();%0D%0A
+%09%09// test key is outofdate%0D%0A
 %09%09map.put(cachek
@@ -1442,94 +1442,485 @@
 ;%0D%0A%09
-%09result = updatedCacheManager.getOutDatedCache(null);%0D%0A%09%09assertThat(result).isNotNull(
+%7D%0D%0A%0D%0A%09/**%0D%0A%09 * Test of getOutDatedCache method, of class UpdatedCacheManager.%0D%0A%09 */%0D%0A%09@Test%0D%0A%09public void testGetNoYetOutDatedCache() %7B%0D%0A%09%09System.out.println(%22getNoYetOutDatedCache%22);%0D%0A%09%09String cachekey = UUID.randomUUID().toString();%0D%0A%09%09Map%3CString, Long%3E map = new HashMap%3C%3E();%0D%0A%09%09Date now = new Date();%0D%0A%09%09map.put(cachekey, now.getTime()+DELAY);%0D%0A%09%09updatedCacheManager.receiveCacheRemoveEvent(cachekey);%0D%0A%09%09Collection%3CString%3E result = updatedCacheManager.getOutDatedCache(map
 );%0D%0A
@@ -1944,16 +1944,31 @@
 lt).
-isEmpty(
+doesNotContain(cachekey
 );%0D%0A
@@ -1991,39 +1991,32 @@
 Test of 
-receiveCacheRemoveEvent
+getOutDatedCache
  method,
@@ -2151,59 +2151,8 @@
 );%0D%0A
-%09%09String cachekey = UUID.randomUUID().toString();%0D%0A
 %09%09Ma
@@ -2209,32 +2209,83 @@
  = new Date();%0D%0A
+%09%09String cachekey = UUID.randomUUID().toString();%0D%0A
 %09%09map.put(cachek
@@ -2293,33 +2293,33 @@
 y, now.getTime()
-+
+-
 DELAY);%0D%0A%09%09updat
@@ -2317,60 +2317,336 @@
 %0D%0A%09%09
-updatedCacheManager.receiveCacheRemoveEvent(cachekey
+Collection%3CString%3E result = updatedCacheManager.getOutDatedCache(map);%0D%0A%09%09assertThat(result).isNotNull();%0D%0A%09%09assertThat(result).isEmpty();%0D%0A%09%7D%0D%0A%0D%0A%09/**%0D%0A%09 * Test of getOutDatedCache method, of class UpdatedCacheManager.%0D%0A%09 */%0D%0A%09@Test%0D%0A%09public void testGetOutDatedCacheNullMap() %7B%0D%0A%09%09System.out.println(%22getNoOutDatedCacheNullMap%22
 );%0D%0A
@@ -2704,35 +2704,36 @@
 etOutDatedCache(
-map
+null
 );%0D%0A%09%09assertThat
@@ -2741,39 +2741,59 @@
 result).
-doe
+i
 sNot
-Contain(cachekey
+Null();%0D%0A%09%09assertThat(result).isEmpty(
 );%0D%0A%09%7D%0D%0A

improve test2