// Path: parent/bundles/com.google.eclipse.mechanic/src/com/google/eclipse/mechanic/core/keybinding/KbaChangeSet.java
// enum Action {
//   ADD("add"),
//   REMOVE("remove"),
//   ;
// 
//   /**
//    * Label as it appears in the .kbd JSON file
//    */
//   private final String label;
// 
//   Action(String label) {
//     this.label = label;
//   }
// 
//   public static Action fromLabel(String someLabel) {
//     for (Action a : values()) {
//       if (a.label.equals(someLabel))
//         return a;
//     }
//     throw new IllegalArgumentException(String.format(
//         "'%s' is not a valid action",
//         someLabel));
//   }
// 
//   static Action forLabel(String label) {
//     for (Action action : values()) {
//       if (action.label.equals(label)) {
//         return action;
//       }
//     }
//     throw new IllegalArgumentException(label);
//   }
//     
//   @Override
//   public String toString() {
//     return label;
//   }
// }
// 
// Path: parent/bundles/com.google.eclipse.mechanic/src/com/google/eclipse/mechanic/core/keybinding/KbaChangeSet.java
// static final class KbaBindingList {
//   private final ImmutableList<KbaBinding> list;
// 
//   public KbaBindingList(KbaBinding... list) {
//     this(Arrays.asList(list));
//   }
//     
//   public KbaBindingList(Iterable<KbaBinding> list) {
//     this.list = ImmutableList.copyOf(list);
//   }
// 
//   @Override
//   public int hashCode() {
//     return Objects.hashCode(list);
//   }
// 
//   @Override
//   public boolean equals(Object obj) {
//     if (!(obj instanceof KbaBindingList)) {
//       return false;
//     }
//     KbaBindingList that = (KbaBindingList) obj;
//     return this.list.equals(that.list);
//   }
// 
//   @Override
//   public String toString() {
//     return this.list.toString();
//   }
// 
//   public ImmutableList<KbaBinding> getList() {
//     return list;
//   }
// }
// 
// Path: parent/bundles/com.google.eclipse.mechanic/src/com/google/eclipse/mechanic/core/keybinding/KeyBindingsManualFormatter.java
// enum BindingType {
//   USER,
//   SYSTEM,
//   ;
//     
//   static BindingType from(Binding binding) {
//     return from(binding.getType());
//   }
//     
//   static BindingType from(int eclipseBindingType) {
//     if (eclipseBindingType == Binding.SYSTEM) {
//       return SYSTEM;
//     } else if (eclipseBindingType == Binding.USER) {
//       return USER;
//     } else {
//       throw new UnsupportedOperationException("Binding type: " + eclipseBindingType);
//     }
//   }
//     
// }


import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.eclipse.mechanic.core.keybinding.KbaChangeSet.Action;
import com.google.eclipse.mechanic.core.keybinding.KbaChangeSet.KbaBindingList;
import com.google.eclipse.mechanic.core.keybinding.KeyBindingsManualFormatter.BindingType;
import org.junit.Test;
import java.io.StringReader;
import java.util.List;
import java.util.Map;
import junit.framework.Assert;

  @Test
  public void testARoundTripCommandWithNoParams() {
    
    KbaBinding expectedKbaBinding = kbaBindingCommandWithNoParams();
    Map<KbaChangeSetQualifier, KbaChangeSet> map = kbaMap(new KbaBindingList(
        expectedKbaBinding));
    
    String json = KeyBindingsManualFormatter.getBindingsPrintout(BindingType.USER, map, "");
    KeyBindingsModel kbaFromJson = KeyBindingsParser.deSerialize(new StringReader(json));

    List<KbaChangeSet> keyBindingsChangeSetsToAdd = Lists.newArrayList(
        kbaFromJson.getKeyBindingsChangeSetsWith(Action.ADD));
    Assert.assertEquals(1, keyBindingsChangeSetsToAdd.size());
    Assert.assertEquals(1, keyBindingsChangeSetsToAdd.get(0).getBindingList().size());
    
    KbaBinding actualKbaBinding = keyBindingsChangeSetsToAdd.get(0).getBindingList().get(0);
    
    Assert.assertEquals(expectedKbaBinding, actualKbaBinding);
  }

  @Test
  public void testEscapingDescription() {
    testEscapingDescription("x");
    testEscapingDescription("Joe's Apartment");
    testEscapingDescription("Thank you, \"The Management\"");
    testEscapingDescription("Found on my c:\\ drive");
  }

  private void testEscapingDescription(String description) {
// Path: parent/bundles/com.google.eclipse.mechanic/src/com/google/eclipse/mechanic/core/keybinding/KbaChangeSet.java
// enum Action {
//   ADD("add"),
//   REMOVE("remove"),
//   ;
// 
//   /**
//    * Label as it appears in the .kbd JSON file
//    */
//   private final String label;
// 
//   Action(String label) {
//     this.label = label;
//   }
// 
//   public static Action fromLabel(String someLabel) {
//     for (Action a : values()) {
//       if (a.label.equals(someLabel))
//         return a;
//     }
//     throw new IllegalArgumentException(String.format(
//         "'%s' is not a valid action",
//         someLabel));
//   }
// 
//   static Action forLabel(String label) {
//     for (Action action : values()) {
//       if (action.label.equals(label)) {
//         return action;
//       }
//     }
//     throw new IllegalArgumentException(label);
//   }
//     
//   @Override
//   public String toString() {
//     return label;
//   }
// }
// 
// Path: parent/bundles/com.google.eclipse.mechanic/src/com/google/eclipse/mechanic/core/keybinding/KbaChangeSet.java
// static final class KbaBindingList {
//   private final ImmutableList<KbaBinding> list;
// 
//   public KbaBindingList(KbaBinding... list) {
//     this(Arrays.asList(list));
//   }
//     
//   public KbaBindingList(Iterable<KbaBinding> list) {
//     this.list = ImmutableList.copyOf(list);
//   }
// 
//   @Override
//   public int hashCode() {
//     return Objects.hashCode(list);
//   }
// 
//   @Override
//   public boolean equals(Object obj) {
//     if (!(obj instanceof KbaBindingList)) {
//       return false;
//     }
//     KbaBindingList that = (KbaBindingList) obj;
//     return this.list.equals(that.list);
//   }
// 
//   @Override
//   public String toString() {
//     return this.list.toString();
//   }
// 
//   public ImmutableList<KbaBinding> getList() {
//     return list;
//   }
// }
// 
// Path: parent/bundles/com.google.eclipse.mechanic/src/com/google/eclipse/mechanic/core/keybinding/KeyBindingsManualFormatter.java
// enum BindingType {
//   USER,
//   SYSTEM,
//   ;
//     
//   static BindingType from(Binding binding) {
//     return from(binding.getType());
//   }
//     
//   static BindingType from(int eclipseBindingType) {
//     if (eclipseBindingType == Binding.SYSTEM) {
//       return SYSTEM;
//     } else if (eclipseBindingType == Binding.USER) {
//       return USER;
//     } else {
//       throw new UnsupportedOperationException("Binding type: " + eclipseBindingType);
//     }
//   }
//     
// }


// Path: parent/tests/com.google.eclipse.mechanic.tests/src/com/google/eclipse/mechanic/core/keybinding/KeyBindingsManualFormatterTest.java
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.eclipse.mechanic.core.keybinding.KbaChangeSet.Action;
import com.google.eclipse.mechanic.core.keybinding.KbaChangeSet.KbaBindingList;
import com.google.eclipse.mechanic.core.keybinding.KeyBindingsManualFormatter.BindingType;
import org.junit.Test;
import java.io.StringReader;
import java.util.List;
import java.util.Map;
import junit.framework.Assert;


  @Test
  public void testARoundTripCommandWithNoParams() {
    
    KbaBinding expectedKbaBinding = kbaBindingCommandWithNoParams();
    Map<KbaChangeSetQualifier, KbaChangeSet> map = kbaMap(new KbaBindingList(
        expectedKbaBinding));
    
    String json = KeyBindingsManualFormatter.getBindingsPrintout(BindingType.USER, map, "");
    KeyBindingsModel kbaFromJson = KeyBindingsParser.deSerialize(new StringReader(json));

    List<KbaChangeSet> keyBindingsChangeSetsToAdd = Lists.newArrayList(
        kbaFromJson.getKeyBindingsChangeSetsWith(Action.ADD));
    Assert.assertEquals(1, keyBindingsChangeSetsToAdd.size());
    Assert.assertEquals(1, keyBindingsChangeSetsToAdd.get(0).getBindingList().size());
    
    KbaBinding actualKbaBinding = keyBindingsChangeSetsToAdd.get(0).getBindingList().get(0);
    
    Assert.assertEquals(expectedKbaBinding, actualKbaBinding);
  }

  @Test
  public void testEscapingDescription() {
    testEscapingDescription("x");
    testEscapingDescription("Joe's Apartment");
    testEscapingDescription("Thank you, \"The Management\"");
    testEscapingDescription("Found on my c:\\ drive");
  }

  private void testEscapingDescription(String description) {
    try {