static Object create(final Object bean, DecoratorExecutor executor) { try { Object proxy = new ByteBuddy() .subclass(bean.getClass()) .implement(EnhancedProxy.class) .defineField("bean", bean.getClass(), Modifier.PRIVATE) .defineField("executor", DecoratorExecutor.class, Modifier.PRIVATE) .method(isEquals()) .intercept(to(EqualsInterceptor.class)) .method(isAnnotatedWith(nameStartsWith("cucumber.api"))) .intercept(to(CucumberInterceptor.class)) .method(not(isEquals().or(isClone()).or(isAnnotatedWith(nameStartsWith("cucumber.api"))))) .intercept(toField("bean")) .make() .load(bean.getClass().getClassLoader(), ClassLoadingStrategy.Default.INJECTION) .getLoaded() .newInstance(); ReflectionUtils.injectValue(proxy, "bean", bean); ReflectionUtils.injectValue(proxy, "executor", executor); return proxy; } catch (Exception e) { throw new JpaUnitException("Failed to create proxy for " + bean, e); } } }