Coverage Report - com.aragost.javahg.internals.AddRemoveCommandHelper
 
Classes in this File Line Coverage Branch Coverage Complexity
AddRemoveCommandHelper
89%
17/19
75%
3/4
1.5
 
 1  
 package com.aragost.javahg.internals;
 2  
 
 3  
 import java.io.File;
 4  
 import java.io.IOException;
 5  
 import java.util.List;
 6  
 
 7  
 import com.google.common.collect.Lists;
 8  
 
 9  
 /**
 10  
  * Helper class to implement Add and Removed Command.
 11  
  */
 12  
 public class AddRemoveCommandHelper {
 13  
 
 14  
     private AbstractCommand command;
 15  
 
 16  
     private String prefix;
 17  
 
 18  
     public AddRemoveCommandHelper(AbstractCommand command, String prefix) {
 19  1710
         super();
 20  1710
         this.command = command;
 21  1710
         this.prefix = prefix;
 22  1710
     }
 23  
 
 24  
     public List<String> execute(String... files) {
 25  1712
         List<String> result = Lists.newArrayList();
 26  1712
         for (String line : command.launchIterator(files)) {
 27  929
             if (line.startsWith(prefix)) {
 28  929
                 String file = new String(line.substring(prefix.length()));
 29  929
                 result.add(file);
 30  929
             } else {
 31  0
                 command.cleanUp();
 32  0
                 throw new UnexpectedCommandOutputException(this.command, line);
 33  
             }
 34  
         }
 35  1711
         return result;
 36  
     }
 37  
 
 38  
     public List<File> execute(File... files) {
 39  944
         return stringList2fileList(execute(fileArray2StringArray(files)));
 40  
     }
 41  
 
 42  
     public List<File> execute() {
 43  941
         return execute(new File[0]);
 44  
     }
 45  
 
 46  
     /**
 47  
      * Helper method to convert Files to Strings
 48  
      * 
 49  
      * @param files
 50  
      * @return
 51  
      */
 52  
     private final String[] fileArray2StringArray(File[] files) {
 53  944
         return Utils.fileArray2StringArray(files);
 54  
     }
 55  
 
 56  
     /**
 57  
      * Helper method to convert Strings to Files
 58  
      * 
 59  
      * @param strings
 60  
      * @return
 61  
      * @throws IOException
 62  
      */
 63  
     private final List<File> stringList2fileList(List<String> strings) {
 64  943
         String[] strArray = strings.toArray(new String[strings.size()]);
 65  943
         File[] fileArray = Utils.stringArray2FileArray(this.command.getRepository().getDirectory(), strArray);
 66  943
         return Lists.newArrayList(fileArray);
 67  
     }
 68  
 
 69  
 }