2 test Failed in ./gradlew build

In build I get two test failed -

com.crio.warmup.stock.portfolio.PortfolioManagerTest > calculateExtrapolatedAnnualizedReturn() FAILED
    org.mockito.exceptions.base.MockitoException

com.crio.warmup.stock.portfolio.PortfolioManagerPerformanceTest > calculateExtrapolatedAnnualizedReturn() FAILED
    org.mockito.exceptions.base.MockitoException

I tried to find out the reason but cant find out. There is the following code -

List<String> symbols = annualizedReturns.stream().map(AnnualizedReturn::getSymbol)

        .collect(Collectors.toList());

    Assertions.assertEquals(0.814, annualizedReturns.get(0).getAnnualizedReturn(), 0.01);

    Assertions.assertEquals(0.584, annualizedReturns.get(1).getAnnualizedReturn(), 0.01);

    Assertions.assertEquals(0.33, annualizedReturns.get(2).getAnnualizedReturn(),0.01);

    Assertions.assertEquals(Arrays.asList(new String[]{"AAPL", "MSFT", "GOOGL"}), symbols);

According to previous modules we implemented logic to get sorted list of AnnualizedReturns and I also implemented the exception properly, but I cant understand why these test failed.
@gouravsardana, @chandra-kiran_crio, @Sakshat-Crio.Do, @chandra-kiran_crio

@gouravsardana Sir, I cant resolved the problem please help.

Hey @Soumyadip,

First, add some breakpoints and check if your code is actually returning the right list with the all the data.

If that’s the case, then check if your list contains elements only within the given date range. My guess is that you are returning all objects returned by the API, even ones not lying in given startDate and endDate.

Let me know if it helps!

Heyy !
Set some breakpoints and run the tests in the debug mode. Spend some time in verifying the value of each and every variables in the class during the tests running in the debug mode.

Hey, sorry for a late reply from our side, Make sure you are completing the whole process of calculating the annualized returns within 6 seconds,
You can refer to the tip attached below the Taskboard for understanding how async calls work in java.

@Soumyadip

Let me give you a brief on what is happening with your code.

You need to make sure that the tests need to pass in the specified time limit as @Rahul-Crio.do has suggested, but its a secondary thing.

The Primary thing is, as you’re getting the method failed error, probably the data is not flowing into the call() method, for this you can do the following steps

1: Put the specific breakpoints in your Test file.

2: After that make sure that you’re also making some breakpoints in [ PortfolioManagerImpl.java ] file.

3: See whether the call() method is getting the data or not.

I was also stuck on this issue, as I wasn’t getting the data inside that function, and It got solved by debugging with breakpoints.

But after that, I faced the timelimit exceeding exceptions, for resolving that, I used the following tutorial.

Links

Link 1: https://www.youtube.com/watch?v=6Oo-9Can3H8&list=PLhfHPmPYPPRk6yMrcbfafFGSbE2EPK_A6&index=5

Link 2: https://www.youtube.com/watch?v=mGjlWrhhNF0&list=PLZkgjBpLveVTz629oAvG5_N7RRc0kLX1Y

Hope it’ll help, keep going :running_man:

2 Likes

Thanks to all I already solved the problem.

Closing this topic as your issue has been resolved by the community.