### Question:
WireSafeEnum { @Nonnull @SuppressWarnings("unchecked") public static <T extends Enum<T>> WireSafeEnum<T> fromJson( @Nonnull Class<T> enumType, @Nonnull String jsonValue ) { checkNotNull(enumType, "enumType"); checkNotNull(jsonValue, "jsonValue"); ensureJsonCacheInitialized(enumType); WireSafeEnum<?> cached = JSON_LOOKUP_CACHE.get(enumType).get(jsonValue); if (cached == null) { return new WireSafeEnum<>(enumType, jsonValue); } else { return (WireSafeEnum<T>) cached; } } private  WireSafeEnum(Class<T> enumType, String jsonValue, T enumValue); private  WireSafeEnum(Class<T> enumType, String jsonValue); @Nonnull @SuppressWarnings("unchecked") static WireSafeEnum<T> of(@Nonnull T value); @Nonnull @SuppressWarnings("unchecked") static WireSafeEnum<T> fromJson(
      @Nonnull Class<T> enumType,
      @Nonnull String jsonValue
  ); @Nonnull Class<T> enumType(); @Nonnull @JsonValue String asString(); @Nonnull Optional<T> asEnum(); @Nonnull T asEnumOrThrow(Supplier<? extends X> exceptionSupplier); @Nonnull T asEnumOrThrow(); boolean contains(@Nonnull T value); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString();  }### Answer:
@Test public void itDoesntAllowNullJsonValues() { Throwable t = catchThrowable(() -> WireSafeEnum.fromJson(NullJsonEnum.class, "ABC")); assertThat(t) .isInstanceOf(IllegalStateException.class) .hasMessageContaining("NullJsonEnum") .hasMessageContaining("DEF") .hasMessageContaining("null"); }
@Test public void itSerializesUnknownValueAsString() throws IOException { WireSafeEnum<RetentionPolicy> wrapper = WireSafeEnum.fromJson(RetentionPolicy.class, "INVALID"); assertThat(MAPPER.writeValueAsString(wrapper)).isEqualTo("\"INVALID\""); }
@Test public void itSerializesUnknownValueAsStringWithCustomJson() throws IOException { WireSafeEnum<CustomJsonEnum> wrapper = WireSafeEnum.fromJson(CustomJsonEnum.class, "ABC"); assertThat(MAPPER.writeValueAsString(wrapper)).isEqualTo("\"ABC\""); }
@Test public void itSerializesUnknownValueAsStringWithCollidingJson() throws IOException { WireSafeEnum<CollidingJsonEnum> wrapper = WireSafeEnum.fromJson(CollidingJsonEnum.class, "ABC"); assertThat(MAPPER.writeValueAsString(wrapper)).isEqualTo("\"ABC\""); }
@Test public void itSerializesUnknownValueAsStringWithCollidingJsonAndCreator() throws IOException { WireSafeEnum<CollidingJsonEnumWithCreator> wrapper = WireSafeEnum.fromJson(CollidingJsonEnumWithCreator.class, "ABC"); assertThat(MAPPER.writeValueAsString(wrapper)).isEqualTo("\"ABC\""); }