test_class.declarator: gson = new SampleDomainGsonFactory().create()
test_class.modifier: final
test_class.original_string: final Gson gson = new SampleDomainGsonFactory().create();
test_class.type: Gson
test_class.var_name: gson
test_class.file: myeslib-hazelcast/src/test/java/org/myeslib/hazelcast/storage/HzSnapshotReaderTest.java
test_class.identifier: HzSnapshotReaderTest
test_case.body: @SuppressWarnings({"unchecked" })
  	@Test
  	public void snapshotNotUpToDateWithTransactionHistory() {
  
  		UUID id = UUID.randomUUID();
  		
  		Map<UUID, AggregateRootHistory> eventsMap = Mockito.mock(Map.class);
  		Map<UUID, Snapshot<InventoryItemAggregateRoot>> lastSnapshotMap = Mockito.mock(Map.class);
  		Function<Void, InventoryItemAggregateRoot> inventoryItemInstanceFactory = Mockito.mock(Function.class);
  		AggregateRootHistory transactionHistoryWithOneUnitOfWork = Mockito.mock(AggregateRootHistory.class);
  	
  		long firstVersion = 1;
  		long versionNotYetOnLastSnapshot = 2;
  		
  		List<Event> events = new ArrayList<>();
  		events.add((Event)new InventoryItemCreated(id, "desc"));
  		events.add((Event)new InventoryIncreased(id, 4));
  		events.add((Event)new InventoryDecreased(id, 2));
  		
  		InventoryItemAggregateRoot aggregateInstance = new InventoryItemAggregateRoot();
  		aggregateInstance.setAvailable(4);
  		Snapshot<InventoryItemAggregateRoot> snapshotInstance = new Snapshot<>(aggregateInstance, firstVersion);
  
  		InventoryItemAggregateRoot freshInstance = new InventoryItemAggregateRoot();
  
  		when(eventsMap.get(id)).thenReturn(transactionHistoryWithOneUnitOfWork);
  		when(transactionHistoryWithOneUnitOfWork.getLastVersion()).thenReturn(versionNotYetOnLastSnapshot);
  		when(lastSnapshotMap.get(id)).thenReturn(snapshotInstance);
  		when(transactionHistoryWithOneUnitOfWork.getEventsAfterUntil(firstVersion, versionNotYetOnLastSnapshot)).thenReturn(events);
  	
  		HzSnapshotReader<UUID, InventoryItemAggregateRoot> st = new HzSnapshotReader<UUID, InventoryItemAggregateRoot>(eventsMap, lastSnapshotMap, inventoryItemInstanceFactory);
  		
  		Snapshot<InventoryItemAggregateRoot> resultingSnapshot = st.get(id);
  		
  		verify(eventsMap).get(id);
  		verify(lastSnapshotMap).get(id);
  		verify(transactionHistoryWithOneUnitOfWork, times(2)).getLastVersion(); 
  		when(inventoryItemInstanceFactory.apply(any(Void.class))).thenReturn(freshInstance);
  		verify(inventoryItemInstanceFactory).apply(any(Void.class));
  		verify(transactionHistoryWithOneUnitOfWork).getEventsAfterUntil(firstVersion, versionNotYetOnLastSnapshot);
  		
  		assertThat(resultingSnapshot.getVersion(), is(versionNotYetOnLastSnapshot));
  		
  		InventoryItemAggregateRoot fromSnapshot = resultingSnapshot.getAggregateInstance();
  
  		assertThat(fromSnapshot.getAvailable(), is(2));
  
  	}
test_case.class_method_signature: HzSnapshotReaderTest.snapshotNotUpToDateWithTransactionHistory()
test_case.full_signature: @SuppressWarnings({"unchecked" }) @Test public void snapshotNotUpToDateWithTransactionHistory()
test_case.identifier: snapshotNotUpToDateWithTransactionHistory
test_case.invocations: randomUUID mock mock mock mock add add add setAvailable thenReturn when get thenReturn when getLastVersion thenReturn when get thenReturn when getEventsAfterUntil get get verify get verify getLastVersion verify times thenReturn when apply any apply verify any getEventsAfterUntil verify assertThat getVersion is getAggregateInstance assertThat getAvailable is
test_case.modifiers: @SuppressWarnings({"unchecked" }) @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void snapshotNotUpToDateWithTransactionHistory()
focal_class.declarator: aggregateRootHistoryMap
focal_class.modifier: private final
focal_class.original_string: private final Map<K, AggregateRootHistory> aggregateRootHistoryMap ;
focal_class.type: Map<K, AggregateRootHistory>
focal_class.var_name: aggregateRootHistoryMap
focal_class.declarator: lastSnapshotMap
focal_class.modifier: private final
focal_class.original_string: private final Map<K, Snapshot<A>> lastSnapshotMap ;
focal_class.type: Map<K, Snapshot<A>>
focal_class.var_name: lastSnapshotMap
focal_class.declarator: newInstanceFactory
focal_class.modifier: private final
focal_class.original_string: private final Function<Void, A> newInstanceFactory ;
focal_class.type: Function<Void, A>
focal_class.var_name: newInstanceFactory
focal_class.file: myeslib-hazelcast/src/main/java/org/myeslib/hazelcast/storage/HzSnapshotReader.java
focal_class.identifier: HzSnapshotReader
focal_class.interfaces: implements SnapshotReader<K, A>
focal_class.class_method_signature: HzSnapshotReader.HzSnapshotReader(Map<K, AggregateRootHistory> aggregateRootHistoryMap,
  			Map<K, Snapshot<A>> lastSnapshotMap,
  			Function<Void, A> newInstanceFactory)
focal_class.full_signature: @Inject public  HzSnapshotReader(Map<K, AggregateRootHistory> aggregateRootHistoryMap,
  			Map<K, Snapshot<A>> lastSnapshotMap,
  			Function<Void, A> newInstanceFactory)
focal_class.identifier: HzSnapshotReader
focal_class.modifiers: @Inject public
focal_class.parameters: (Map<K, AggregateRootHistory> aggregateRootHistoryMap,
  			Map<K, Snapshot<A>> lastSnapshotMap,
  			Function<Void, A> newInstanceFactory)
focal_class.signature:  HzSnapshotReader(Map<K, AggregateRootHistory> aggregateRootHistoryMap,
  			Map<K, Snapshot<A>> lastSnapshotMap,
  			Function<Void, A> newInstanceFactory)
focal_class.class_method_signature: HzSnapshotReader.get(final K id)
focal_class.full_signature: public Snapshot<A> get(final K id)
focal_class.identifier: get
focal_class.modifiers: public
focal_class.parameters: (final K id)
focal_class.return: Snapshot<A>
focal_class.signature: Snapshot<A> get(final K id)
focal_class.class_method_signature: HzSnapshotReader.getEventsOrEmptyIfNull(final K id)
focal_class.full_signature: private AggregateRootHistory getEventsOrEmptyIfNull(final K id)
focal_class.identifier: getEventsOrEmptyIfNull
focal_class.modifiers: private
focal_class.parameters: (final K id)
focal_class.return: AggregateRootHistory
focal_class.signature: AggregateRootHistory getEventsOrEmptyIfNull(final K id)
focal_class.class_method_signature: HzSnapshotReader.applyAllEventsOnFreshInstance(final AggregateRootHistory transactionHistory, 
  													  final A aggregateRootFreshInstance)
focal_class.full_signature: private Snapshot<A> applyAllEventsOnFreshInstance(final AggregateRootHistory transactionHistory, 
  													  final A aggregateRootFreshInstance)
focal_class.identifier: applyAllEventsOnFreshInstance
focal_class.modifiers: private
focal_class.parameters: (final AggregateRootHistory transactionHistory, 
  													  final A aggregateRootFreshInstance)
focal_class.return: Snapshot<A>
focal_class.signature: Snapshot<A> applyAllEventsOnFreshInstance(final AggregateRootHistory transactionHistory, 
  													  final A aggregateRootFreshInstance)
focal_class.class_method_signature: HzSnapshotReader.applyEventsSinceLastSnapshot(final AggregateRootHistory transactionHistory,
  													 final Snapshot<A> lastSnapshot)
focal_class.full_signature: private Snapshot<A> applyEventsSinceLastSnapshot(final AggregateRootHistory transactionHistory,
  													 final Snapshot<A> lastSnapshot)
focal_class.identifier: applyEventsSinceLastSnapshot
focal_class.modifiers: private
focal_class.parameters: (final AggregateRootHistory transactionHistory,
  													 final Snapshot<A> lastSnapshot)
focal_class.return: Snapshot<A>
focal_class.signature: Snapshot<A> applyEventsSinceLastSnapshot(final AggregateRootHistory transactionHistory,
  													 final Snapshot<A> lastSnapshot)
focal_method.body: public Snapshot<A> get(final K id) {
  		checkNotNull(id);
  		final A aggregateRootFreshInstance = newInstanceFactory.apply(null);
  		final AggregateRootHistory transactionHistory = getEventsOrEmptyIfNull(id);
  		final Long lastVersion = transactionHistory.getLastVersion();
  		final Snapshot<A> lastSnapshot = lastSnapshotMap.get(id);
  		final Snapshot<A> resultingSnapshot;
  		if (lastSnapshot==null){
  			resultingSnapshot = applyAllEventsOnFreshInstance(transactionHistory, aggregateRootFreshInstance);
  		} else {
  			if (lastSnapshot.getVersion() < lastVersion) {
  				resultingSnapshot = applyEventsSinceLastSnapshot(transactionHistory, lastSnapshot);
  			} else {
  				resultingSnapshot = lastSnapshot;
  			}
  		}
  		return resultingSnapshot;
  	}
focal_method.class_method_signature: HzSnapshotReader.get(final K id)
focal_method.full_signature: public Snapshot<A> get(final K id)
focal_method.identifier: get
focal_method.invocations: checkNotNull apply getEventsOrEmptyIfNull getLastVersion get applyAllEventsOnFreshInstance getVersion applyEventsSinceLastSnapshot
focal_method.modifiers: public
focal_method.parameters: (final K id)
focal_method.return: Snapshot<A>
focal_method.signature: Snapshot<A> get(final K id)