com.github.rwhogg.git_vcr.UtilTest.java Source code

Java tutorial

Introduction

Here is the source code for com.github.rwhogg.git_vcr.UtilTest.java

Source

/*
UtilTest.java: Unit tests for Util.java
    
Copyright  2015 Bob W. Hogg. All Rights Reserved.
    
This file is part of Git-VCR.
    
Git-VCR is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
    
Git-VCR is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.
    
You should have received a copy of the GNU General Public License
along with Git-VCR.  If not, see <http://www.gnu.org/licenses/>.
*/

package com.github.rwhogg.git_vcr;

import java.io.*;
import java.util.*;
import org.apache.commons.lang3.tuple.*;
import org.eclipse.jgit.patch.*;
import org.testng.annotations.*;
import static org.testng.AssertJUnit.*;

/**
 * Unit tests for Util
 */
@Test
public class UtilTest {
    /**
     * patch to use
     */
    private String patchText = "diff --git a/file1 b/file1\n" + "index b14df64..61ca54f 100644\n" + "--- a/file1\n"
            + "+++ b/file1\n" + "@@ -1 +1,2 @@\n" + "-Hi\n" + "+Bye\n" + "+\n" + "diff --git a/file2 b/file2\n"
            + "index 0917008..1cb3cd4 100644\n" + "--- a/file2\n" + "+++ b/file2\n" + "@@ -1 +1,2 @@\n" + "-Bye\n"
            + "+Hi\n" + "+\n" + "diff --git a/file3 b/file3\n" + "index 73dd331..7b7c32a 100644\n" + "--- a/file3\n"
            + "+++ b/file3\n" + "@@ -1 +1,2 @@\n" + "-HelloGoodbye\n" + "+GoodbyeHello\n" + "+\n";

    /**
     * Test getFilesChanged
     */
    @SuppressWarnings("deprecation")
    public void testGetFilesChanged() throws IOException {
        // empty diff
        Patch patch = new Patch();
        assertEquals(Util.getFilesChanged(patch).size(), 0);

        // with files
        patch.parse(new StringBufferInputStream(patchText));
        String[] expectedResults = { "file1", "file2", "file3" };
        List<ImmutablePair<String, String>> results = Util.getFilesChanged(patch);
        for (int i = 0; i < expectedResults.length; i++) {
            ImmutablePair<String, String> result = results.get(i);
            String leftResult = result.left;
            assertEquals(leftResult, result.right);
            assertEquals(leftResult, expectedResults[i]);
        }
    }
}