WrapperFactoryDefault implements WrapperFactory { @Override public <T> T wrap(T domainObject) { return wrap(domainObject, control()); }  @PostConstruct void init(); @Override T wrap(T domainObject); @Override T wrap(
            final T domainObject,
            final SyncControl syncControl); @Override T wrapMixin(Class<T> mixinClass, Object mixedIn); @Override T wrapMixin(Class<T> mixinClass, Object mixedIn, SyncControl syncControl); @Override boolean isWrapper(Object possibleWrappedDomainObject); @Override T unwrap(T possibleWrappedDomainObject); @Override T asyncWrap(
            final T domainObject,
            final AsyncControl<R> asyncControl); @Override T asyncWrapMixin(Class<T> mixinClass, Object mixedIn, AsyncControl<R> asyncControl); @Override List<InteractionListener> getListeners(); @Override boolean addInteractionListener(InteractionListener listener); @Override boolean removeInteractionListener(InteractionListener listener); @Override void notifyListeners(InteractionEvent interactionEvent);  }
@Test public void wrap_ofUnwrapped_delegates_to_createProxy() throws Exception { final DomainObject domainObject = new DomainObject(); wrapperFactory.wrap(domainObject); assertThat(createProxyCalledWithDomainObject, is(domainObject)); assertThat(createProxyCalledWithSyncControl, is(not(nullValue()))); }
@Test public void wrap_ofWrapped_sameMode_returnsUnchanged() throws Exception { final DomainObject wrappedObject = new DomainObject(); final DomainObject domainObject = new WrappingDomainObject(wrappedObject, ImmutableEnumSet.noneOf(ExecutionMode.class)); final DomainObject wrappingObject = wrapperFactory.wrap(domainObject); assertThat(wrappingObject, is(domainObject)); assertThat(createProxyCalledWithDomainObject, is(nullValue())); }
@Test public void wrap_ofWrapped_differentMode_delegates_to_createProxy() throws Exception { final DomainObject wrappedObject = new DomainObject(); final DomainObject domainObject = new WrappingDomainObject(wrappedObject, ImmutableEnumSet.noneOf(ExecutionMode.class)); final DomainObject wrappingObject = wrapperFactory.wrap(domainObject, SyncControl.control().withSkipRules()); assertThat(wrappingObject, is(not(domainObject))); assertThat(createProxyCalledWithDomainObject, is(wrappedObject)); Assertions.assertThat(createProxyCalledWithSyncControl.getExecutionModes()).contains(ExecutionMode.SKIP_RULE_VALIDATION); }