CacheKeyBuilderImpl implements CacheKeyBuilder { @Override public String getAssignCacheKey(final AnnotationData data) { if (data == null || data.getAssignedKey() == null || data.getAssignedKey().length() < 1) { throw new InvalidParameterException("Ids for objects in the cache must be at least 1 character long."); } return data.getNamespace() + SEPARATOR + data.getAssignedKey(); }  void setDefaultKeyProvider(final KeyProvider defaultKeyProvider); KeyProvider getDefaultKeyProvider(); @Override String getCacheKey(final AnnotationData data, final Object[] args, final String methodDesc); @Override String getCacheKey(final Object keyObject, final String namespace); @Override List<String> getCacheKeys(final List<Object> keyObjects, final String namespace); @Override List<String> getCacheKeys(final AnnotationData data, final Object[] args, final String methodDesc); @Override String getAssignCacheKey(final AnnotationData data);  }
@Test public void getAssignCacheKey() { AnnotationData data = new AnnotationData(); try { data.setAssignedKey(null); data.setNamespace(null); cacheKeyBuilder.getAssignCacheKey(data); fail("Expected exception."); } catch (InvalidParameterException ex) { assertTrue(ex.getMessage().indexOf("at least 1 character") != -1); System.out.println(ex.getMessage()); } try { data.setAssignedKey(""); cacheKeyBuilder.getAssignCacheKey(data); fail("Expected exception."); } catch (InvalidParameterException ex) { assertTrue(ex.getMessage().indexOf("at least 1 character") != -1); System.out.println(ex.getMessage()); } final String objectId = RandomStringUtils.randomAlphanumeric(20); final String namespace = RandomStringUtils.randomAlphanumeric(12); data.setAssignedKey(objectId); data.setNamespace(namespace); final String result = cacheKeyBuilder.getAssignCacheKey(data); assertTrue(result.indexOf(objectId) != -1); assertTrue(result.indexOf(namespace) != -1); }