@Test
public void should_build_proxy_with_all_fields_loaded() throws Exception {
long primaryKey = RandomUtils.nextLong(0,Long.MAX_VALUE);
PropertyMeta pm = mock(PropertyMeta.class, RETURNS_DEEP_STUBS);
PropertyMeta counterMeta = mock(PropertyMeta.class, RETURNS_DEEP_STUBS);
Object value = new Object();
CompleteBean entity = CompleteBeanTestBuilder.builder().id(primaryKey).name("name").buid();
proxifier = spy(proxifier);
doReturn(interceptor).when(proxifier).buildInterceptor(eq(context), eq(entity), anySetOf(Method.class));
when(context.getEntityMeta()).thenReturn(entityMeta);
when(entityMeta.getIdMeta()).thenReturn(idMeta);
when(entityMeta.getAllMetasExceptCounters()).thenReturn(Arrays.asList(pm));
when(entityMeta.getAllCounterMetas()).thenReturn(Arrays.asList(counterMeta));
when(pm.forValues().getValueFromField(entity)).thenReturn(value);
when(context.getConfigContext()).thenReturn(configContext);
when(factory.createProxyClass(entity.getClass(), configContext)).thenReturn((Class) entity.getClass());
when(instantiator.instantiate(Mockito.<Class<Factory>>any())).thenReturn(realProxy);
Object proxy = proxifier.buildProxyWithAllFieldsLoadedExceptCounters(entity, context);
assertThat(proxy).isNotNull();
assertThat(proxy).isInstanceOf(Factory.class);
Factory factory = (Factory) proxy;
assertThat(factory.getCallbacks()).hasSize(1);
assertThat(factory.getCallback(0)).isInstanceOf(ProxyInterceptor.class);
verify(pm.forValues()).getValueFromField(entity);
verify(pm.forValues()).setValueToField(realProxy, value);
verify(counterMeta.forValues()).setValueToField(entity,null);
}