use of com.google.gerrit.server.account.AccountResolver.Searcher in project gerrit by GerritCodeReview.
the class AccountResolverTest method noShortCircuit.
@Test
public void noShortCircuit() throws Exception {
ImmutableList<Searcher<?>> searchers = ImmutableList.of(new TestSearcher("foo", false, newAccount(1)), new TestSearcher("bar", false, newAccount(2), newAccount(3)));
Result result = search("foo", searchers, AccountResolverTest::allVisiblePredicate);
assertThat(result.input()).isEqualTo("foo");
assertThat(result.asIdSet()).containsExactlyElementsIn(ids(1));
result = search("bar", searchers, AccountResolverTest::allVisiblePredicate);
assertThat(result.input()).isEqualTo("bar");
assertThat(result.asIdSet()).containsExactlyElementsIn(ids(2, 3));
result = search("baz", searchers, AccountResolverTest::allVisiblePredicate);
assertThat(result.input()).isEqualTo("baz");
assertThat(result.asIdSet()).isEmpty();
}
use of com.google.gerrit.server.account.AccountResolver.Searcher in project gerrit by GerritCodeReview.
the class AccountResolverTest method asUniqueWithMultipleResults.
@Test
public void asUniqueWithMultipleResults() throws Exception {
ImmutableList<Searcher<?>> searchers = ImmutableList.of(new TestSearcher("foo", false, newAccount(1), newAccount(2)));
UnresolvableAccountException thrown = assertThrows(UnresolvableAccountException.class, () -> search("foo", searchers, AccountResolverTest::allVisiblePredicate).asUnique());
assertThat(thrown).hasMessageThat().isEqualTo("Account 'foo' is ambiguous (at most 3 shown):\n1: Anonymous Name (1)\n2: Anonymous Name (2)");
}
use of com.google.gerrit.server.account.AccountResolver.Searcher in project gerrit by GerritCodeReview.
the class AccountResolverTest method dontFilterInactive.
@Test
public void dontFilterInactive() throws Exception {
ImmutableList<Searcher<?>> searchers = ImmutableList.of(new TestSearcher("foo", false, newInactiveAccount(1)), new TestSearcher("f.*", false, newInactiveAccount(2)));
Result result = search("foo", searchers, AccountResolverTest::allVisiblePredicate);
// Searchers always short-circuit when finding a non-empty result list, and this one didn't
// filter out inactive results, so the second searcher never ran.
assertThat(result.asIdSet()).containsExactlyElementsIn(ids(1));
assertThat(getOnlyElement(result.asList()).account().isActive()).isFalse();
assertThat(filteredInactiveIds(result)).isEmpty();
}
use of com.google.gerrit.server.account.AccountResolver.Searcher in project gerrit by GerritCodeReview.
the class AccountResolverTest method shortCircuit.
@Test
public void shortCircuit() throws Exception {
ImmutableList<Searcher<?>> searchers = ImmutableList.of(new TestSearcher("f.*", true), new TestSearcher("foo|bar", false, newAccount(1)));
Result result = search("foo", searchers, AccountResolverTest::allVisiblePredicate);
assertThat(result.input()).isEqualTo("foo");
assertThat(result.asIdSet()).isEmpty();
result = search("bar", searchers, AccountResolverTest::allVisiblePredicate);
assertThat(result.input()).isEqualTo("bar");
assertThat(result.asIdSet()).containsExactlyElementsIn(ids(1));
}
use of com.google.gerrit.server.account.AccountResolver.Searcher in project gerrit by GerritCodeReview.
the class AccountResolverTest method shouldUseCustomAccountActivityPredicate.
@Test
public void shouldUseCustomAccountActivityPredicate() throws Exception {
TestSearcher searcher1 = new TestSearcher("foo", false, newInactiveAccount(1));
searcher1.setCallerShouldFilterOutInactiveCandidates();
TestSearcher searcher2 = new TestSearcher("f.*", false, newInactiveAccount(2));
searcher2.setCallerShouldFilterOutInactiveCandidates();
ImmutableList<Searcher<?>> searchers = ImmutableList.of(searcher1, searcher2);
Result result = search("foo", searchers, AccountResolverTest::allVisiblePredicate, (a) -> true);
// Searchers always short-circuit when finding a non-empty result list,
// and this one didn't filter out inactive results,
// so the second searcher never ran.
assertThat(result.asIdSet()).containsExactlyElementsIn(ids(1));
assertThat(getOnlyElement(result.asList()).account().isActive()).isFalse();
assertThat(filteredInactiveIds(result)).isEmpty();
}
Aggregations