// Copyright 2011 The MOE Authors All Rights Reserved.

package com.google.devtools.moe.client.testing;

import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableSet;
import com.google.devtools.moe.client.AppContext;
import com.google.devtools.moe.client.database.Db;
import com.google.devtools.moe.client.database.Equivalence;
import com.google.devtools.moe.client.database.SubmittedMigration;
import com.google.devtools.moe.client.repositories.Revision;

import java.util.ArrayList;
import java.util.Set;

/**
 * Db for testing
 *
 */
public class DummyDb implements Db {

  public boolean returnEquivalences;
  public ArrayList<Equivalence> equivalences;
  public ArrayList<SubmittedMigration> migrations;

  public DummyDb(boolean returnEquivalences) {
    this.returnEquivalences = returnEquivalences;
    equivalences = new ArrayList<Equivalence>();
    migrations = new ArrayList<SubmittedMigration>();
  }

  @Override
  public void noteEquivalence(Equivalence equivalence) {
    equivalences.add(equivalence);
  }

  @Override
  public Set<Revision> findEquivalences(Revision revision, String otherRepository) {
    if (!returnEquivalences) {
      return ImmutableSet.of();
    } else {
      return ImmutableSet.of(new Revision("1", otherRepository),
                             new Revision("2", otherRepository));
    }
  }

  @Override
  public boolean noteMigration(SubmittedMigration migration) {
    return !migrations.contains(migration) && migrations.add(migration);
  }

  @Override
  public void writeToLocation(String dbLocation) {
    Joiner j = Joiner.on("\n");
    StringBuilder b = new StringBuilder("Equivalences:\n");
    j.join(b, equivalences);
    b.append("\nMigrations:\n");
    j.join(b, migrations);
    AppContext.RUN.ui.info(b.toString());
  }
}

@@ -591,16 +591,73 @@
 s Db %7B%0A%0A
+  private static final Joiner JOINER = Joiner.on(%22%5Cn%22);%0A%0A
   public
@@ -1636,110 +1636,102 @@
     
-Joiner j = Joiner.on(%22%5Cn%22);%0A    StringBuilder b = new StringBuilder(%22Equivalences:%5Cn%22);%0A    j
+String b = new StringBuilder()%0A        .append(%22Equivalences:%5Cn%22)%0A        .append(JOINER
 .join(
-b, 
 equi
@@ -1743,15 +1743,18 @@
 ces)
-;
+)
 %0A    
-b
+    
 .app
@@ -1779,24 +1779,37 @@
 %5Cn%22)
-;
 %0A    
-j
+    .append(JOINER
 .join(
-b, 
 migr
@@ -1815,16 +1815,37 @@
 rations)
+)%0A        .toString()
 ;%0A    Ap
@@ -1866,27 +1866,16 @@
 i.info(b
-.toString()
 );%0A  %7D%0A%7D

Add @CheckReturnValue to CaseFormat, Enums, Equivalence, Joiner, MoreObjects, Strings and Suppliers. Change on 2015/01/26 by kak <kak@google.com> ------------- Created by MOE: http://code.google.com/p/moe-java MOE_MIGRATED_REVID=84797925