Java Optional List and Cassandra - Passing Array to Optional List

by ananth reddy   Last Updated March 14, 2019 20:26 PM

I have a Java Repository class with a method to get the values from DB.

@Query("Select * from r_t_status where status IN (:status) ALLOW FILTERING")
public Optional<List<RTStatusEntity>> findAllByStatus(@Param("status") List<String> status);

I have written the following JUnit test case for the above method.

@Test
    public void testfindAllByStatus() {
        saveEntity();//mocking db entity
        Optional<List<RTEntity>> entity = rTStatusRepository
                .findAllByStatus(Arrays.asList("TEST_STATUS1"));
        assertNotNull(entity);
        assertEquals(1, entity.get().size());
}

private void saveEntity() {
rTStatusRepository.save(RepoTestUtils.getRTStatusEntity(TEST_TRACE1, TEST_TIME1, TEST_REQUESTID1,
TEST_CLIENTID1, TEST_SESSIONTOKEN1, TEST_STATUS1, TEST_TARGETDEVICEID1, TEST_TID1));
}

Expected Behavior: Test case should return success. Actual Behavior: Test case fails and throws an assertion error.expected:<1> but was:<0> not sure why.

Is there anything wrong that I'm doing here for the test to fail?



Related Questions


JUnit test always fails when comparing two objects

Updated August 17, 2016 08:11 AM



Java8 : stream findFirst result

Updated June 09, 2017 15:26 PM