@Test public void testGenerateCacheKey() throws Exception { final Method method = KeyObject.class.getMethod("toString", (Class<?>[]) null); try { cut.generateObjectId(method, new KeyObject(null)); fail("Expected Exception."); } catch (RuntimeException ex) { assertTrue(ex.getMessage().indexOf("empty key value") != -1); } try { cut.generateObjectId(method, new KeyObject("")); fail("Expected Exception."); } catch (RuntimeException ex) { assertTrue(ex.getMessage().indexOf("empty key value") != -1); } final String result = "momma"; assertEquals(result, cut.generateObjectId(method, new KeyObject(result))); }
String generateObjectId(final Method keyMethod, final Object keyObject) throws Exception { final String objectId = (String) keyMethod.invoke(keyObject, (Object[]) null); if (objectId == null || objectId.length() < 1) { throw new RuntimeException("Got an empty key value from " + keyMethod.getName()); } return objectId; }
DefaultKeyProvider implements KeyProvider { String generateObjectId(final Method keyMethod, final Object keyObject) throws Exception { final String objectId = (String) keyMethod.invoke(keyObject, (Object[]) null); if (objectId == null || objectId.length() < 1) { throw new RuntimeException("Got an empty key value from " + keyMethod.getName()); } return objectId; } }
DefaultKeyProvider implements KeyProvider { String generateObjectId(final Method keyMethod, final Object keyObject) throws Exception { final String objectId = (String) keyMethod.invoke(keyObject, (Object[]) null); if (objectId == null || objectId.length() < 1) { throw new RuntimeException("Got an empty key value from " + keyMethod.getName()); } return objectId; }  }
DefaultKeyProvider implements KeyProvider { String generateObjectId(final Method keyMethod, final Object keyObject) throws Exception { final String objectId = (String) keyMethod.invoke(keyObject, (Object[]) null); if (objectId == null || objectId.length() < 1) { throw new RuntimeException("Got an empty key value from " + keyMethod.getName()); } return objectId; }  void setMethodStore(final CacheKeyMethodStore methodStore); CacheKeyMethodStore getMethodStore(); @Override String generateKey(final Object keyObject); @Override String[] generateKeys(final Object[] keyObjects); }
DefaultKeyProvider implements KeyProvider { String generateObjectId(final Method keyMethod, final Object keyObject) throws Exception { final String objectId = (String) keyMethod.invoke(keyObject, (Object[]) null); if (objectId == null || objectId.length() < 1) { throw new RuntimeException("Got an empty key value from " + keyMethod.getName()); } return objectId; }  void setMethodStore(final CacheKeyMethodStore methodStore); CacheKeyMethodStore getMethodStore(); @Override String generateKey(final Object keyObject); @Override String[] generateKeys(final Object[] keyObjects);  }