Rewrite query tests to better use Truth
Instead of asserting about individual changes in order, use containsExactlyElementsIn(...).inOrder(). Rewrite query helper methods so empty/non-empty assertions line up better. Change-Id: Ib4b2a0727caa4b483e03b488d5373a0ee0009769
This commit is contained in:
		
				
					committed by
					
						
						David Pursehouse
					
				
			
			
				
	
			
			
			
						parent
						
							e313b93bc2
						
					
				
				
					commit
					7f678a2352
				
			@@ -116,6 +116,23 @@ public interface Changes {
 | 
			
		||||
    public EnumSet<ListChangesOption> getOptions() {
 | 
			
		||||
      return options;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public String toString() {
 | 
			
		||||
      StringBuilder sb =  new StringBuilder(getClass().getSimpleName())
 | 
			
		||||
          .append('{')
 | 
			
		||||
          .append(query);
 | 
			
		||||
      if (limit != 0) {
 | 
			
		||||
        sb.append(", limit=").append(limit);
 | 
			
		||||
      }
 | 
			
		||||
      if (start != 0) {
 | 
			
		||||
        sb.append(", start=").append(start);
 | 
			
		||||
      }
 | 
			
		||||
      if (!options.isEmpty()) {
 | 
			
		||||
        sb.append("options=").append(options);
 | 
			
		||||
      }
 | 
			
		||||
      return sb.append('}').toString();
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
 
 | 
			
		||||
@@ -24,7 +24,6 @@ import com.google.gerrit.extensions.api.changes.Changes;
 | 
			
		||||
import com.google.gerrit.extensions.client.ListChangesOption;
 | 
			
		||||
import com.google.gerrit.extensions.common.ChangeInfo;
 | 
			
		||||
import com.google.gerrit.extensions.restapi.AuthException;
 | 
			
		||||
import com.google.gerrit.extensions.restapi.BadRequestException;
 | 
			
		||||
import com.google.gerrit.extensions.restapi.IdString;
 | 
			
		||||
import com.google.gerrit.extensions.restapi.RestApiException;
 | 
			
		||||
import com.google.gerrit.extensions.restapi.TopLevelResource;
 | 
			
		||||
@@ -145,7 +144,7 @@ class ChangesImpl implements Changes {
 | 
			
		||||
      List<ChangeInfo> infos = (List<ChangeInfo>) result;
 | 
			
		||||
 | 
			
		||||
      return ImmutableList.copyOf(infos);
 | 
			
		||||
    } catch (BadRequestException | AuthException | OrmException e) {
 | 
			
		||||
    } catch (AuthException | OrmException e) {
 | 
			
		||||
      throw new RestApiException("Cannot query changes", e);
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 
 | 
			
		||||
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							@@ -14,8 +14,6 @@
 | 
			
		||||
 | 
			
		||||
package com.google.gerrit.server.query.change;
 | 
			
		||||
 | 
			
		||||
import static org.junit.Assert.assertTrue;
 | 
			
		||||
 | 
			
		||||
import com.google.gerrit.lifecycle.LifecycleManager;
 | 
			
		||||
import com.google.gerrit.reviewdb.client.Change;
 | 
			
		||||
import com.google.gerrit.testutil.InMemoryModule;
 | 
			
		||||
@@ -45,12 +43,12 @@ public class LuceneQueryChangesTest extends AbstractQueryChangesTest {
 | 
			
		||||
        repo.parseBody(repo.commit().message("one.two.three").create());
 | 
			
		||||
    Change change2 = newChange(repo, commit2, null, null, null).insert();
 | 
			
		||||
 | 
			
		||||
    assertTrue(query("message:foo_ba").isEmpty());
 | 
			
		||||
    assertResultEquals(change1, queryOne("message:bar"));
 | 
			
		||||
    assertResultEquals(change1, queryOne("message:foo_bar"));
 | 
			
		||||
    assertResultEquals(change1, queryOne("message:foo bar"));
 | 
			
		||||
    assertResultEquals(change2, queryOne("message:two"));
 | 
			
		||||
    assertResultEquals(change2, queryOne("message:one.two"));
 | 
			
		||||
    assertResultEquals(change2, queryOne("message:one two"));
 | 
			
		||||
    assertQuery("message:foo_ba");
 | 
			
		||||
    assertQuery("message:bar", change1);
 | 
			
		||||
    assertQuery("message:foo_bar", change1);
 | 
			
		||||
    assertQuery("message:foo bar", change1);
 | 
			
		||||
    assertQuery("message:two", change2);
 | 
			
		||||
    assertQuery("message:one.two", change2);
 | 
			
		||||
    assertQuery("message:one two", change2);
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user