test_class.declarator: lastSnapshotMap
test_class.modifier: @Mock
test_class.original_string: @Mock
  	Map<UUID, Snapshot<InventoryItemAggregateRoot>> lastSnapshotMap ;
test_class.type: Map<UUID, Snapshot<InventoryItemAggregateRoot>>
test_class.var_name: lastSnapshotMap
test_class.declarator: newInstanceFunction
test_class.modifier: @Mock
test_class.original_string: @Mock
  	Function<Void, InventoryItemAggregateRoot> newInstanceFunction;
test_class.type: Function<Void, InventoryItemAggregateRoot>
test_class.var_name: newInstanceFunction
test_class.declarator: arReader
test_class.modifier: @Mock
test_class.original_string: @Mock
  	AggregateRootHistoryReaderDao<UUID> arReader ;
test_class.type: AggregateRootHistoryReaderDao<UUID>
test_class.var_name: arReader
test_class.file: myeslib-jdbi/src/test/java/org/myeslib/jdbi/storage/JdbiSnapshotReaderTest.java
test_class.identifier: JdbiSnapshotReaderTest
test_case.body: @Test
  	public void snapshotNotUpToDateWithTransactionHistory() {
  
  		UUID id = UUID.randomUUID();
  		
  		AggregateRootHistory transactionHistory = Mockito.mock(AggregateRootHistory.class);
  	
  		long firstVersion = 1;
  		long versionNotYetOnLastSnapshot = 2;
  		
  		List<Event> events = Arrays.asList((Event)new InventoryDecreased(id, 2));
  		
  		InventoryItemAggregateRoot aggregateInstance = new InventoryItemAggregateRoot();
  		aggregateInstance.setAvailable(3);
  		Snapshot<InventoryItemAggregateRoot> snapshotInstance = new Snapshot<>(aggregateInstance, firstVersion);
  	
  		when(transactionHistory.getLastVersion()).thenReturn(versionNotYetOnLastSnapshot);
  		when(lastSnapshotMap.get(id)).thenReturn(snapshotInstance);
  		when(transactionHistory.getEventsAfterUntil(firstVersion, versionNotYetOnLastSnapshot)).thenReturn(events);
  	
  		InventoryItemAggregateRoot freshInstance = new InventoryItemAggregateRoot();
  
  		JdbiSnapshotReader<UUID, InventoryItemAggregateRoot> st = new JdbiSnapshotReader<UUID, InventoryItemAggregateRoot>(lastSnapshotMap, arReader, newInstanceFunction);
  		
  		when(newInstanceFunction.apply(any(Void.class))).thenReturn(freshInstance);
  		when(arReader.get(id)).thenReturn(transactionHistory);
  
  		Snapshot<InventoryItemAggregateRoot> resultingSnapshot = st.get(id);
  		
  		verify(arReader).get(id);
  		verify(lastSnapshotMap).get(id);
  		verify(transactionHistory, times(2)).getLastVersion(); 
  		verify(transactionHistory).getEventsAfterUntil(firstVersion, versionNotYetOnLastSnapshot);
  		
  		assertThat(resultingSnapshot.getVersion(), is(versionNotYetOnLastSnapshot));
  		
  		InventoryItemAggregateRoot fromSnapshot = resultingSnapshot.getAggregateInstance();
  
  		assertThat(fromSnapshot.getAvailable(), is(1));
  
  	}
test_case.class_method_signature: JdbiSnapshotReaderTest.snapshotNotUpToDateWithTransactionHistory()
test_case.full_signature: @Test public void snapshotNotUpToDateWithTransactionHistory()
test_case.identifier: snapshotNotUpToDateWithTransactionHistory
test_case.invocations: randomUUID mock asList setAvailable thenReturn when getLastVersion thenReturn when get thenReturn when getEventsAfterUntil thenReturn when apply any thenReturn when get get get verify get verify getLastVersion verify times getEventsAfterUntil verify assertThat getVersion is getAggregateInstance assertThat getAvailable is
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void snapshotNotUpToDateWithTransactionHistory()
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: arReader
focal_class.modifier: private final
focal_class.original_string: private final AggregateRootHistoryReaderDao<K> arReader ;
focal_class.type: AggregateRootHistoryReaderDao<K>
focal_class.var_name: arReader
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-jdbi/src/main/java/org/myeslib/jdbi/storage/JdbiSnapshotReader.java
focal_class.identifier: JdbiSnapshotReader
focal_class.interfaces: implements SnapshotReader<K, A>
focal_class.class_method_signature: JdbiSnapshotReader.JdbiSnapshotReader(
  			Map<K, Snapshot<A>> lastSnapshotMap,
  			AggregateRootHistoryReaderDao<K> arReader,
  			Function<Void, A> newInstanceFactory)
focal_class.full_signature: @Inject public  JdbiSnapshotReader(
  			Map<K, Snapshot<A>> lastSnapshotMap,
  			AggregateRootHistoryReaderDao<K> arReader,
  			Function<Void, A> newInstanceFactory)
focal_class.identifier: JdbiSnapshotReader
focal_class.modifiers: @Inject public
focal_class.parameters: (
  			Map<K, Snapshot<A>> lastSnapshotMap,
  			AggregateRootHistoryReaderDao<K> arReader,
  			Function<Void, A> newInstanceFactory)
focal_class.signature:  JdbiSnapshotReader(
  			Map<K, Snapshot<A>> lastSnapshotMap,
  			AggregateRootHistoryReaderDao<K> arReader,
  			Function<Void, A> newInstanceFactory)
focal_class.class_method_signature: JdbiSnapshotReader.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: JdbiSnapshotReader.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: JdbiSnapshotReader.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: JdbiSnapshotReader.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: JdbiSnapshotReader.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)