Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

andThen support after condition has been evaluated? #68

Closed
pbromley opened this issue Dec 15, 2016 · 4 comments
Closed

andThen support after condition has been evaluated? #68

pbromley opened this issue Dec 15, 2016 · 4 comments

Comments

@pbromley
Copy link

Apologies if I'm coming at this from the wrong angle but is there any support (or direction of how i should do this) for running some code after the condition has been evaluated to true e.g. my current code is as follows

await().atMost(5, SECONDS).until(() -> someList.size(), is(equalTo(1))

is there any support for something like

await().atMost(5, SECONDS).until(() -> someList.size(), is(equalTo(1)).andThen(() -> assertThat(someList.get(0), is(equalTo("hello")))

so I know there is definitely 1 message, now I can do more assertions on the contents of the list

@johanhaleby
Copy link
Collaborator

Hi,

Would this be enough?

List<String> someList = await().atMost(5, SECONDS).until(() -> someList, hasSize(1)));
assertThat(someList.get(0), is(equalTo("hello"))

/Johan

@pbromley
Copy link
Author

i thought it might be, but await() doesn't seem to block so the assertThat would get evaluated too soon.

I was just about to answer my own question with this

await().atMost(5, SECONDS).until(() -> {
    assertThat(someList.size(), is(equalTo(1)));
    assertThat(someList.get(0), is(equalTo("hello")));
})

That seems to run assertThat(someList.size(), is(equalTo(1))) for at most 5 seconds before moving onto the next line (probably due to an assertionError being thrown)

@pbromley
Copy link
Author

pbromley commented Dec 15, 2016

whoops - you are right - some dodgy logic in my code meant the next bit of code ran after the await() blocked but didn't report correctly.

Apologies - close this and ignore me ;)

Thanks for your quick replies

@johanhaleby
Copy link
Collaborator

No problem, thanks for using the library :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants