ImmutableThing implements Thing { @Override public Thing setDefinition(@Nullable final CharSequence definitionIdentifier) { if (null != definitionIdentifier) { return new ImmutableThing(thingId, acl, policyId, ImmutableThingDefinition.ofParsed(definitionIdentifier), attributes, features, lifecycle, revision, modified, created, metadata); } else { return new ImmutableThing(thingId, acl, policyId, NullThingDefinition.getInstance(), attributes, features, lifecycle, revision, modified, created, metadata); } } private  ImmutableThing(@Nullable final ThingId thingId,
            @Nullable final AccessControlList acl,
            @Nullable final PolicyId policyId,
            @Nullable final ThingDefinition definition,
            @Nullable final Attributes attributes,
            @Nullable final Features features,
            @Nullable final ThingLifecycle lifecycle,
            @Nullable final ThingRevision revision,
            @Nullable final Instant modified,
            @Nullable final Instant created,
            @Nullable final Metadata metadata); @Override Optional<ThingRevision> getRevision(); @Override Optional<Instant> getModified(); @Override Optional<Instant> getCreated(); @Override boolean isDeleted(); @Override Optional<ThingId> getEntityId(); @Override Optional<String> getNamespace(); @Override Optional<Attributes> getAttributes(); @Override Thing setAttributes(@Nullable final Attributes attributes); @Override Thing removeAttributes(); @Override Thing setAttribute(final JsonPointer attributePath, final JsonValue attributeValue); @Override Thing removeAttribute(final JsonPointer attributePath); @Override Optional<ThingDefinition> getDefinition(); @Override Thing setDefinition(@Nullable final CharSequence definitionIdentifier); @Override Thing removeDefinition(); @Override Optional<Features> getFeatures(); @Override Thing removeFeatures(); @Override Thing setFeatures(@Nullable final Features features); @Override Thing setFeature(final Feature feature); @Override Thing removeFeature(final String featureId); @Override Thing setFeatureDefinition(final String featureId, final FeatureDefinition definition); @Override Thing removeFeatureDefinition(final String featureId); @Override Thing setFeatureProperties(final String featureId, final FeatureProperties properties); @Override Thing removeFeatureProperties(final String featureId); @Override Thing setFeatureProperty(final String featureId, final JsonPointer propertyJsonPointer,
            final JsonValue propertyValue); @Override Thing removeFeatureProperty(final String featureId, final JsonPointer propertyPath); @Override @Deprecated Optional<AccessControlList> getAccessControlList(); @Override @Deprecated Thing setAccessControlList(final AccessControlList accessControlList); @Override @Deprecated Thing setAclEntry(final AclEntry aclEntry); @Override @Deprecated Thing removeAllPermissionsOf(final AuthorizationSubject authorizationSubject); @Override Optional<PolicyId> getPolicyEntityId(); @Override Thing setPolicyId(@Nullable final PolicyId policyId); @Override Optional<ThingLifecycle> getLifecycle(); @Override Thing setLifecycle(final ThingLifecycle newLifecycle); @Override Optional<Metadata> getMetadata(); @Override JsonObject toJson(final JsonSchemaVersion schemaVersion, final Predicate<JsonField> thePredicate); @Override int hashCode(); @SuppressWarnings({"squid:MethodCyclomaticComplexity", "squid:S1067", "OverlyComplexMethod"}) @Override boolean equals(final Object obj); @Override String toString();  }
@Test public void setThingDefinitionStringWorksAsExpected() { final String newDefinition = "foo:new:version"; final Thing changedThing = KNOWN_THING_V2.setDefinition(newDefinition); assertThat(changedThing) .isNotSameAs(KNOWN_THING_V2) .hasId(THING_ID) .hasPolicyId(POLICY_ID) .hasAttributes(ATTRIBUTES) .hasDefinition(newDefinition) .hasFeatures(FEATURES) .hasLifecycle(LIFECYCLE) .hasRevision(REVISION); }
@Test public void setThingDefinitionWorksAsExpected() { final ImmutableThingDefinition newDefinition = ImmutableThingDefinition.ofParsed("foo:new:crew"); final Thing changedThing = KNOWN_THING_V2.setDefinition(newDefinition); assertThat(changedThing) .isNotSameAs(KNOWN_THING_V2) .hasId(THING_ID) .hasPolicyId(POLICY_ID) .hasAttributes(ATTRIBUTES) .hasDefinition(newDefinition) .hasFeatures(FEATURES) .hasLifecycle(LIFECYCLE) .hasRevision(REVISION); }