@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();
  }
  @Test
  public void should_init_default_object_factory_mapper() throws Exception {
    doCallRealMethod().when(extractor).initObjectMapperFactory(configMap);
    ObjectMapperFactory actual = extractor.initObjectMapperFactory(configMap);

    assertThat(actual).isNotNull();

    ObjectMapper mapper = actual.getMapper(Integer.class);

    assertThat(mapper).isNotNull();
    assertThat(mapper.getSerializationConfig().getSerializationInclusion())
        .isEqualTo(Inclusion.NON_NULL);
    assertThat(
            mapper
                .getDeserializationConfig()
                .isEnabled(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES))
        .isFalse();
    Collection<AnnotationIntrospector> ais =
        mapper.getSerializationConfig().getAnnotationIntrospector().allIntrospectors();

    assertThat(ais).hasSize(2);
    Iterator<AnnotationIntrospector> iterator = ais.iterator();

    assertThat(iterator.next())
        .isInstanceOfAny(JacksonAnnotationIntrospector.class, JaxbAnnotationIntrospector.class);
    assertThat(iterator.next())
        .isInstanceOfAny(JacksonAnnotationIntrospector.class, JaxbAnnotationIntrospector.class);
  }
  @Test
  public void should_init_forceCFCreation_to_default_value() throws Exception {
    doCallRealMethod().when(extractor).initForceCFCreation(configMap);
    boolean actual = extractor.initForceCFCreation(configMap);

    assertThat(actual).isFalse();
  }
  @Test
  public void should_init_empty_entity_packages() throws Exception {
    doCallRealMethod().when(extractor).initEntityPackages(configMap);
    List<String> actual = extractor.initEntityPackages(configMap);

    assertThat(actual).isEmpty();
  }
  @Test
  public void should_init_default_write_consistency_level() throws Exception {
    configMap.put(CONSISTENCY_LEVEL_WRITE_DEFAULT_PARAM, "LOCAL_QUORUM");

    doCallRealMethod().when(extractor).initDefaultWriteConsistencyLevel(configMap);
    assertThat(extractor.initDefaultWriteConsistencyLevel(configMap)).isEqualTo(LOCAL_QUORUM);
  }
  @Test
  public void should_init_default_read_consistency_level() throws Exception {
    configMap.put(CONSISTENCY_LEVEL_READ_DEFAULT_PARAM, "ONE");

    doCallRealMethod().when(extractor).initDefaultReadConsistencyLevel(configMap);
    assertThat(extractor.initDefaultReadConsistencyLevel(configMap)).isEqualTo(ONE);
  }
  @Test
  public void should_return_empty_consistency_map_when_no_parameter() throws Exception {
    doCallRealMethod().when(extractor).initWriteConsistencyMap(configMap);

    Map<String, ConsistencyLevel> consistencyMap = extractor.initWriteConsistencyMap(configMap);

    assertThat(consistencyMap).isEmpty();
  }
  @Test
  public void should_init_forceCFCreation() throws Exception {
    configMap.put(FORCE_CF_CREATION_PARAM, true);

    doCallRealMethod().when(extractor).initForceCFCreation(configMap);
    boolean actual = extractor.initForceCFCreation(configMap);

    assertThat(actual).isTrue();
  }
  @Test
  public void should_init_object_mapper_factory() throws Exception {
    configMap.put(OBJECT_MAPPER_FACTORY_PARAM, factory);

    doCallRealMethod().when(extractor).initObjectMapperFactory(configMap);
    ObjectMapperFactory actual = extractor.initObjectMapperFactory(configMap);

    assertThat(actual).isSameAs(factory);
  }
  @Test
  public void should_init_entity_packages() throws Exception {
    configMap.put(ENTITY_PACKAGES_PARAM, "my.package.entity,another.package.entity,third.package");

    doCallRealMethod().when(extractor).initEntityPackages(configMap);
    List<String> actual = extractor.initEntityPackages(configMap);

    assertThat(actual)
        .containsExactly("my.package.entity", "another.package.entity", "third.package");
  }
  @Test
  public void should_return_empty_consistency_map_when_empty_map_parameter() throws Exception {
    configMap.put(CONSISTENCY_LEVEL_WRITE_MAP_PARAM, new HashMap<String, String>());

    doCallRealMethod().when(extractor).initWriteConsistencyMap(configMap);

    Map<String, ConsistencyLevel> consistencyMap = extractor.initWriteConsistencyMap(configMap);

    assertThat(consistencyMap).isEmpty();
  }
  @Test
  public void should_exception_when_invalid_consistency_level() throws Exception {
    configMap.put(CONSISTENCY_LEVEL_READ_DEFAULT_PARAM, "wrong_value");

    exception.expect(IllegalArgumentException.class);
    exception.expectMessage("'wrong_value' is not a valid Consistency Level");

    doCallRealMethod().when(extractor).initDefaultReadConsistencyLevel(configMap);
    extractor.initDefaultReadConsistencyLevel(configMap);
  }
  @Test
  public void should_init_object_mapper_factory_from_mapper() throws Exception {
    configMap.put(OBJECT_MAPPER_PARAM, mapper);

    doCallRealMethod().when(extractor).initObjectMapperFactory(configMap);
    ObjectMapperFactory actual = extractor.initObjectMapperFactory(configMap);

    assertThat(actual).isNotNull();
    assertThat(actual.getMapper(Long.class)).isSameAs(mapper);
  }
  @Test
  public void should_init_write_consistency_level_map() throws Exception {
    configMap.put(
        CONSISTENCY_LEVEL_WRITE_MAP_PARAM, ImmutableMap.of("cf1", "THREE", "cf2", "EACH_QUORUM"));

    doCallRealMethod().when(extractor).initWriteConsistencyMap(configMap);
    Map<String, ConsistencyLevel> consistencyMap = extractor.initWriteConsistencyMap(configMap);

    assertThat(consistencyMap.get("cf1")).isEqualTo(ConsistencyLevel.THREE);
    assertThat(consistencyMap.get("cf2")).isEqualTo(ConsistencyLevel.EACH_QUORUM);
  }
  @Test
  public void should_init_read_consistency_level_map() throws Exception {
    configMap.put(
        CONSISTENCY_LEVEL_READ_MAP_PARAM, ImmutableMap.of("cf1", "ONE", "cf2", "LOCAL_QUORUM"));

    doCallRealMethod().when(extractor).initReadConsistencyMap(configMap);
    Map<String, ConsistencyLevel> consistencyMap = extractor.initReadConsistencyMap(configMap);

    assertThat(consistencyMap.get("cf1")).isEqualTo(ConsistencyLevel.ONE);
    assertThat(consistencyMap.get("cf2")).isEqualTo(ConsistencyLevel.LOCAL_QUORUM);
  }
 @Test
 public void should_return_default_one_level_when_no_parameter() throws Exception {
   doCallRealMethod().when(extractor).initDefaultReadConsistencyLevel(configMap);
   assertThat(extractor.initDefaultReadConsistencyLevel(configMap)).isEqualTo(ONE);
 }