Adapt tests to PR 47105, fix handling of implicit trunk "tags"
authorStefan Bodewig <bodewig@apache.org>
Tue, 5 May 2009 14:03:11 +0000 (14:03 +0000)
committerStefan Bodewig <bodewig@apache.org>
Tue, 5 May 2009 14:03:11 +0000 (14:03 +0000)
git-svn-id: https://svn.apache.org/repos/asf/ant/antlibs/svn/trunk@771731 13f79535-47bb-0310-9956-ffa450edef68

src/main/org/apache/ant/svn/SvnTagDiff.java
src/tests/junit/org/apache/ant/svn/SvnTagDiffTest.java

index 4e34ff6..5e4109c 100644 (file)
@@ -91,6 +91,9 @@ import org.apache.tools.ant.util.FileUtils;
  */
 public class SvnTagDiff extends AbstractSvnTask {
 
+    private static final String TRUNK = "trunk";
+    private static final String TRUNK_SLASH = TRUNK + "/";
+
     /**
      * Used to create the temp file for svn log
      */
@@ -240,7 +243,8 @@ public class SvnTagDiff extends AbstractSvnTask {
 
         // sort out whats tags and whats branches
         this.fromCopy = fromTag !=null ? fromTag : fromBranch;
-        this.toCopy = toTag != null ? toTag : toBranch;
+        this.toCopy = toTag != null ? toTag 
+            : toBranch != null ? toBranch : TRUNK;
         this.fromName = fromTag != null ? "fromTag" : "fromBranch";
         this.toName = toTag != null ? "toTag" : "toBranch";
         this.fromDir = fromTag != null ? "tags/" : "branches/";
@@ -277,8 +281,8 @@ public class SvnTagDiff extends AbstractSvnTask {
     }
 
     private void addDiffArguments(){
-        if (fromCopy.equals("trunk") || fromCopy.equals("trunk/")) {
-            addSubCommandArgument(baseURL + "trunk/");
+        if (fromCopy.equals(TRUNK) || fromCopy.equals(TRUNK_SLASH)) {
+            addSubCommandArgument(baseURL + TRUNK_SLASH);
         } else {
             if (fromCopy.endsWith("/")) {
                 addSubCommandArgument(baseURL + fromDir + fromCopy);
@@ -286,9 +290,8 @@ public class SvnTagDiff extends AbstractSvnTask {
                 addSubCommandArgument(baseURL + fromDir + fromCopy + "/");
             }
         }
-        if (toCopy == null || toCopy.equals("trunk")
-            || toCopy.equals("trunk/")) {
-            addSubCommandArgument(baseURL + "trunk/");
+        if (toCopy.equals(TRUNK) || toCopy.equals(TRUNK_SLASH)) {
+            addSubCommandArgument(baseURL + TRUNK_SLASH);
         } else {
             if (toCopy.endsWith("/")) {
                 addSubCommandArgument(baseURL + toDir + toCopy);
index dd0d5af..aa47066 100644 (file)
@@ -49,16 +49,16 @@ public class SvnTagDiffTest extends BuildFileTest {
 
     public void testDiffWithExplicitTrunk() throws IOException {
         String log = executeTargetAndReadLogFully("diff-with-explicit-trunk");
-        assertDiffWithTrunk(log);
+        assertDiffWithTrunk(log, "toTag");
     }
 
     public void testDiffWithImplicitTrunk() throws IOException {
         String log = executeTargetAndReadLogFully("diff-with-implicit-trunk");
-        assertDiffWithTrunk(log);
+        assertDiffWithTrunk(log, "toBranch");
     }
 
-    private static void assertDiffWithTrunk(String log) {
-        assertAttributes(log, "10_BETA1", "trunk");
+    private static void assertDiffWithTrunk(String log, String tag2Name) {
+        assertAttributes(log, "10_BETA1", tag2Name, "trunk");
         assertAdded(log);
         assertModified(log);
         assertDeleted(log);
@@ -78,14 +78,21 @@ public class SvnTagDiffTest extends BuildFileTest {
 
     private static final void assertAttributes(String log, String tag1,
                                                String tag2) {
+        assertAttributes(log, tag1, "toTag", tag2);
+    }
+
+    private static final void assertAttributes(String log, String tag1,
+                                               String tag2Name, String tag2) {
         int start = log.indexOf("<tagdiff");
         Assert.assertTrue(start > -1);
         int end = log.indexOf(">", start);
         Assert.assertTrue(end > -1);
-        Assert.assertTrue(log.indexOf("tag1=\"" + tag1 + "\"", start) > -1);
-        Assert.assertTrue(log.indexOf("tag1=\"" + tag1 + "\"", start) < end);
-        Assert.assertTrue(log.indexOf("tag2=\"" + tag2 + "\"", start) > -1);
-        Assert.assertTrue(log.indexOf("tag2=\"" + tag2 + "\"", start) < end);
+        Assert.assertTrue(log.indexOf("fromTag=\"" + tag1 + "\"", start) > -1);
+        Assert.assertTrue(log.indexOf("fromTag=\"" + tag1 + "\"", start) < end);
+        Assert.assertTrue(log.indexOf(tag2Name + "=\"" + tag2 + "\"",
+                                      start) > -1);
+        Assert.assertTrue(log.indexOf(tag2Name + "=\"" + tag2 + "\"",
+                                      start) < end);
         Assert.assertTrue(log.indexOf("svnurl=\"http://svn.apache.org/",
                                       start) > -1);
         Assert.assertTrue(log.indexOf("svnurl=\"http://svn.apache.org/",