@JsonCreator private static @Nonnull LiteralCommunityConjunction create( @JsonProperty(PROP_REQUIRED_COMMUNITIES) SortedSet<Long> requiredCommunities) { return new LiteralCommunityConjunction( firstNonNull(requiredCommunities, ImmutableSortedSet.of())); }
@Test public void testAsLiteralCommunities() { LiteralCommunityConjunction l = new LiteralCommunityConjunction(ImmutableSet.of(1L, 2L)); _thrown.expect(UnsupportedOperationException.class); l.asLiteralCommunities(null); }
@Test public void testMatchAnyCommunity() { LiteralCommunityConjunction l = new LiteralCommunityConjunction(ImmutableSet.of(1L, 2L)); _thrown.expect(UnsupportedOperationException.class); l.matchAnyCommunity(null, ImmutableSet.of(1L)); }
@Test public void testMatchCommunity() { LiteralCommunityConjunction l = new LiteralCommunityConjunction(ImmutableSet.of(1L, 3L)); _thrown.expect(UnsupportedOperationException.class); l.matchCommunity(null, 1L); }
@Test public void testMatchedCommunities() { LiteralCommunityConjunction l = new LiteralCommunityConjunction(ImmutableSet.of(1L, 3L)); _thrown.expect(UnsupportedOperationException.class); l.matchedCommunities(null, ImmutableSet.of(1L, 2L)); } }
private static CommunityListLine toCommunityListLine(StandardCommunityListLine sclLine) { Collection<Long> lineCommunities = sclLine.getCommunities(); CommunitySetExpr expr = lineCommunities.size() == 1 ? new LiteralCommunity(lineCommunities.iterator().next()) : new LiteralCommunityConjunction(lineCommunities); return new CommunityListLine(sclLine.getAction(), expr); }
@Test public void testEquals() { new EqualsTester() .addEqualityGroup( new LiteralCommunityConjunction(ImmutableSet.of(1L, 2L)), new LiteralCommunityConjunction(ImmutableSet.of(2L, 1L))) .addEqualityGroup(new LiteralCommunityConjunction(ImmutableSet.of(2L))) .testEquals(); }
@Test public void testMatchCommunities() { Set<Long> matchingCommunitySetCandidate1 = ImmutableSet.of(1L, 3L); Set<Long> matchingCommunitySetCandidate2 = ImmutableSet.of(1L, 2L, 3L); Set<Long> nonMatchingCommunitySetCandidate1 = ImmutableSet.of(1L); Set<Long> nonMatchingCommunitySetCandidate2 = ImmutableSet.of(3L); LiteralCommunityConjunction l = new LiteralCommunityConjunction(ImmutableSet.of(1L, 3L)); assertThat(l, matchCommunities(null, matchingCommunitySetCandidate1)); assertThat(l, matchCommunities(null, matchingCommunitySetCandidate2)); assertThat(l, not(matchCommunities(null, nonMatchingCommunitySetCandidate1))); assertThat(l, not(matchCommunities(null, nonMatchingCommunitySetCandidate2))); }
@Test public void testMatchedCommunitiesUnsupported() { CommunityList unsupported = new CommunityList( "", ImmutableList.of( CommunityListLine.accepting( new LiteralCommunityConjunction(ImmutableSet.of(1L, 2L)))), false); _thrown.expect(UnsupportedOperationException.class); unsupported.matchedCommunities(null, ImmutableSet.of(1L, 2L)); } }
@Test public void testAsLiteralCommunitiesUnsupported() { CommunityList expr = new CommunityList( "", ImmutableList.of( CommunityListLine.accepting(new LiteralCommunityConjunction(ImmutableSet.of(1L)))), false); _thrown.expect(UnsupportedOperationException.class); expr.asLiteralCommunities(null); }