AttachedEntityMetadata implements EntityMetadata { @Override public String toString() { return getClass().getSimpleName() + "{" + "schema=" + owner.getTypeName() + ", document=" + safeDocumentToString() + '}'; } AttachedEntityMetadata(final EntityAdapter owner, final ODocument document); EntityAdapter getOwner(); ODocument getDocument(); @Override @Nonnull EntityId getId(); @Override @Nonnull EntityVersion getVersion(); DetachedEntityMetadata detach(); @Override String toString(); @Override Optional<Class<T>> getEntityType(); @Override Optional<T> getEntity();  }
@Test public void toStringOutsideTxShouldNotLogSerializerError() { EntityMetadata metadata; try (ODatabaseDocumentTx db = database.getInstance().acquire()) { entityAdapter.register(db); db.begin(); TestEntity entity = new TestEntity(); entity.primary = "Hello"; entity.secondary = "World"; entityAdapter.set(db, entity); db.commit(); } try (ODatabaseDocumentTx db = database.getInstance().acquire()) { metadata = entityAdapter.get(db).getEntityMetadata(); } ODatabaseRecordThreadLocal.INSTANCE.remove(); String toStringOutput = metadata.toString(); ArgumentCaptor<ILoggingEvent> events = ArgumentCaptor.forClass(ILoggingEvent.class); verify(mockAppender, atLeastOnce()).doAppend(events.capture()); events.getAllValues().forEach( event -> assertThat(event.getFormattedMessage(), not(containsString("Error deserializing record")))); if (entityAdapter.isPartialEntity()) { assertThat(toStringOutput, containsString("{primary:Hello}")); } else { assertThat(toStringOutput, containsString("{primary:Hello,secondary:World}")); } }