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

Validate that no conditionals appear inside expectation recording block #97

Closed
rliesenfeld opened this Issue Nov 6, 2014 · 3 comments

Comments

2 participants
@rliesenfeld
Member

rliesenfeld commented Nov 6, 2014

For verification blocks, conditionals need to be allowed in assertions, at least.

@rliesenfeld rliesenfeld self-assigned this Nov 6, 2014

@topsy-turvy

This comment has been minimized.

Show comment
Hide comment
@topsy-turvy

topsy-turvy Jan 20, 2015

Hello. I have the following code

new StrictExpectations(accountInfoUpdater) {
        {
            for (int i = 0; i < squadRequests.length; ++i) {
                accountInfoUpdater.updateAccountInfo(squadRequests[i]);
            }
        }
    };

It checks that 'updateAccountInfo' was called for each squadRequests member. I'm not sure I understand how it should look like now. Could you assist?

topsy-turvy commented Jan 20, 2015

Hello. I have the following code

new StrictExpectations(accountInfoUpdater) {
        {
            for (int i = 0; i < squadRequests.length; ++i) {
                accountInfoUpdater.updateAccountInfo(squadRequests[i]);
            }
        }
    };

It checks that 'updateAccountInfo' was called for each squadRequests member. I'm not sure I understand how it should look like now. Could you assist?

@rliesenfeld

This comment has been minimized.

Show comment
Hide comment
@rliesenfeld

rliesenfeld Jan 20, 2015

Member

I would probably capture the arguments passed in multiple calls to "updateAccountInfo" into a List, then check the contents of the list afterwards:

final List<AccountInfo> updatedSquadRequests = new ArrayList<>();
new Expectations() {{
    accountInfoUpdater.updateAccountInfo(withCapture(updatedSquadRequests));
}};
// call SUT
assertArrayEquals(asList(squadRequests), updatedSquadRequests);

Even better, use a verification block (unless partial mocking of "accountInfoUpdater" really is needed):

// call SUT

new Verifications() {{
    List<AccountInfo> updatedSquadRequests = new ArrayList<>();
    accountInfoUpdater.updateAccountInfo(withCapture(updatedSquadRequests));
    assertArrayEquals(asList(squadRequests), updatedSquadRequests);
}};
Member

rliesenfeld commented Jan 20, 2015

I would probably capture the arguments passed in multiple calls to "updateAccountInfo" into a List, then check the contents of the list afterwards:

final List<AccountInfo> updatedSquadRequests = new ArrayList<>();
new Expectations() {{
    accountInfoUpdater.updateAccountInfo(withCapture(updatedSquadRequests));
}};
// call SUT
assertArrayEquals(asList(squadRequests), updatedSquadRequests);

Even better, use a verification block (unless partial mocking of "accountInfoUpdater" really is needed):

// call SUT

new Verifications() {{
    List<AccountInfo> updatedSquadRequests = new ArrayList<>();
    accountInfoUpdater.updateAccountInfo(withCapture(updatedSquadRequests));
    assertArrayEquals(asList(squadRequests), updatedSquadRequests);
}};
@topsy-turvy

This comment has been minimized.

Show comment
Hide comment
@topsy-turvy

topsy-turvy Jan 21, 2015

Thank you rliesenfeld,

The first sample with Expectations works.

topsy-turvy commented Jan 21, 2015

Thank you rliesenfeld,

The first sample with Expectations works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment