### Question:
PersistorGeneratorImmutables extends PersistorGeneratorAbstract { @Override protected <BEAN> Persistor<BEAN> generate(ClassDescriptor<BEAN> classDescriptor, Map<String, PropertyPersistor<BEAN, ?, ?>> propertyPersistorMap, VersionManipulator<BEAN> versionManipulator, GeneratorManipulator<BEAN> generatorManipulator, final TypeConverterFactory typeFactory) throws Exception { final Optional<Method> builderMethod = getBuilderMethod(classDescriptor.getMappedClass()); final PersistorImmutablesBuilder<BEAN, ?> builderPersistor = buildBeanBuilder(classDescriptor.getMappedClass(), builderMethod.get().getReturnType(), typeFactory); return new PersistorImmutables<>(classDescriptor, propertyPersistorMap, versionManipulator, generatorManipulator, builderPersistor); }  @Override boolean applicableFor(Class<BEAN> beanClass);  }### Answer:
@Test public void should_use_builder_when_reading_the_resultset() throws Exception { final ClassDescriptor<ImmutableFoobarValue> classDescriptor = new ClassDescriptorBuilderImpl<>(ImmutableFoobarValue.class).build(); final Persistor<ImmutableFoobarValue> persistor = immutablesGenerator.generate(classDescriptor, new TypeConverterFactory(() -> new Jackson2JsonService())); final ResultEntry rs = Mockito.mock(ResultEntry.class); Mockito.when(rs.getString("bar")).thenReturn("barValue"); Mockito.when(rs.getString("name")).thenReturn("nameValue"); Mockito.when(rs.getInt("foo")).thenReturn(111); final ImmutableFoobarValue value = persistor.beanFromResultSet(rs, new ArrayList<>()); assertNotNull(value); assertEquals("barValue", value.bar()); assertTrue(value.name().isPresent()); assertEquals("nameValue", value.name().get()); assertEquals(111, value.foo()); Mockito.verify(rs, Mockito.times(1)).getString("bar"); Mockito.verify(rs, Mockito.times(1)).getString("name"); Mockito.verify(rs, Mockito.times(1)).getInt("foo"); Mockito.verify(rs, Mockito.times(0)).getLong("initBits"); }
@Test public void should_increase_the_bean_version() throws Exception { final ClassDescriptor<ImmutableFoobarValue> classDescriptor = new ClassDescriptorBuilderImpl<>(ImmutableFoobarValue.class).build(); final Persistor<ImmutableFoobarValue> persistor = immutablesGenerator.generate(classDescriptor, new TypeConverterFactory(() -> new Jackson2JsonService())); final int version = 1; final ImmutableFoobarValue bean = ImmutableFoobarValue.builder() .bar("bar") .foo(0) .version(1) .build(); final ImmutableFoobarValue updatedBean = persistor.increaseVersion(bean, false); assertEquals(version + 1, updatedBean.version().get().intValue()); }
@Test public void should_read_properties() throws Exception { final ClassDescriptor<ImmutableFoobarValue> classDescriptor = new ClassDescriptorBuilderImpl<>(ImmutableFoobarValue.class).build(); final Persistor<ImmutableFoobarValue> persistor = immutablesGenerator.generate(classDescriptor, new TypeConverterFactory(() -> new Jackson2JsonService())); final ImmutableFoobarValue foobar = ImmutableFoobarValue.builder() .name(UUID.randomUUID().toString()) .bar(UUID.randomUUID().toString()) .foo(new Random().nextInt()) .build(); assertEquals(foobar.bar(), persistor.getPropertyValues(new String[]{"bar"}, foobar)[0]); assertEquals(foobar.name().get(), persistor.getPropertyValues(new String[]{"name"}, foobar)[0]); assertEquals(foobar.foo(), persistor.getPropertyValues(new String[]{"foo"}, foobar)[0]); }