-
Notifications
You must be signed in to change notification settings - Fork 75
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
Adding a test for the null pointer exception I ran across today. #4
Conversation
Should the constructor take another argument, or should the constructor be more defensive?
Hey Adam, was this NPE from having an null in the My goal was to have all constructors work as is...I'll go test that locally. |
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; |
There was a problem hiding this comment.
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).
@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. |
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 |
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. |
@berlin-ab I've also got some |
Better yet, you could probably just create a 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? |
Ok, updated with production code. Side note, I'm not exactly sure what |
} | ||
|
||
private LinkedHashMap<String, Object> defaultCustom() { | ||
return new LinkedHashMap<String, Object>(); |
There was a problem hiding this comment.
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.
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/ |
Ok, I've pushed a new commit that allows custom to be nil and just calls the copy constructor. |
You rock. I'm going to pull this, run the tests, and merge it in, thanks. |
And then I'm going to hook up travis... |
Great, thanks! |
Should the constructor take another argument, or should the constructor
be more defensive?