Cake { @JsonIgnore public <T> T getContext() { if (this.prefixStack.isEmpty()) { throw new IllegalStateException("cannot get context in root namespace"); } else { String prefix = this.getPrefixWithSeparator(this.prefixStack); prefix = prefix.substring(0, prefix.length() - 1); if (!entries.containsKey(prefix)) { throw new RuntimeException("cake does not contain context value for namespace " + prefix); } return (T) entries.get(prefix); } } 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 = IllegalStateException.class) public void testGetContext_throwsInRootNamespace() { cake.getContext(); }