]> source.dussan.org Git - aspectj.git/commitdiff
Add basic rename functionality to file step
authorAndy Clement <aclement@pivotal.io>
Wed, 14 Feb 2018 20:38:59 +0000 (12:38 -0800)
committerAndy Clement <aclement@pivotal.io>
Wed, 14 Feb 2018 20:38:59 +0000 (12:38 -0800)
testing/newsrc/org/aspectj/testing/FileSpec.java

index f9876928b5abf28d0bd597a09a7c247c9c7b4fef..2164f38f117b6e6594067d4165b8b7075eb08ce4 100644 (file)
@@ -23,6 +23,9 @@ import org.aspectj.tools.ajc.AjcTestCase;
 public class FileSpec implements ITestStep {
 
        private String toDelete;
+       
+       private String renameFrom;
+       private String renameTo;
 
        // private String dir;
        // private AjcTest test;
@@ -30,13 +33,23 @@ public class FileSpec implements ITestStep {
        public FileSpec() {
        }
 
+       public void setRenameFrom(String file) {
+               this.renameFrom = file;
+       }
+       
+       public void setRenameTo(String file) {
+               this.renameTo = file;
+       }
+       
        public void setDeletefile(String file) {
                this.toDelete = file;
        }
 
+       @Override
        public void addExpectedMessage(ExpectedMessageSpec message) {
        }
 
+       @Override
        public void execute(AjcTestCase inTestCase) {
                File sandbox = inTestCase.getSandboxDirectory();
                if (toDelete != null) {
@@ -47,6 +60,14 @@ public class FileSpec implements ITestStep {
                                recursiveDelete(targetForDeletion);
                        }
                }
+               if (renameFrom != null) {
+                       if (renameTo == null) {
+                               throw new IllegalStateException("If setting renameFrom the renameTo should also be set");
+                       }
+                       File fileFrom = new File(sandbox, renameFrom);
+                       File fileTo = new File(sandbox, renameTo);
+                       fileFrom.renameTo(fileTo);
+               }
        }
 
        private void recursiveDelete(File toDelete) {
@@ -59,10 +80,12 @@ public class FileSpec implements ITestStep {
                toDelete.delete();
        }
 
+       @Override
        public void setBaseDir(String dir) {
                // this.dir = dir;
        }
 
+       @Override
        public void setTest(AjcTest test) {
                // this.test = test;
        }