DefaultKeyProvider implements KeyProvider { @Override public String[] generateKeys(final Object[] keyObjects) { if (keyObjects == null || keyObjects.length < 1) { throw new InvalidParameterException("The key objects must be defined."); } final String[] results = new String[keyObjects.length]; for (int i = 0; i < keyObjects.length; i++) { results[i] = generateKey(keyObjects[i]); } return results; }  void setMethodStore(final CacheKeyMethodStore methodStore); CacheKeyMethodStore getMethodStore(); @Override String generateKey(final Object keyObject); @Override String[] generateKeys(final Object[] keyObjects);  }
@Test public void testMultiplexExceptions() { try { cut.generateKeys(null); fail("Expected exception"); } catch (InvalidParameterException ex) { } try { cut.generateKeys(new Object[0]); fail("Expected exception"); } catch (InvalidParameterException ex) { } }
@Test public void testMultiplex() { final Object[] src = new Object[4]; final String[] expectedResults = new String[4]; final String data = "abcdefghijklmnopqrstuvwxyz"; for (int ix = 0; ix < 4; ix++) { final String val = data.substring(0, 5 + ix); src[ix] = new KeyObject(val); expectedResults[ix] = val; } final String [] results = cut.generateKeys(src); assertArrayEquals(expectedResults, results); }