TerracottaMBeanGenerator { @SuppressWarnings("unchecked") <T> Class<? extends ServerMBean> generateMBeanInterface(Class<T> serviceInterface) { requireNonNull(serviceInterface); return (Class<? extends ServerMBean>) new ByteBuddy() .makeInterface(ServerMBean.class, serviceInterface) .name(serviceInterface.getName() + "MBean") .make() .load(getClass().getClassLoader()) .getLoaded(); }    }
@Test public void test_generateMBeanInterface() throws NoSuchMethodException { assertThat( () -> generator.generateMBeanInterface(null), is(throwing(instanceOf(NullPointerException.class)))); Class<? extends ServerMBean> mBeanInterface = generator.generateMBeanInterface(MyService.class); assertThat(mBeanInterface.getName(), is(equalTo(MyService.class.getName() + "MBean"))); assertThat(MyService.class.isAssignableFrom(mBeanInterface), is(true)); assertThat(ServerMBean.class.isAssignableFrom(mBeanInterface), is(true)); assertThat(mBeanInterface.getMethod("say", String.class), is(not(nullValue()))); }