ConcurrentMaps { static final <KEY, VALUE> ConcurrentMap<KEY, VALUE> asConcurrentMap(final Map<KEY, VALUE> map) { if (ConcurrentMap.class.isAssignableFrom(map.getClass())) { return (ConcurrentMap<KEY, VALUE>) nullsafe(map); } return new ConcurrentHashMap<>(nullsafe(map)); } private  ConcurrentMaps();   }
@Test public void shouldMakeDefensiveCopyOfMap() { final Map<Object, Object> map = new HashMap<>(); final ConcurrentMap<Object, Object> concurrentMap = ConcurrentMaps.asConcurrentMap(map); Assert.assertNotNull("Returned map is NULL", concurrentMap); Assert.assertNotSame("Instsances are the same", map, concurrentMap); }
@Test public void shouldReturnConcurrentMap() { final Map<Object, Object> map = new ConcurrentHashMap<>(); final ConcurrentMap<Object, Object> concurrentMap = ConcurrentMaps.asConcurrentMap(map); Assert.assertNotNull("Returned map is NULL", concurrentMap); Assert.assertSame("Instances are not the same", map, concurrentMap); }