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

Overriding then() #20

Open
nbarrett opened this issue May 6, 2015 · 1 comment
Open

Overriding then() #20

nbarrett opened this issue May 6, 2015 · 1 comment

Comments

@nbarrett
Copy link

nbarrett commented May 6, 2015

Hi again yatspeccers,

I have a question regarding then(), which is implemented with a single method signature in TestState.java as follows:

public <ItemOfInterest> TestState then(StateExtractor<ItemOfInterest> extractor, Matcher<? super ItemOfInterest> matcher) throws Exception {
    assertThat(extractor.execute(capturedInputAndOutputs), matcher);
    return this;
}

As I understand, in order to use then(), I have to supply a StateExtractor typed first argument, which makes sense in a simple scenario where I want to get a piece of state from the application and then do a straightforward assertion on it e.g.

then(theLoginLinkDisplay(), is(false))

However in the tests I'm writing, I find that I want to do quite a few assertions and I don't necessarily want to pass them all declaratively in the test narrative either, I just want to do all them all 'under the hood' and report back any match failures. e.g.

then(theLogin(), isSuccessfulAndAllDetailsOfMyAccountIsDisplayed());

In the above, isSuccessfulAndAllDetailsOfMyAccountIsDisplayed() is a self contained matcher which has access to multiple bits of application state and doesn't even refer to the state returned by theLogin() which is only reallly there to satisfy the method signature.

So what it seems that what I need is a then() that takes just a single matcher argument that does all of the end-point assertion work. Is this a crazy Idea and/or am I missing the point here?

Thanks in advance,
Nick

@dtandersen
Copy link

I've seen a couple of examples where a method named thenTheLoginIsSuccessfulAndAllDetailsOfMyAccountIsDisplayed() is used instead of then().

If you want to use then() you could also make a object that encapsulates the details you are interested in and passes it to the Hamcrest matcher.

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