JcsCache implements ICache<K, V> { @Override public void put(final K key, final V value) throws CacheOperationException { if (null == key) { throw new CacheOperationException("Key must not be null"); } try { cache.putInGroup(key, groupName, value); } catch (final CacheException e) { throw new CacheOperationException("Failed to add item to cache", e); } } JcsCache(final CompositeCache cache); private  JcsCache(final String cacheName, final ICompositeCacheAttributes attr); @Override V get(final K key); @Override void put(final K key, final V value); @Override void remove(final K key); @Override Collection<V> getAllValues(); @Override Set<K> getAllKeys(); @Override int size(); @Override void clear();  }
@Test public void shouldThrowAnExceptionIfEntryAlreadyExistsWhenUsingPutSafe() { try { cache.put("test", 1); cache.putSafe("test", 1); fail(); } catch (final OverwritingException | CacheOperationException e) { assertEquals("Cache entry already exists for key: test", e.getMessage()); } }
@Test public void shouldThrowExceptionWhenAddingNullKeyToCache() { try { cache.put(null, 2); fail("Expected an exception"); } catch (final CacheOperationException e) { assertNotNull(e.getMessage()); } }
@Test public void shouldThrowExceptionIfAddingNullValue() { try { cache.put("test", null); fail("Expected an exception"); } catch (final CacheOperationException e) { assertNotNull(e.getMessage()); } }