@Test
public void verifyGetLatestAnalyticsTables()
{

    Program prA = createProgram( 'A' );
    Program prB = createProgram( 'B' );
    List<Program> programs = Lists.newArrayList( prA, prB );
    Date lastFullTableUpdate = new DateTime( 2019, 3, 1, 2, 0 ).toDate();
    Date lastLatestPartitionUpdate = new DateTime( 2019, 3, 1, 9, 0 ).toDate();
    Date startTime = new DateTime( 2019, 3, 1, 10, 0 ).toDate();
    AnalyticsTableUpdateParams params = AnalyticsTableUpdateParams.newBuilder().withStartTime( startTime )
        .withLatestPartition().build();
    List<Map<String, Object>> queryResp = Lists.newArrayList();
    queryResp.add( ImmutableMap.of( "dataelementid", 1 ) );
    when( systemSettingManager.getSystemSetting( SettingKey.LAST_SUCCESSFUL_ANALYTICS_TABLES_UPDATE ) )
        .thenReturn( lastFullTableUpdate );
    when( systemSettingManager.getSystemSetting( SettingKey.LAST_SUCCESSFUL_LATEST_ANALYTICS_PARTITION_UPDATE ) )
        .thenReturn( lastLatestPartitionUpdate );
    when( jdbcTemplate.queryForList( Mockito.anyString() ) ).thenReturn( queryResp );
    when( idObjectManager.getAllNoAcl( Program.class ) ).thenReturn( programs );
    List<AnalyticsTable> tables = subject.getAnalyticsTables( params );
    assertThat( tables, hasSize( 2 ) );
    AnalyticsTable tableA = tables.get( 0 );
    AnalyticsTable tableB = tables.get( 0 );
    assertThat( tableA, notNullValue() );
    assertThat( tableB, notNullValue() );
    AnalyticsTablePartition partitionA = tableA.getLatestPartition();
    AnalyticsTablePartition partitionB = tableA.getLatestPartition();
    assertThat( partitionA, notNullValue() );
    assertThat( partitionA.isLatestPartition(), equalTo( true ) );
    assertThat( partitionA.getStartDate(), equalTo( lastFullTableUpdate ) );
    assertThat( partitionA.getEndDate(), equalTo( startTime ) );
    assertThat( partitionB, notNullValue() );
    assertThat( partitionB.isLatestPartition(), equalTo( true ) );
    assertThat( partitionB.getStartDate(), equalTo( lastFullTableUpdate ) );
    assertThat( partitionB.getEndDate(), equalTo( startTime ) );
}