### Question:
B2JsonHandlerMap { public synchronized <T> B2JsonTypeHandler<T> getHandler(Type type) throws B2JsonException { B2Preconditions.checkState(!inGetHandler); B2Preconditions.checkState(handlersAddedToMap.isEmpty()); { final B2JsonTypeHandler<T> existingHandlerOrNull = lookupHandler(type); if (existingHandlerOrNull != null) { return existingHandlerOrNull; } } inGetHandler = true; final B2JsonTypeHandler<T> handler; final List<B2JsonTypeHandler> handlersToCheckDefaults; try { handler = getUninitializedHandler(type); for (int i = 0; i < handlersAddedToMap.size(); i++) { final B2JsonTypeHandler handlerAdded = handlersAddedToMap.get(i); if (handlerAdded instanceof B2JsonInitializedTypeHandler) { ((B2JsonInitializedTypeHandler) handlerAdded).initialize(this); } } handlersToCheckDefaults = new ArrayList<>(handlersAddedToMap); } catch (Throwable t) { for (B2JsonTypeHandler handlerAdded : handlersAddedToMap) { map.remove(handlerAdded.getHandledType()); } throw new B2JsonException(t.getMessage()); } finally { handlersAddedToMap.clear(); B2Preconditions.checkState(inGetHandler); inGetHandler = false; } try { for (B2JsonTypeHandler<?> handlerToCheck : handlersToCheckDefaults) { if (handlerToCheck instanceof B2JsonTypeHandlerWithDefaults) { final B2JsonTypeHandlerWithDefaults handlerWithDefaults = (B2JsonTypeHandlerWithDefaults) handlerToCheck; handlerWithDefaults.checkDefaultValuesAndRememberResult(); } } } finally { handlersAddedToMap.clear(); } return handler; } B2JsonHandlerMap(); private  B2JsonHandlerMap(Map<Type, B2JsonTypeHandler<?>> initialMapOrNull); synchronized B2JsonTypeHandler<T> getHandler(Type type);  }### Answer:
@Test public void testBadClassNotLeftInMap() { final B2JsonHandlerMap handlerMap = new B2JsonHandlerMap(); try { handlerMap.getHandler(BadClassHolder.class); fail("should have thrown"); } catch (Throwable t) { assertThat(t.getMessage(), containsString("BadClass has no constructor annotated with B2Json.constructor")); } try { handlerMap.getHandler(BadClassHolder.class); fail("should have thrown"); } catch (Throwable t) { assertThat(t.getMessage(), containsString("BadClass has no constructor annotated with B2Json.constructor")); } }
@Test public void testSet() throws B2JsonException { final B2JsonHandlerMap handlerMap = new B2JsonHandlerMap(); thrown.expectMessage("actualTypeArguments must be same length as class' type parameters"); handlerMap.getHandler(HashSet.class); }