### Question:
StronglyConsistentCacheAccessor extends EhcacheDecoratorAdapter { @Override public Element putIfAbsent(Element element, boolean doNotNotifyCacheReplicators) throws NullPointerException { Object objectKey = element.getObjectKey(); if (objectKey == null) { throw new NullPointerException(); } acquireWriteLockOnKey(objectKey); try { Element current = getQuiet(objectKey); if (current == null) { super.put(element, doNotNotifyCacheReplicators); } return current; } finally { releaseWriteLockOnKey(objectKey); } } StronglyConsistentCacheAccessor(Ehcache underlyingCache); @Override Element putIfAbsent(Element element, boolean doNotNotifyCacheReplicators); @Override Element putIfAbsent(Element element); @Override boolean replace(Element old, Element element); @Override Element replace(Element element); @Override boolean removeElement(Element element); @Override void put(Element element, boolean doNotNotifyCacheReplicators); @Override void put(Element element); @Override void putAll(Collection<Element> elements); @Override void putQuiet(Element element); @Override void putWithWriter(Element element); @Override boolean remove(Object key, boolean doNotNotifyCacheReplicators); @Override void removeAll(Collection<?> keys); @Override boolean remove(Object key); @Override void removeAll(Collection<?> keys, boolean doNotNotifyCacheReplicators); @Override boolean remove(Serializable key, boolean doNotNotifyCacheReplicators); @Override boolean remove(Serializable key); @Override boolean removeQuiet(Object key); @Override boolean removeQuiet(Serializable key); @Override boolean removeWithWriter(Object key); @Override Element removeAndReturnElement(Object key); @Override Element get(Object key); @Override Map<Object, Element> getAll(Collection<?> keys); @Override Element get(Serializable key); @Override Element getQuiet(Object key); @Override Element getQuiet(Serializable key); @Override Element getWithLoader(Object key, CacheLoader loader, Object loaderArgument); @Override Map getAllWithLoader(Collection keys, Object loaderArgument);  }### Answer:
@Test public void testPutIfAbsent() { Element element = new Element("key", "value"); Ehcache underlyingCache = buildMockCache(); when(underlyingCache.getQuiet((Object)"key")).thenReturn(null, element); StronglyConsistentCacheAccessor cacheAccessor = new StronglyConsistentCacheAccessor(underlyingCache); element = cacheAccessor.putIfAbsent(element); assertThat(element, nullValue()); element = cacheAccessor.putIfAbsent(new Element("key", "otherValue")); assertThat(element.getObjectValue(), equalTo((Object)"value")); try { cacheAccessor.putIfAbsent(new Element(null, null)); fail("Expected NPE with null key"); } catch (NullPointerException e) { } }