ShutdownReasonFactory { public static ShutdownReason fromJson(final JsonObject jsonObject) { checkNotNull(jsonObject, "reason JSON object"); final ShutdownReasonType type = getReasonType(jsonObject); if (ShutdownReasonType.Known.PURGE_NAMESPACE.equals(type)) { return PurgeNamespaceReason.fromJson(jsonObject); } else if (ShutdownReasonType.Known.PURGE_ENTITIES.equals(type)) { return PurgeEntitiesReason.fromJson(jsonObject); } else { return ShutdownNoReason.INSTANCE; } } private  ShutdownReasonFactory(); static ShutdownReason fromJson(final JsonObject jsonObject); static ShutdownReason getPurgeNamespaceReason(final CharSequence namespace); static ShutdownReason getPurgeEntitiesReason(final List<EntityId> entityIds);  }
@Test public void fromJsonWithoutType() { final JsonObject jsonObject = purgeNamespaceReasonJson.toBuilder() .remove(ShutdownReason.JsonFields.TYPE) .build(); assertThat(ShutdownReasonFactory.fromJson(jsonObject)).isEqualTo(ShutdownNoReason.INSTANCE); }
@Test public void fromJsonWithUnknownType() { final JsonObject shutdownReasonWithUnknownType = purgeEntitiesReasonJson.toBuilder() .set(ShutdownReason.JsonFields.TYPE, "fooBar") .build(); assertThat(ShutdownReasonFactory.fromJson(shutdownReasonWithUnknownType)).isEqualTo(ShutdownNoReason.INSTANCE); }