ApplicableFlagCalculator { public Flags computeApplicableFlags() { return ApplicableFlagBuilder.builder() .add(Iterators.toStream(mailboxMessages.iterator()) .map(MailboxMessage::createFlags) .collect(Guavate.toImmutableList())) .build(); } ApplicableFlagCalculator(Iterable<MailboxMessage> mailboxMessages); Flags computeApplicableFlags();  }
@Test void computeApplicableFlagsShouldReturnOnlyDefaultApplicableFlagsWhenNoMessage() { ApplicableFlagCalculator calculator = new ApplicableFlagCalculator(ImmutableList.<MailboxMessage>of()); assertThat(calculator.computeApplicableFlags()).isEqualTo(getDefaultApplicableFlag()); }
@Test void computeApplicableFlagsShouldReturnOnlyDefaultApplicableFlagWhenNoMessageWithUserCustomFlag() { List<MailboxMessage> mailboxMessages = ImmutableList.of( createMessage(new Flags(Flag.ANSWERED)), createMessage(new Flags(Flag.DELETED)), createMessage(new Flags(Flag.USER)), createMessage(new Flags(Flag.RECENT))); ApplicableFlagCalculator calculator = new ApplicableFlagCalculator(mailboxMessages); assertThat(calculator.computeApplicableFlags()).isEqualTo(getDefaultApplicableFlag()); }
@Test void computeApplicableFlagsShouldReturnOnlyDefaultApplicableFlagAndAllUserCustomFlagUsedOneMessage() { List<MailboxMessage> mailboxMessages = ImmutableList.of( createMessage(new Flags("capture me")), createMessage(new Flags("french"))); ApplicableFlagCalculator calculator = new ApplicableFlagCalculator(mailboxMessages); Flags expected = ApplicableFlagBuilder .builder() .add("capture me", "french") .build(); assertThat(calculator.computeApplicableFlags()).isEqualTo(expected); }
@Test void unionFlagsShouldAlwaysIgnoreRecentAndUser() { List<MailboxMessage> mailboxMessages = ImmutableList.of( createMessage(new Flags(Flag.RECENT)), createMessage(new Flags(Flag.USER))); ApplicableFlagCalculator calculator = new ApplicableFlagCalculator(mailboxMessages); Flags result = calculator.computeApplicableFlags(); SoftAssertions.assertSoftly(softly -> { softly.assertThat(result.contains(Flag.RECENT)).isFalse(); softly.assertThat(result.contains(Flag.USER)).isFalse(); }); }