Test invalid stock is failing, tried every possibility

I have gone through the forum and added constraints for the following possibilities:

  1. args[1] is not provided: For this, I chose the endDate to be of today’s date

  2. startDate or endDate are not provided in the response array: I have chosen values the nearest to both the dates i.e, For startDate I have chosen arrayIndexValue of 0 and for endDate I have chosen arrayIndexValue of (array.length - 1).

  3. Handled all the NullPointer, ArrayOutOfBound, RunTimeExceptions

  4. Returning empty list after exception

  5. Sorted the data properly

  6. Ensured that there are no hardcoded values in the data

But still, after taking so many precautions. One test case mainCalculateReturnsInvalidStocks() is failing.
I have been stuck on this issue for 3 days. Tried everything. Please help me out.

I really want to enroll myself in Crio-Code Byte for this I need to finish the deadline.
@anand-crio @ajay-crio @sridherj-criodo @som @theIceman

OK… Check how your code is brhaving when you try to calculate the annualized returns for a stock that doesnt exist of the exchange - say ABCS1234. Does it throw a RuntimeException?

Ok so basically they are expecting runtime exception if you look closely so you have to explicitly throw runtime exception whenever you see the invalid dates issue

@Samyak_Jain You dont need to catch them in this module.

Yes sir @anand-crio @Samyak_Jain @som, I have made changes.
Now my code is throwing the RunTimeExeception and returning an empty list.
But still the test is not clearing.
Sir, please have a look at my code.

I just saw your code, I think the issue is resolved. Please let me know if the issue is still not been resolved. If the issue is resolved please mark any reply which led to the solution of the issue as solution.

@Saurav_Crio.Do @anand-crio Sir, I have tested two times.
Still the test case is failing. No change.

Please have a look again where I am doing wrong.

How can you do both things at the same time?

@anand-crio
I have thrown the RunTimeException from the getLatestQuotes function (which is intended to fetch the API results). Then I am catching the exception in mainCalculateSingleReturn function which returns the Empty List.

Is it not required to throw the EmptyList after raising the RuntimeException?

Have a look at my code sir: https://gitlab.crio.do/COHORT_ME_QMONEY_ENROLL_CRIO_LAUNCH_2020/devaljain1998-ME_QMONEY/commit/0b5245c72f7ee42a6a4e544b5f45572ad1fa7f1f

You just need to throw. no need to handle. remove that catch block.
We will deal with exception handling in later modules.

Solved the problem.
All the test cases passed.
Did the following changes:

  1. Raised RuntimeException when the API is not been fetching correctly.

  2. If the args[1] i.e the end date is not provided then raising the IllegalArugmentException

Thank You very much @anand-crio sir for helping me out with this. :smiley: :smiley: :smiley:

1 Like