@Test
  public void should_serialize_to_json() throws Exception {
    // Given
    pmf.configContext = configContext;
    ObjectMapper mapper = new ObjectMapper();
    mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
    when(configContext.getMapperFor(CompleteBean.class)).thenReturn(mapper);
    CompleteBean entity = CompleteBeanTestBuilder.builder().id(10L).name("name").buid();

    // When
    final String serialized = pmf.jsonSerialize(entity);

    // Then
    assertThat(serialized)
        .isEqualTo(
            "{\"id\":10,\"name\":\"name\",\"friends\":[],\"followers\":[],\"preferences\":{}}");
  }
  @Test
  public void should_create_batching_persistence_manager() throws Exception {
    // Given
    Map<Class<?>, EntityMeta> entityMetaMap = new HashMap<Class<?>, EntityMeta>();
    PersistenceContextFactory contextFactory = mock(PersistenceContextFactory.class);

    // When
    pmf.entityMetaMap = entityMetaMap;
    pmf.configContext = configContext;
    pmf.daoContext = daoContext;
    pmf.contextFactory = contextFactory;

    PersistenceManager manager = pmf.createBatchingPersistenceManager();

    // Then
    assertThat(manager).isNotNull();
  }
 @Before
 public void setUp() {
   pmf =
       new PersistenceManagerFactory(
           cluster, ImmutableMap.<ConfigurationParameters, Object>of(FORCE_TABLE_CREATION, true));
   pmf.configurationMap = configMap;
   Whitebox.setInternalState(pmf, ArgumentExtractor.class, argumentExtractor);
   Whitebox.setInternalState(pmf, AchillesBootstrapper.class, boostrapper);
   Whitebox.setInternalState(pmf, ProxyClassFactory.class, proxyClassFactory);
 }
  @Test
  public void should_deserialize_from_json() throws Exception {
    // Given
    pmf.configContext = configContext;
    ObjectMapper mapper = new ObjectMapper();
    mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
    when(configContext.getMapperFor(CompleteBean.class)).thenReturn(mapper);

    // When
    final CompleteBean actual =
        pmf.deserializeJson(CompleteBean.class, "{\"id\":10,\"name\":\"name\"}");

    // Then
    assertThat(actual.getId()).isEqualTo(10L);
    assertThat(actual.getName()).isEqualTo("name");
    assertThat(actual.getFriends()).isNull();
    assertThat(actual.getFollowers()).isNull();
    assertThat(actual.getPreferences()).isNull();
  }
  @Test
  public void should_bootstrap_persistence_manager_factory() throws Exception {
    // Given
    List<Class<?>> candidateClasses = Arrays.asList();
    List<Interceptor<?>> interceptors = Arrays.asList();
    Map<Class<?>, EntityMeta> entityMetaMap =
        ImmutableMap.<Class<?>, EntityMeta>of(CompleteBean.class, new EntityMeta());
    ParsingResult parsingResult = new ParsingResult(entityMetaMap, true);

    // When
    when(argumentExtractor.initConfigContext(configMap)).thenReturn(configContext);
    when(argumentExtractor.initSession(cluster, configMap)).thenReturn(session);
    when(argumentExtractor.initInterceptors(configMap)).thenReturn(interceptors);
    when(argumentExtractor.initProxyWarmUp(configMap)).thenReturn(true);
    when(argumentExtractor.initEntities(configMap)).thenReturn(candidateClasses);

    when(configMap.getTyped(ENTITY_PACKAGES)).thenReturn("packages");
    when(configMap.getTyped(KEYSPACE_NAME)).thenReturn("keyspace");
    when(boostrapper.buildMetaDatas(configContext, candidateClasses)).thenReturn(parsingResult);
    when(configContext.isForceColumnFamilyCreation()).thenReturn(true);
    when(boostrapper.buildDaoContext(session, parsingResult, configContext)).thenReturn(daoContext);

    pmf.bootstrap();

    // Then
    assertThat(pmf.entityMetaMap).isSameAs(entityMetaMap);
    assertThat(pmf.configContext).isSameAs(configContext);
    assertThat(pmf.daoContext).isSameAs(daoContext);
    PersistenceContextFactory contextFactory =
        Whitebox.getInternalState(pmf, PersistenceContextFactory.class);
    assertThat(Whitebox.getInternalState(contextFactory, DaoContext.class)).isSameAs(daoContext);
    assertThat(Whitebox.getInternalState(contextFactory, ConfigurationContext.class))
        .isSameAs(configContext);
    assertThat(Whitebox.getInternalState(contextFactory, "entityMetaMap")).isSameAs(entityMetaMap);

    verify(boostrapper).buildMetaDatas(configContext, candidateClasses);
    verify(boostrapper).validateOrCreateTables(contextCaptor.capture());
    verify(boostrapper).addInterceptorsToEntityMetas(interceptors, entityMetaMap);
    verify(proxyClassFactory).createProxyClass(CompleteBean.class);

    SchemaContext schemaContext = contextCaptor.getValue();

    assertThat(Whitebox.getInternalState(schemaContext, Cluster.class)).isSameAs(cluster);
    assertThat(Whitebox.getInternalState(schemaContext, Session.class)).isSameAs(session);
    assertThat(Whitebox.getInternalState(schemaContext, "entityMetaMap")).isSameAs(entityMetaMap);
    assertThat(Whitebox.getInternalState(schemaContext, "keyspaceName")).isEqualTo("keyspace");
    assertThat((Boolean) Whitebox.getInternalState(schemaContext, "forceColumnFamilyCreation"))
        .isTrue();
    assertThat((Boolean) Whitebox.getInternalState(schemaContext, "hasCounter")).isTrue();
  }