CheckSpec implements JsonObjectConvertible { public static CheckSpec copyOf(final @NotNull CheckSpec original) { final CheckSpec copy = new CheckSpec(); copy.setName(original.getName()); copy.setImpl(original.getImpl()); copy.setTemplate(original.getTemplate()); copy.setSkip(original.isSkip()); copy.setInlineScript(original.getInlineScript()); copy.setInlineEngine(original.getInlineEngine()); copy.setConfig(original.getConfig()); return copy; }  @NotNull static CheckSpec.JsonKeys keys(); String getImpl(); void setImpl(final String impl); String getInlineScript(); void setInlineScript(final String inlineScript); String getInlineEngine(); void setInlineEngine(final String inlineEngine); final boolean isAbstract(); final boolean notAbstract(); String getName(); void setName(final String name); String getTemplate(); void setTemplate(final String template); boolean isSkip(); void setSkip(final boolean skip); final boolean notSkipped(); JsonObject getConfig(); void setConfig(final JsonObject config); final boolean overrides(final @NotNull CheckSpec that); final boolean isOverriddenBy(final @NotNull CheckSpec that); final CheckSpec overlay(final @NotNull CheckSpec that); final boolean inherits(final @NotNull CheckSpec that); final boolean isInheritedBy(final @NotNull CheckSpec that); final CheckSpec inherit(final @NotNull CheckSpec that); static CheckSpec fromJson(final @NotNull JsonObject json); @Override final JsonObject toJson(); @Override String toString(); @Override boolean equals(final Object o); @Override int hashCode(); static CheckSpec copyOf(final @NotNull CheckSpec original); static ImmutableSpec immutableCopyOf(final @NotNull CheckSpec original);  }
@Test public void testCopyOf() { final CheckSpec.JsonKeys keys = CheckSpec.keys(); final JsonObject specJson = obj() .key(keys.name(), keys.name()) .key(keys.impl(), keys.impl()) .key(keys.inlineScript(), keys.inlineScript()) .key(keys.inlineEngine(), keys.inlineEngine()) .key(keys.config(), key("foo", "bar")) .key(keys.template(), keys.template()) .key(keys.skip(), true) .get(); final CheckSpec spec = CheckSpec.fromJson(specJson); assertEquals("copy should equal copied", spec, CheckSpec.copyOf(spec)); assertEquals("immutable copy should equal copied", spec, CheckSpec.immutableCopyOf(spec)); assertEquals("copied should equal copy", CheckSpec.copyOf(spec), spec); assertEquals("copied should equal immutable copy", CheckSpec.immutableCopyOf(spec), spec); final Set<CheckSpec> specSet = new HashSet<>(); specSet.add(spec); specSet.add(CheckSpec.copyOf(spec)); assertEquals("hashSet should still only have one.", 1, specSet.size()); specSet.add(CheckSpec.immutableCopyOf(spec)); assertEquals("hashSet should still only have one.", 1, specSet.size()); final CheckSpec diffed = CheckSpec.copyOf(spec); diffed.setName("eman"); specSet.add(diffed); assertEquals("hashSet should now have two.", 2, specSet.size()); }