Skip to content

Overriding then() #20

@nbarrett

Description

@nbarrett

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions