From 4590f8623d3f77e8e23cf6717b94fab4450cd5d4 Mon Sep 17 00:00:00 2001 From: Dariusz Luksza Date: Thu, 20 Jan 2011 00:15:26 +0100 Subject: Remove useless tests after merging change I6b030af1 Since change I6b030af13ba092855ef68e5a6087bb357fdb7bb2 GitResourceVariantTree.fetchVariant() always return null hence all tests for this method and its delegates can be removed. Change-Id: Idc463ec8d6432dd99c383f2dc433c0f32b1af9ab Signed-off-by: Dariusz Luksza Signed-off-by: Matthias Sohn --- .../synchronize/GitResourceVariantTreeTest.java | 275 --------------------- .../synchronize/GitTestResourceVariantTree.java | 35 --- 2 files changed, 310 deletions(-) delete mode 100644 org.eclipse.egit.core.test/src/org/eclipse/egit/core/synchronize/GitResourceVariantTreeTest.java delete mode 100644 org.eclipse.egit.core.test/src/org/eclipse/egit/core/synchronize/GitTestResourceVariantTree.java (limited to 'org.eclipse.egit.core.test') diff --git a/org.eclipse.egit.core.test/src/org/eclipse/egit/core/synchronize/GitResourceVariantTreeTest.java b/org.eclipse.egit.core.test/src/org/eclipse/egit/core/synchronize/GitResourceVariantTreeTest.java deleted file mode 100644 index ccbff67fdc..0000000000 --- a/org.eclipse.egit.core.test/src/org/eclipse/egit/core/synchronize/GitResourceVariantTreeTest.java +++ /dev/null @@ -1,275 +0,0 @@ -/******************************************************************************* - * Copyright (C) 2010, Dariusz Luksza - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - *******************************************************************************/ -package org.eclipse.egit.core.synchronize; - -import static org.eclipse.jgit.lib.Constants.HEAD; -import static org.eclipse.jgit.lib.Constants.MASTER; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -import java.io.File; -import java.io.InputStream; -import java.util.Arrays; -import java.util.Comparator; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.NullProgressMonitor; -import org.eclipse.egit.core.op.ConnectProviderOperation; -import org.eclipse.egit.core.project.RepositoryMapping; -import org.eclipse.egit.core.synchronize.dto.GitSynchronizeData; -import org.eclipse.egit.core.synchronize.dto.GitSynchronizeDataSet; -import org.eclipse.egit.core.test.GitTestCase; -import org.eclipse.egit.core.test.TestProject; -import org.eclipse.egit.core.test.TestRepository; -import org.eclipse.jdt.core.IPackageFragment; -import org.eclipse.jdt.core.IType; -import org.eclipse.jgit.api.Git; -import org.eclipse.jgit.lib.Constants; -import org.eclipse.jgit.lib.Repository; -import org.eclipse.team.core.variants.IResourceVariant; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -public class GitResourceVariantTreeTest extends GitTestCase { - - private Repository repo; - - private IProject iProject; - - private TestRepository testRepo; - - @Before - public void createGitRepository() throws Exception { - iProject = project.project; - testRepo = new TestRepository(gitDir); - testRepo.connect(iProject); - repo = RepositoryMapping.getMapping(iProject).getRepository(); - } - - @After - public void clearGitResources() throws Exception { - testRepo.disconnect(iProject); - testRepo.dispose(); - repo = null; - super.tearDown(); - } - - /** - * roots() method should return list of projects that are associated with - * given repository. In this case there is only one project associated with - * this repository therefore only one root should be returned. - * - * @throws Exception - */ - @Test - public void shouldReturnOneRoot() throws Exception { - // when - new Git(repo).commit().setAuthor("JUnit", "junit@egit.org") - .setMessage("Initial commit").call(); - GitSynchronizeData data = new GitSynchronizeData(repo, HEAD, HEAD, false); - GitSynchronizeDataSet dataSet = new GitSynchronizeDataSet(data); - - // given - GitResourceVariantTree grvt = new GitTestResourceVariantTree(dataSet, - null); - - // then - assertEquals(1, grvt.roots().length); - IResource actualProject = grvt.roots()[0]; - assertEquals(this.project.getProject(), actualProject); - } - - /** - * When we have two or more project associated with repository, roots() - * method should return list of project. In this case we have two project - * associated with particular repository, therefore '2' value is expected. - * - * @throws Exception - */ - @Test - public void shouldReturnTwoRoots() throws Exception { - // when - // create second project - TestProject secondProject = new TestProject(true, "Project-2"); - IProject secondIProject = secondProject.project; - // add connect project with repository - new ConnectProviderOperation(secondIProject, gitDir).execute(null); - new Git(repo).commit().setAuthor("JUnit", "junit@egit.org") - .setMessage("Initial commit").call(); - GitSynchronizeData data = new GitSynchronizeData(repo, HEAD, HEAD, false); - GitSynchronizeDataSet dataSet = new GitSynchronizeDataSet(data); - - // given - GitResourceVariantTree grvt = new GitTestResourceVariantTree(dataSet, - null); - - // then - IResource[] roots = grvt.roots(); - // sort in order to be able to assert the project instances - Arrays.sort(roots, new Comparator() { - public int compare(IResource r1, IResource r2) { - String path1 = r1.getFullPath().toString(); - String path2 = r2.getFullPath().toString(); - return path1.compareTo(path2); - } - }); - assertEquals(2, roots.length); - IResource actualProject = roots[0]; - assertEquals(this.project.project, actualProject); - IResource actualProject1 = roots[1]; - assertEquals(secondIProject, actualProject1); - } - - /** - * Checks that getResourceVariant will not throw NPE for null argument. This - * method is called with null argument when local or remote resource does - * not exist. - * - * @throws Exception - */ - @Test - public void shouldReturnNullResourceVariant() throws Exception { - // when - new Git(repo).commit().setAuthor("JUnit", "junit@egit.org") - .setMessage("Initial commit").call(); - GitSynchronizeData data = new GitSynchronizeData(repo, HEAD, MASTER, - false); - GitSynchronizeDataSet dataSet = new GitSynchronizeDataSet(data); - - // given - GitResourceVariantTree grvt = new GitRemoteResourceVariantTree(dataSet); - - // then - assertNull(grvt.getResourceVariant(null)); - } - - /** - * getResourceVariant() should return null when given resource doesn't exist - * in repository. - * - * @throws Exception - */ - @Test - public void shouldReturnNullResourceVariant2() throws Exception { - // when - IPackageFragment iPackage = project.createPackage("org.egit.test"); - IType mainJava = project.createType(iPackage, "Main.java", - "class Main {}"); - new Git(repo).commit().setAuthor("JUnit", "junit@egit.org") - .setMessage("Initial commit").call(); - GitSynchronizeData data = new GitSynchronizeData(repo, HEAD, MASTER, - false); - GitSynchronizeDataSet dataSet = new GitSynchronizeDataSet(data); - - // given - GitResourceVariantTree grvt = new GitRemoteResourceVariantTree(dataSet); - - // then - assertNull(grvt.getResourceVariant(mainJava.getResource())); - } - - /** - * Check if getResourceVariant() does return the same resource that was - * committed. Passes only when it is run as a single test, not as a part of - * largest test suite - * - * @throws Exception - */ - @Test - public void shoulReturnSameResourceVariant() throws Exception { - // when - String fileName = "Main.java"; - File file = testRepo.createFile(iProject, fileName); - testRepo.appendContentAndCommit(iProject, file, "class Main {}", - "initial commit"); - IFile mainJava = testRepo.getIFile(iProject, file); - GitSynchronizeData data = new GitSynchronizeData(repo, HEAD, MASTER, - false); - GitSynchronizeDataSet dataSet = new GitSynchronizeDataSet(data); - - // given - GitResourceVariantTree grvt = new GitRemoteResourceVariantTree(dataSet); - - // then - IResourceVariant actual = grvt.getResourceVariant(mainJava); - assertNotNull(actual); - assertEquals(fileName, actual.getName()); - - InputStream actualIn = actual.getStorage(new NullProgressMonitor()) - .getContents(); - byte[] actualByte = getBytesAndCloseStream(actualIn); - InputStream expectedIn = mainJava.getContents(); - byte[] expectedByte = getBytesAndCloseStream(expectedIn); - assertArrayEquals(expectedByte, actualByte); - } - - /** - * Create and commit Main.java file in master branch, then create branch - * "test" checkout nearly created branch and modify Main.java file. - * getResourceVariant() should obtain Main.java file content from "master" - * branch. Passes only when it is run as a single test, not as a part of - * largest test suite - * - * @throws Exception - */ - @Test - public void shouldReturnDifferentResourceVariant() throws Exception { - // when - String fileName = "Main.java"; - File file = testRepo.createFile(iProject, fileName); - testRepo.appendContentAndCommit(iProject, file, "class Main {}", - "initial commit"); - IFile mainJava = testRepo.getIFile(iProject, file); - - testRepo.createAndCheckoutBranch(Constants.R_HEADS + Constants.MASTER, - Constants.R_HEADS + "test"); - testRepo.appendContentAndCommit(iProject, file, "// test", - "first commit"); - GitSynchronizeData data = new GitSynchronizeData(repo, HEAD, MASTER, - false); - GitSynchronizeDataSet dataSet = new GitSynchronizeDataSet(data); - - // given - GitResourceVariantTree grvt = new GitRemoteResourceVariantTree(dataSet); - - // then - IResourceVariant actual = grvt.getResourceVariant(mainJava); - assertNotNull(actual); - assertEquals(fileName, actual.getName()); - - InputStream actualIn = actual.getStorage(new NullProgressMonitor()) - .getContents(); - byte[] actualByte = getBytesAndCloseStream(actualIn); - InputStream expectedIn = mainJava.getContents(); - byte[] expectedByte = getBytesAndCloseStream(expectedIn); - - // assert arrays not equals - if (Arrays.equals(expectedByte, actualByte)) - fail(); - else - assertTrue(true); - } - - private byte[] getBytesAndCloseStream(InputStream stream) throws Exception { - try { - byte[] actualByte = new byte[stream.available()]; - stream.read(actualByte); - return actualByte; - } finally { - stream.close(); - } - } -} diff --git a/org.eclipse.egit.core.test/src/org/eclipse/egit/core/synchronize/GitTestResourceVariantTree.java b/org.eclipse.egit.core.test/src/org/eclipse/egit/core/synchronize/GitTestResourceVariantTree.java deleted file mode 100644 index fbbd67bd84..0000000000 --- a/org.eclipse.egit.core.test/src/org/eclipse/egit/core/synchronize/GitTestResourceVariantTree.java +++ /dev/null @@ -1,35 +0,0 @@ -/******************************************************************************* - * Copyright (C) 2010, Dariusz Luksza - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - *******************************************************************************/ -package org.eclipse.egit.core.synchronize; - -import org.eclipse.egit.core.synchronize.dto.GitSynchronizeData; -import org.eclipse.egit.core.synchronize.dto.GitSynchronizeDataSet; -import org.eclipse.jgit.revwalk.RevCommit; -import org.eclipse.team.core.TeamException; -import org.eclipse.team.core.variants.ResourceVariantByteStore; - -/** - * Implementation of abstract {@link GitResourceVariantTree} class. It is only - * used in {@link GitResourceVariantTreeTest} for testing public methods that - * are implemented in base class. - */ -class GitTestResourceVariantTree extends GitResourceVariantTree { - - GitTestResourceVariantTree(GitSynchronizeDataSet data, - ResourceVariantByteStore store) { - super(store, data); - } - - @Override - protected RevCommit getRevCommit(GitSynchronizeData gsd) - throws TeamException { - return null; - } - -} -- cgit v1.2.3