@Test
void properRankingOfRatings() {

    final int targetShareA = 1;
    final int targetShareB = targetShareA * 5;
    final int targetShareC = targetShareB * 5;
    final ParsedStrategy parsed = new ParsedStrategy(new DefaultValues(DefaultPortfolio.EMPTY),
            asList(
                    new PortfolioShare(Rating.A, fromPercentage(targetShareA)),
                    new PortfolioShare(Rating.B, fromPercentage(targetShareB)),
                    new PortfolioShare(Rating.C, fromPercentage(targetShareC))),
            Collections.emptyMap(), Collections.emptyMap());
    // all ratings have zero share; C > B > A
    final Set<Rating> ratings = EnumSet.of(Rating.A, Rating.B, Rating.C);
    PortfolioOverview portfolio = preparePortfolio(BigDecimal.ZERO, BigDecimal.ZERO, BigDecimal.ZERO);
    assertOrder(Util.rankRatingsByDemand(parsed, portfolio), Rating.C, Rating.B, Rating.A);
    // A only; B, C overinvested
    portfolio = preparePortfolio(BigDecimal.ZERO, BigDecimal.valueOf(10), BigDecimal.valueOf(30));
    assertOrder(Util.rankRatingsByDemand(parsed, portfolio), Rating.A);
    // B > A > C
    portfolio = preparePortfolio(BigDecimal.valueOf(0.99), BigDecimal.ZERO, BigDecimal.valueOf(24.9));
    assertOrder(Util.rankRatingsByDemand(parsed, portfolio), Rating.B, Rating.A, Rating.C);
}