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

empty elementOfJsonPath #343

Merged
merged 9 commits into from
Sep 14, 2020
Merged

Conversation

vegterb
Copy link
Contributor

@vegterb vegterb commented Sep 7, 2020

return null with empty elementOfJsonPath

@vegterb vegterb changed the title emptyElementOfJsonPath empty elementOfJsonPath Sep 7, 2020
@fhoeben
Copy link
Owner

fhoeben commented Sep 8, 2020

Looks good. Would you mind adding a test?

@vegterb
Copy link
Contributor Author

vegterb commented Sep 8, 2020

JsonFixtureTest Class & two tests added

Copy link
Owner

@fhoeben fhoeben left a comment

Choose a reason for hiding this comment

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

Looks good. A few minor points to finish it I believe

vegterb and others added 3 commits September 10, 2020 09:45
Suggested changes fhoeben

Co-authored-by: Fried Hoeben <github@hsac.nl>
Retry commit batch review changes fhoeben

Co-authored-by: Fried Hoeben <github@hsac.nl>
@vegterb
Copy link
Contributor Author

vegterb commented Sep 10, 2020

@fhoeben changes made, thanks for the feedback.

@fhoeben
Copy link
Owner

fhoeben commented Sep 10, 2020

Just remembered JsonHttpTest: has its own handling (if only Java had mixins) of getting elements. Please make the same change there.
Sorry for not mentioning it earlier...

Created mocked tests in JsonHttpTestTest
Changed tests in JsonFixtureTest to mocked tests
@vegterb
Copy link
Contributor Author

vegterb commented Sep 10, 2020

@fhoeben as per your comment I updated JsonHttpTest but got a bit stuck on the unit test in JsonHttpTestTest, my girlfriend suggested Mockito, which was already part of your project so I also updated the JsonFixtureTest. Let me know what you think.

@fhoeben
Copy link
Owner

fhoeben commented Sep 10, 2020

Although I really like mockito, I try to keep away from using spies as much as possible as they tend to couple your test too tightly to the implementation. Instead I suggest you take a look at wiki/FitNesseRoot/HsacAcceptanceTests/SlimTests/HttpTest/JsonHttpTest.wiki line 30, I believe adding one line there to check element 2 would be the easiest way to test the changed behaviour (line 30 tests the behaviour when the element is present)

@vegterb
Copy link
Contributor Author

vegterb commented Sep 10, 2020

I could of course not use the spy implementation and just use a mock for the HttpResponse class and keep using all the methodes within the 'JsonHttpTest' class. It's you're call... mock or revert and use:
|check |element |2 |of json path|airplanes[?(@.airline=='KLM')].type|null|
is also no problem.

I will revert the changes in the 'JsonFixtureTest'.

@vegterb
Copy link
Contributor Author

vegterb commented Sep 10, 2020

It's an interesting thought though as with a spy I would isolate the specific method and I'm not dependent on changes in other methods. Isn't the FitNesse test therefore not more dependent on the implementation?

@fhoeben
Copy link
Owner

fhoeben commented Sep 10, 2020

I would prefer |check |element |2 |of json path|airplanes[?(@.airline=='KLM')].type|null|

The spy indeed isolates the specific method, but that method is the implementation detail. The FitNesse test checks the behaviour of the class given a certain response from the remote server, it's completely decoupled from how the fixture arrives at that response. So JsonHttpTest could be completely refactored (for instance by delegating to JsonFixture, or even rewriting it in Kotlin) and the test needs no change: it still verifies whether the correct response is given.

Added check null test to JsonHttpTest.wiki
@vegterb
Copy link
Contributor Author

vegterb commented Sep 14, 2020

@fhoeben all changes made, should be good now.

Copy link
Owner

@fhoeben fhoeben left a comment

Choose a reason for hiding this comment

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

Looks good. One minor thing left

@fhoeben fhoeben merged commit 6d66e53 into fhoeben:master Sep 14, 2020
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.

2 participants