Skip to content

Add Tests #22

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

Open
wants to merge 17 commits into
base: develop
Choose a base branch
from
Open

Add Tests #22

wants to merge 17 commits into from

Conversation

lbkehlmann
Copy link

Adds tests. Increases test coverage from 30% to 70% 😸 See https://coveralls.io/r/toopher/toopher-java

lbkehlmann and others added 16 commits June 4, 2014 11:12
It was difficult to test ToopherAPI because ToopherAPI#authenticate
instantiated AuthenticationStatus objects. It's now possible to provide
an AuthenticationStatusFactory to ToopherAPI.

To facilitate optional arguments to ToopherAPI, there's now a ToopherAPI
builder that all of the existing constructors dump their arguments into,
and a ToopherAPI constructor which takes a ToopherAPI.Builder.

There's a mock factory and an example test (that should be renamed or
removed) that demonstrates the use of these new classes.
* feature/builders:
  Add factories and builders all over the places

Conflicts:
	src/test/java/com/toopher/TestToopherAPI.java
}

public Builder setTerminalNameExtra(String terminalNameExtra) {
return addExtra("terminal_name_extra", terminalNameExtra);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not check for null and not empty for this and the following property?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is code from ToopherAPI that I refactored to use builders and factories. There wasn't a null check in the original code and I didn't want to add a null check for fear of changing the behavior, since we didn't have tests around it.

@coveralls
Copy link

Coverage Status

Coverage increased (+24.32%) when pulling e4b2f65 on authenticateTest into 2c1b483 on develop.

this.reason = reason;
this.terminalId = terminalId;
this.terminalName = terminalName;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What would the json parameter contain in this case? Without reviewing the code more thoroughly this method seems like it would simply create an object from json then set the same properties again.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

json is the JSONObject, like AuthenticationStatus#_raw_data (or whatever) in toopher-python. Off the top of my head, the only thing that the call to super does is save json as an instance variable.

toopherApi.authenticate(pairingId, terminalName);
} catch(RequestError re){
assertTrue(true);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like people prefer to put the failure under the method that should throw an exception. See http://stackoverflow.com/a/156868/553403

try {
    toopherApi.authenticate(pairingId, terminalName);
    fail("My method didn't throw when I expected it to");
} catch(RequestError re){
    assertTrue(true);
}

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A test without any assertions passes, so

  1. without a call to fail, this test doesn't actually test anything, and
  2. assertTrue(true) is unnecessary.

@trdarr
Copy link

trdarr commented Jun 13, 2014

I'm glad that toopher-java is getting some much-needed attention!

I'd like to see this pull request made a bit more consistent before it's merged. @smholloway pointed out some formatting issues, and hinted that the style of the tests changes from the first test to the last, since you refactored HttpClientMock and I refactored ToopherAPI as you were writing writing them. For example, later tests

  1. use the builders and factories;
  2. use the Map<URI, ResponseMock> HttpClientMock constructor; and
  3. assert that data was sent to the HttpClient

while earlier tests don't. Not every test tests the same thing, so some of these might not be applicable in some cases, but many of them should be quite similar to each other.

.build();

try {
api.authenticate(PAIRING_ID, TERMINAL_NAME);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@smholloway Here's an example of using TERMINAL_NAME.

@coveralls
Copy link

Coverage Status

Coverage increased (+30.67%) when pulling 01b98a2 on authenticateTest into 2c1b483 on develop.

@egrim
Copy link
Member

egrim commented Jun 17, 2014

I'm really liking where this is headed - thanks to all the contributors!

@trdarr
Copy link

trdarr commented Nov 20, 2014

Rereading the conversation, I think this is good to merge. The things I pointed out don’t invalidate this pull request and can be implemented as future work, but +30% test coverage!

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

Successfully merging this pull request may close these issues.

5 participants