@Test
public void testRefreshWhenNewerVersionExists() throws FlowRetrievalException, FlowMapperException, SerializerException, FlowTransformException, IOException {

    final String className = "Test Class";
    final AtomicInteger refreshedCounter = new AtomicInteger(0);
    final FlowUri flowUri = new FlowUri("http://localhost:18080", "1234", "5678");
    when(flowMapper.getFlowMapping(className)).thenReturn(Optional.of(flowUri));
    final VersionedFlowSnapshot flowSnapshot = FlowTestUtils.createSnapshot(flowUri.getBucketId(), flowUri.getFlowId(), 2);
    when(flowRetrievalService.getLatestFlow(flowUri)).thenReturn(flowSnapshot);
    final FlowMappingEntity flowMappingEntity = FlowTestUtils.createFlowMappingEntity(className, flowUri, 1, "YAML");
    when(flowMappingRepository.findById(className)).thenReturn(Optional.of(flowMappingEntity));
    flowRefresherTask.refreshAgentClass(className, refreshedCounter);
    // should have refreshed from v1 to v2
    assertEquals(1, refreshedCounter.get());
}