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

Adding a test for the null pointer exception I ran across today. #4

Merged

Conversation

berlin-ab
Copy link
Contributor

Should the constructor take another argument, or should the constructor
be more defensive?

Should the constructor take another argument, or should the constructor
be more defensive?
@Crisfole
Copy link
Contributor

Hey Adam, was this NPE from having an null in the custom field? I have a fix for that in place.

My goal was to have all constructors work as is...I'll go test that locally.

@berlin-ab
Copy link
Contributor Author

Yep, that's the one. We also found another NPE when calling #log. I can file a separate test for that if you'd like.

try {
new Rollbar("some-access-token", "some-environment");
} catch (NullPointerException e) {
exceptionDidHappen = true;
Copy link
Contributor

Choose a reason for hiding this comment

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

You can just use fail() here, and then drop the exceptionDidHappen field.

Also you might be better off with:

Rollbar r = new Rollbar("Some access token", "environment name");
pass();

The uncaught error will propagate up and will display better in the test panels/command line. (Because it will include the exception stack trace).

@Crisfole
Copy link
Contributor

@berlin-ab Please do file the other test! This is a new library that I'm really excited about, but it needs some battle hardening.

@berlin-ab
Copy link
Contributor Author

I wanted to make the intention of the test clear and I wasn't sure that raising the exception would do that. I'll try out fail() and see how I feel about it.

@berlin-ab
Copy link
Contributor Author

Thanks for making this library. I've used Rollbar on other projects in different languages, and I was disappointed to not find something more stable for Java. I'm happy to help.

@Crisfole
Copy link
Contributor

@berlin-ab I've also got some hamcrest test utilities already present. You can probably find something like 'doesNotThrow' (maybe).

@Crisfole
Copy link
Contributor

Better yet, you could probably just create a testContructorWorks test:

Rollbar r = new Rollbar("at", "env");
assertEqual("at", r.accessToken());
assertEqual("env", r.environment());

To explain my hesitation: By having sufficient coverage (and ensuring we've run through at least all the functions/constructors) we can get a full stack trace for any uncaught exceptions, without ever having to explicitly test that a particular call doesn't throw.

Make sense?

@berlin-ab
Copy link
Contributor Author

Ok, updated with production code.

Side note, I'm not exactly sure what custom means for this variable. Can you think of another name that is more descriptive?

}

private LinkedHashMap<String, Object> defaultCustom() {
return new LinkedHashMap<String, Object>();
Copy link
Contributor

Choose a reason for hiding this comment

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

In this case the 'defaultCustom' would actually need to be null, which would cause it to be skipped in the serializer.

@Crisfole
Copy link
Contributor

In this case there's literally nothing more descriptive since it contains all the "custom" data you want to send. Literally whatever you want.

Grep for "custom" in here: https://rollbar.com/docs/api/items_post/

@berlin-ab
Copy link
Contributor Author

Ok, I've pushed a new commit that allows custom to be nil and just calls the copy constructor.

@Crisfole
Copy link
Contributor

You rock. I'm going to pull this, run the tests, and merge it in, thanks.

@Crisfole
Copy link
Contributor

And then I'm going to hook up travis...

@berlin-ab
Copy link
Contributor Author

Great, thanks!

@Crisfole Crisfole merged commit aabd410 into rollbar:master Apr 14, 2016
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.

None yet

2 participants