简体   繁体   中英

AssertionError on assertThat on a list

I'm sending 2 rows of data from my cucumber feature file:

Scenario: Verify the data in the summary
    Then the 'Summary' section contains the following data:
     | Time Frame: 06/22/2016 20:47:22 UTC to 09/18/2016 17:00:53 UTC          |
     | Tabs: 47def , tr1 , e998                                                |

I'm trying to check that the data from each row of my feature file is found in the actual text that was pulled from the page:

public void sectionContainsTheFollowingData(String section, List<String> expected) {
    // text data pulled from the page is stored in 'actual'
    List<String> actual = SUMMARY.getSummaryData(section);
        for (String cell : expected) {
            assertThat(String.format("Did not find %s in data %s", cell, actual), actual.contains(cell));
        }

When I execute this I get the following error:

java.lang.AssertionError: Did not find Time Frame: 06/22/2016 20:47:22 UTC to 09/18/2016 17:00:53 UTC in data [Time Frame: 06/22/2016 20:47:22 UTC to 09/18/2016 17:00:53 UTC Tabs: 47def , tr1 , e998]

I'm not sure why I get this error. I can see that "Time Frame: 06/22/2016 20:47:22 UTC to 09/18/2016 17:00:53 UTC" is in both the actual and expected. I'm guessing that my assertion is looking for an exact match, but I don't want an exact match. I just need the text from each row of the data table in the feature file to be somewhere within the actual text pulled from the page.

With streams:

for (String cell : expected) {
    assertThat(String.format("Did not find %s in data %s", cell, actual), actual.stream().anyMatch(string -> string.contains(cell));
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM