Cake { public static String key(String... subKeys) { if (subKeys.length == 0) { throw new IllegalArgumentException("cannot form cake key; no keys supplied"); } Arrays.asList(subKeys).forEach(Cake::validateKey); return StringUtils.join(subKeys, Cake.SEPARATOR); } Cake();  Cake(Cake other); static String key(String... subKeys); @SuppressWarnings("unchecked") T get(String... key); @SuppressWarnings("unchecked") T get(Class<T> clazz, String... key); void publish(String key, Object value); void inNamespace(String key, Runnable runnable); String getPublishedKeyForValue(Object value, boolean fullyQualified); @JsonIgnore String getNamespace(); boolean hasContext(); @JsonIgnore T getContext(); @JsonIgnore @SuppressWarnings("unchecked") T getContext(Class<T> clazz); @JsonIgnore T getOrGetContext(String... key); @JsonIgnore T getOrGetContext(Class<T> clazz, String... key); static final String SEPARATOR; }
@Test(expected = IllegalArgumentException.class) public void testKey_throwsOnNoInputs() { Cake.key(); }
@Test(expected = IllegalArgumentException.class) public void testKey_throwsOnNullSubkey() { Cake.key("foo", null); }
@Test(expected = IllegalArgumentException.class) public void testKey_throwsOnEmptyStringSubkey() { Cake.key("", "bar"); }
@Test(expected = IllegalArgumentException.class) public void testKey_throwsOnSubkeyContainingSeparator() { Cake.key("a" + Cake.SEPARATOR + "b", "c"); }
@Test public void testKey_noSeparatorForSingleKey() { assertEquals("a", Cake.key("a")); }
@Test public void testKey_returnsKeysSeparatedBySeparator() { assertEquals("a" + Cake.SEPARATOR + "b", Cake.key("a", "b")); }