Assessment is failing. I didn't hardcode anything, and I have checked for all exceptions

I have not hardcoded anything and I have handled all the cases related to invalid dates, NullPointer exceptions etc. But still my assessment is failing.
Please look into my code @ajay-crio
Please help :sweat:

What are doing when end date is less tha start date?

I am throwing RunTimeException after checking inside if block that is the end date is before start date

This is the unit test log

Hey , it’s not about hardcoding any values, after going through your workspace, I found that, there is an logical error in your code for comparing buydate is after send date, can you check again?

1 Like

Sir but I think that is what we have to handel. That if the purchaseDate(buyDate) is after endDate then we have to throw Exception.
Sir please tell me if I am wrong.

From you code right now, you have used the opposite conditon , you are throwing when the buy date is lesser than endDate

1 Like

Hey for each stock you only have to make an API call once, Understand the task here, you can get the buy price and the sell price in a single call.
Hint: You buyPrice is the first element and your sell price is the last element :slight_smile:

1 Like

Sir I am getting very much frustrated.
According to your reply, I tried to change the condition by applying not(!) operator for reversing the condition. But not my code is not even building.
I don’t know what to do :sweat:

Ok sir I am implementing it

Hey, you are on the right track, depending upon your code, you have logical errors, as far as I can see,
You had given a condition for buyPrice is before selling price . raise an exception, it’s obvious it will not build, understand the task at hand here.

1 Like

Sir , I am also facing same issue . My (custom) invalid date test case is also passing but finally getting build failure.

You can use the concept of localdates to subtract 2 dates here, you do not have do much complex calculations

1 Like

Sir one last question. We have to do the same thing in invalid dates, & invalid stocks also. Throw Exception and handle them?

^The above reply was for the 2nd user.
You have to handle the case where an InvalidDate is not there with the latest Date,

1 Like

I am handling the dates by two cases-

  1. If the end date is before buy date then exception
  2. If the end date is after today’s date or after the latest date of stock detail present in the api, in this case fetch the latest stock record.

Is there any other cases (invalid stock names) or just date? Also is my approach right?

Read the TODO’s and understand the task, solve your logical errors and your task is done


Sir , I think that calculation is not causing problem because I have checked it by passing several test cases. But still I am getting assessment failure . And also unit log file says nothing except ‘build failure’ .