diff options
Diffstat (limited to 'org.eclipse.jgit.test/tst/org/eclipse/jgit/attributes/AttributesNodeDirCacheIteratorTest.java')
-rw-r--r-- | org.eclipse.jgit.test/tst/org/eclipse/jgit/attributes/AttributesNodeDirCacheIteratorTest.java | 174 |
1 files changed, 73 insertions, 101 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/attributes/AttributesNodeDirCacheIteratorTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/attributes/AttributesNodeDirCacheIteratorTest.java index 49279e6e5a..35b953320e 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/attributes/AttributesNodeDirCacheIteratorTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/attributes/AttributesNodeDirCacheIteratorTest.java @@ -1,44 +1,11 @@ /* - * Copyright (C) 2010, Red Hat Inc. - * and other copyright owners as documented in the project's IP log. + * Copyright (C) 2010, Red Hat Inc. and others * - * This program and the accompanying materials are made available - * under the terms of the Eclipse Distribution License v1.0 which - * accompanies this distribution, is reproduced below, and is - * available at http://www.eclipse.org/org/documents/edl-v10.php + * This program and the accompanying materials are made available under the + * terms of the Eclipse Distribution License v. 1.0 which is available at + * https://www.eclipse.org/org/documents/edl-v10.php. * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or - * without modification, are permitted provided that the following - * conditions are met: - * - * - Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided - * with the distribution. - * - * - Neither the name of the Eclipse Foundation, Inc. nor the - * names of its contributors may be used to endorse or promote - * products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND - * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * SPDX-License-Identifier: BSD-3-Clause */ package org.eclipse.jgit.attributes; @@ -52,21 +19,20 @@ import static org.junit.Assert.assertTrue; import java.io.IOException; import java.util.Collections; -import java.util.LinkedHashMap; import java.util.List; -import java.util.Map; import org.eclipse.jgit.api.Git; import org.eclipse.jgit.attributes.Attribute.State; import org.eclipse.jgit.dircache.DirCacheIterator; import org.eclipse.jgit.junit.RepositoryTestCase; import org.eclipse.jgit.lib.FileMode; +import org.eclipse.jgit.treewalk.CanonicalTreeParser; import org.eclipse.jgit.treewalk.TreeWalk; import org.junit.Before; import org.junit.Test; /** - * Tests attributes node behavior on the the index. + * Tests attributes node behavior on the index. */ public class AttributesNodeDirCacheIteratorTest extends RepositoryTestCase { @@ -80,8 +46,6 @@ public class AttributesNodeDirCacheIteratorTest extends RepositoryTestCase { private Git git; - private TreeWalk walk; - @Override @Before public void setUp() throws Exception { @@ -107,23 +71,25 @@ public class AttributesNodeDirCacheIteratorTest extends RepositoryTestCase { // Adds file to index git.add().addFilepattern(".").call(); - walk = beginWalk(); - - assertIteration(F, ".gitattributes"); - assertIteration(F, "readme.txt", asList(EOL_LF)); + try (TreeWalk walk = beginWalk()) { + assertIteration(walk, F, ".gitattributes"); + assertIteration(walk, F, "readme.txt", asList(EOL_LF)); - assertIteration(D, "src"); + assertIteration(walk, D, "src"); - assertIteration(D, "src/config"); - assertIteration(F, "src/config/.gitattributes"); - assertIteration(F, "src/config/readme.txt", asList(DELTA_UNSET)); - assertIteration(F, "src/config/windows.file", null); - assertIteration(F, "src/config/windows.txt", asList(DELTA_UNSET)); + assertIteration(walk, D, "src/config"); + assertIteration(walk, F, "src/config/.gitattributes"); + assertIteration(walk, F, "src/config/readme.txt", + asList(DELTA_UNSET)); + assertIteration(walk, F, "src/config/windows.file", null); + assertIteration(walk, F, "src/config/windows.txt", + asList(DELTA_UNSET)); - assertIteration(F, "windows.file", null); - assertIteration(F, "windows.txt", asList(EOL_LF)); + assertIteration(walk, F, "windows.file", null); + assertIteration(walk, F, "windows.txt", asList(EOL_LF)); - endWalk(); + assertFalse("Not all files tested", walk.next()); + } } /** @@ -140,17 +106,18 @@ public class AttributesNodeDirCacheIteratorTest extends RepositoryTestCase { // Adds file to index git.add().addFilepattern(".").call(); - walk = beginWalk(); - assertIteration(F, "l0.txt"); + try (TreeWalk walk = beginWalk()) { + assertIteration(walk, F, "l0.txt"); - assertIteration(D, "level1"); - assertIteration(F, "level1/l1.txt"); + assertIteration(walk, D, "level1"); + assertIteration(walk, F, "level1/l1.txt"); - assertIteration(D, "level1/level2"); - assertIteration(F, "level1/level2/l2.txt"); + assertIteration(walk, D, "level1/level2"); + assertIteration(walk, F, "level1/level2/l2.txt"); - endWalk(); + assertFalse("Not all files tested", walk.next()); + } } /** @@ -168,18 +135,19 @@ public class AttributesNodeDirCacheIteratorTest extends RepositoryTestCase { // Adds file to index git.add().addFilepattern(".").call(); - walk = beginWalk(); - assertIteration(F, ".gitattributes"); - assertIteration(F, "l0.txt"); + try (TreeWalk walk = beginWalk()) { + assertIteration(walk, F, ".gitattributes"); + assertIteration(walk, F, "l0.txt"); - assertIteration(D, "level1"); - assertIteration(F, "level1/l1.txt"); + assertIteration(walk, D, "level1"); + assertIteration(walk, F, "level1/l1.txt"); - assertIteration(D, "level1/level2"); - assertIteration(F, "level1/level2/l2.txt"); + assertIteration(walk, D, "level1/level2"); + assertIteration(walk, F, "level1/level2/l2.txt"); - endWalk(); + assertFalse("Not all files tested", walk.next()); + } } @Test @@ -193,18 +161,19 @@ public class AttributesNodeDirCacheIteratorTest extends RepositoryTestCase { // Adds file to index git.add().addFilepattern(".").call(); - walk = beginWalk(); - assertIteration(F, ".gitattributes"); + try (TreeWalk walk = beginWalk()) { + assertIteration(walk, F, ".gitattributes"); - assertIteration(D, "levelA"); - assertIteration(F, "levelA/.gitattributes"); - assertIteration(F, "levelA/lA.txt"); + assertIteration(walk, D, "levelA"); + assertIteration(walk, F, "levelA/.gitattributes"); + assertIteration(walk, F, "levelA/lA.txt"); - assertIteration(D, "levelB"); - assertIteration(F, "levelB/.gitattributes"); + assertIteration(walk, D, "levelB"); + assertIteration(walk, F, "levelB/.gitattributes"); - endWalk(); + assertFalse("Not all files tested", walk.next()); + } } @Test @@ -217,25 +186,27 @@ public class AttributesNodeDirCacheIteratorTest extends RepositoryTestCase { // Adds file to index git.add().addFilepattern(".").call(); - walk = beginWalk(); - assertIteration(F, "gitattributes"); + try (TreeWalk walk = beginWalk()) { + assertIteration(walk, F, "gitattributes"); - assertIteration(F, "l0.txt"); + assertIteration(walk, F, "l0.txt"); - assertIteration(D, "levelA"); - assertIteration(F, "levelA/file.gitattributes"); - assertIteration(F, "levelA/lA.txt"); + assertIteration(walk, D, "levelA"); + assertIteration(walk, F, "levelA/file.gitattributes"); + assertIteration(walk, F, "levelA/lA.txt"); - endWalk(); + assertFalse("Not all files tested", walk.next()); + } } - private void assertIteration(FileMode type, String pathName) + private void assertIteration(TreeWalk walk, FileMode type, String pathName) throws IOException { - assertIteration(type, pathName, Collections.<Attribute> emptyList()); + assertIteration(walk, type, pathName, + Collections.<Attribute> emptyList()); } - private void assertIteration(FileMode type, String pathName, + private void assertIteration(TreeWalk walk, FileMode type, String pathName, List<Attribute> nodeAttrs) throws IOException { assertTrue("walk has entry", walk.next()); assertEquals(pathName, walk.getPathString()); @@ -243,27 +214,32 @@ public class AttributesNodeDirCacheIteratorTest extends RepositoryTestCase { DirCacheIterator itr = walk.getTree(0, DirCacheIterator.class); assertNotNull("has tree", itr); - AttributesNode attributeNode = itr.getEntryAttributesNode(db + AttributesNode attributesNode = itr.getEntryAttributesNode(db .newObjectReader()); - assertAttributeNode(pathName, attributeNode, nodeAttrs); + assertAttributesNode(walk, pathName, attributesNode, nodeAttrs); if (D.equals(type)) walk.enterSubtree(); } - private void assertAttributeNode(String pathName, - AttributesNode attributeNode, List<Attribute> nodeAttrs) { - if (attributeNode == null) + private void assertAttributesNode(TreeWalk walk, String pathName, + AttributesNode attributesNode, List<Attribute> nodeAttrs) + throws IOException { + if (attributesNode == null) assertTrue(nodeAttrs == null || nodeAttrs.isEmpty()); else { - Map<String, Attribute> entryAttributes = new LinkedHashMap<String, Attribute>(); - attributeNode.getAttributes(pathName, false, entryAttributes); + Attributes entryAttributes = new Attributes(); + new AttributesHandler(walk, + () -> walk.getTree(CanonicalTreeParser.class)) + .mergeAttributes(attributesNode, pathName, false, + entryAttributes); if (nodeAttrs != null && !nodeAttrs.isEmpty()) { for (Attribute attribute : nodeAttrs) { - assertThat(entryAttributes.values(), hasItem(attribute)); + assertThat(entryAttributes.getAll(), + hasItem(attribute)); } } else { assertTrue( @@ -289,8 +265,4 @@ public class AttributesNodeDirCacheIteratorTest extends RepositoryTestCase { newWalk.addTree(new DirCacheIterator(db.readDirCache())); return newWalk; } - - private void endWalk() throws IOException { - assertFalse("Not all files tested", walk.next()); - } } |