OscarJohnson6 / IndieProject

0 stars 0 forks source link

Week 8 ready for review #6

Closed OscarJohnson6 closed 2 months ago

OscarJohnson6 commented 2 months ago

Hi, @pawaitemadisoncollege week 8 is complete.

apiUnitTests

pawaitemadisoncollege commented 2 months ago

Hi @OscarJohnson6 - You've done a lot of work consuming apis with java code!

I was curious about how to avoid having the generic List as the root element, so I tried this out and was able to create it such that there's a more meaningful java object as the root. It still has a list in it, but at least the object is somewhat meaningful.

Here is what I did:

I went to the API Ninjas site, found the Exercises service, and ran a request. Then I copied the entire response and ran it through the robo pojo generator - note that I gave the root object the name "Exercises", which gave me two classes: Exercises which has a list of ExercisesItem. I hope this helps you see how you can avoid having that List as the root.

CopiedThisEntireResponse

GeneratingPojos Pojos
OscarJohnson6 commented 2 months ago

Hi, @pawaitemadisoncollege I still got the error below when I tried that on the API ninjas response. error

The pojos/classes it generated are the same. pojos

Here is my unit test failing. testAndresponse

I searched on Google and found this StackOverflow article. The top reply said

JsonMappingException: out of START_ARRAY token exception is thrown by Jackson object mapper as it's expecting an Object {} whereas it found an Array [{}] in response. This can be solved by replacing Object with Object[] in the argument for geForObject("url",Object[].class).

Which I think follows the error I am having as the response from API Ninja is a collection of objects or [{}] but I have the readValue saying that it's an object for the ApiNinjaResult class. I was also thinking would it be less complex to just have it be an array instead of creating an object for a class that can only be an array? Because won't I end up doing this: ApiNinjaResult results = ninjasExercise.createApiResponse( "", "", "", "", 5); List<ApiNinjaResultItem> resultItems = results.getApiNinjaResult(); instead of: List<ApiNinjaResultItem> resultItems = ninjasExercise.createApiResponse( "", "", "", "", 5);

For the user accounts test I got (weightDao.getByPropertyEqual("user", idNumber) to work but since it was an object of the user instead of just the id number and I was sure how to tell it to get the user id because user.Id didn't work; I just changed to from getByPropertyEqual to getById.



Also to keep my response in one spot, when I tried running a coverage test on my HealthCalculations class I get No coverage results. I can't figure out why, when I looked at the configurations it wasn't any different than what I had in week 3's exercise which has the coverage results show up. One thing I tried was generating a unit test class from the HealthCalculations and copying my code but that also didn't have coverage results display. Here is a picture of the configuration settings: calculationCoverage

pawaitemadisoncollege commented 2 months ago

Hey Oscar, I poked around at this too and found the same thing you did with the array. Sorry I sent you down a rabbit hole there! I'm learning too :)

I am not sure about the coverage issue, but this might be a dialog to check:

Screenshot 2024-03-16 at 5 59 00 PM
OscarJohnson6 commented 2 months ago

Hi, I got my coverage results to show. I modified the coverage config to include the HealthCalculations class, but I am not sure why I needed to because I went back and checked week 3 and it works without it. I added tests for another user and got my coverage to be 100%. testCoverage

pawaitemadisoncollege commented 2 months ago

Awesome! Thanks for sending that on!