FlagsFactory { public static Builder builder() { return new Builder(); }  static Flags createFlags(MailboxMessage mailboxMessage, String[] userFlags); static Builder builder(); static Flags empty();  }
@Test void builderShouldAllowEmptyFactory() { assertThat(FlagsFactory.builder().build()).isEqualTo(emptyFlags); }
@Test void builderShouldNotRequireFlagsInstanceWhenUserFlagsDefined() { Flags actual = FlagsFactory.builder().addUserFlags("userFlag").build(); assertThat(actual.getUserFlags()).containsOnly("userFlag"); }
@Test void builderShouldNotRequireUserFlagsWhenFlagsInstanceDefined() { assertThat(FlagsFactory.builder().flags(new Flags()).build()).isNotNull(); }
@Test void builderShouldAcceptNullUserFlags() { assertThat( FlagsFactory.builder() .addUserFlags((String)null) .build()) .isEqualTo(new Flags()); }
@Test void builderShouldFilterUserFlags() { Flags actual = FlagsFactory.builder() .flags(someFlags) .filteringFlags( FlagsFilter .builder() .userFlagFilter(f -> f.equals("soCool")) .build()) .build(); assertThat(actual.getUserFlags()).containsOnly("soCool"); }
@Test void builderShouldFilterSystemFlags() { Flags actual = FlagsFactory.builder() .flags(someFlags) .filteringFlags( FlagsFilter .builder() .systemFlagFilter(f -> f.equals(Flag.SEEN)) .build()) .build(); assertThat(actual.getSystemFlags()).containsOnly(Flag.SEEN); }
@Test void builderShouldAllowFilteringOnEmptyFlags() { Flags actual = FlagsFactory.builder() .flags(emptyFlags) .filteringFlags( FlagsFilter .builder() .systemFlagFilter(f -> f.equals(Flag.SEEN)) .userFlagFilter(f -> f.equals("soCool")) .build()) .build(); assertThat(actual).isNotNull(); }
@Test void builderShouldFilterOnFlags() { Flags actual = FlagsFactory.builder() .flags(someFlags) .filteringFlags( FlagsFilter .builder() .systemFlagFilter(f -> f.equals(Flag.SEEN)) .userFlagFilter(f -> f.equals("soCool")) .build()) .build(); assertThat(actual.getSystemFlags()).containsOnly(Flag.SEEN); assertThat(actual.getUserFlags()).containsOnly("soCool"); }
@Test void builderShouldTrimEmptyUserFlags() { Flags flags = new Flags(); flags.add(""); flags.add("value2"); Flags actual = FlagsFactory.builder().flags(flags).addUserFlags("", "value").build(); assertThat(actual.getUserFlags()).containsOnly("value", "value2"); }
@Test void builderShouldTrimNullUserFlags() { Flags actual = FlagsFactory.builder().addUserFlags(null, "value").build(); assertThat(actual.getUserFlags()).containsOnly("value"); }