diff options
author | Ivan Motsch <ivan.motsch@bsiag.com> | 2015-11-17 13:32:20 +0100 |
---|---|---|
committer | Ivan Motsch <ivan.motsch@bsiag.com> | 2015-11-27 11:40:34 +0100 |
commit | 75697adc5a0024449351aacac89618c3b83add11 (patch) | |
tree | e50cae59d87dc42ef2fe7ebc932e3371bf0602c9 /org.eclipse.jgit.test | |
parent | adbe9006831a5d03a3513f4a09dbda8703e19f7c (diff) | |
download | jgit-75697adc5a0024449351aacac89618c3b83add11.tar.gz jgit-75697adc5a0024449351aacac89618c3b83add11.zip |
Add the new class Attributes holding multiple Attribute(s)
Attributes represents a semantic collector of Attribute(s) and replaces
the anonymous Map<String,Attribute>. This class will be returned by
TreeWalk.getAttributes(). It offers convenient access to the attributes
wrapped in the Attributes object. Adds preparations for a future
Attribute Macro Expansion
Change-Id: I8348c8c457a2a7f1f0c48050e10399b0fa1cdbe1
Signed-off-by: Ivan Motsch <ivan.motsch@bsiag.com>
Diffstat (limited to 'org.eclipse.jgit.test')
4 files changed, 23 insertions, 29 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 3e6ca62202..0e595e61f8 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 @@ -52,9 +52,7 @@ 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; @@ -258,12 +256,14 @@ public class AttributesNodeDirCacheIteratorTest extends RepositoryTestCase { assertTrue(nodeAttrs == null || nodeAttrs.isEmpty()); else { - Map<String, Attribute> entryAttributes = new LinkedHashMap<String, Attribute>(); - attributesNode.getAttributes(pathName, false, entryAttributes); + Attributes entryAttributes = new Attributes(); + attributesNode.getAttributes(pathName, + false, entryAttributes); if (nodeAttrs != null && !nodeAttrs.isEmpty()) { for (Attribute attribute : nodeAttrs) { - assertThat(entryAttributes.values(), hasItem(attribute)); + assertThat(entryAttributes.getAll(), + hasItem(attribute)); } } else { assertTrue( diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/attributes/AttributesNodeTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/attributes/AttributesNodeTest.java index d82baaa36e..d478a7cf08 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/attributes/AttributesNodeTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/attributes/AttributesNodeTest.java @@ -49,10 +49,6 @@ import static org.junit.Assert.assertEquals; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Set; import org.junit.After; import org.junit.Test; @@ -104,8 +100,8 @@ public class AttributesNodeTest { is = new ByteArrayInputStream(attributeFileContent.getBytes()); AttributesNode node = new AttributesNode(); node.parse(is); - assertAttribute("file.type1", node, Collections.<Attribute> emptySet()); - assertAttribute("file.type2", node, Collections.<Attribute> emptySet()); + assertAttribute("file.type1", node, new Attributes()); + assertAttribute("file.type2", node, new Attributes()); } @Test @@ -115,7 +111,7 @@ public class AttributesNodeTest { is = new ByteArrayInputStream(attributeFileContent.getBytes()); AttributesNode node = new AttributesNode(); node.parse(is); - assertAttribute("file.type1", node, Collections.<Attribute> emptySet()); + assertAttribute("file.type1", node, new Attributes()); assertAttribute("file.type2", node, asSet(A_UNSET_ATTR)); } @@ -127,8 +123,8 @@ public class AttributesNodeTest { is = new ByteArrayInputStream(attributeFileContent.getBytes()); AttributesNode node = new AttributesNode(); node.parse(is); - assertAttribute("file.type1", node, Collections.<Attribute> emptySet()); - assertAttribute("file.type2", node, Collections.<Attribute> emptySet()); + assertAttribute("file.type1", node, new Attributes()); + assertAttribute("file.type2", node, new Attributes()); assertAttribute("file.type3", node, asSet(new Attribute("attr", ""))); } @@ -166,17 +162,14 @@ public class AttributesNodeTest { } private void assertAttribute(String path, AttributesNode node, - Set<Attribute> attrs) { - HashMap<String, Attribute> attributes = new HashMap<String, Attribute>(); + Attributes attrs) { + Attributes attributes = new Attributes(); node.getAttributes(path, false, attributes); - assertEquals(attrs, new HashSet<Attribute>(attributes.values())); + assertEquals(attrs, attributes); } - static Set<Attribute> asSet(Attribute... attrs) { - Set<Attribute> result = new HashSet<Attribute>(); - for (Attribute attr : attrs) - result.add(attr); - return result; + static Attributes asSet(Attribute... attrs) { + return new Attributes(attrs); } } diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/attributes/AttributesNodeWorkingTreeIteratorTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/attributes/AttributesNodeWorkingTreeIteratorTest.java index bcf17174b8..6ad19a2491 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/attributes/AttributesNodeWorkingTreeIteratorTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/attributes/AttributesNodeWorkingTreeIteratorTest.java @@ -53,9 +53,7 @@ import static org.junit.Assert.assertTrue; import java.io.File; import java.io.IOException; import java.util.Collections; -import java.util.LinkedHashMap; import java.util.List; -import java.util.Map; import org.eclipse.jgit.attributes.Attribute.State; import org.eclipse.jgit.errors.CorruptObjectException; @@ -227,12 +225,14 @@ public class AttributesNodeWorkingTreeIteratorTest extends RepositoryTestCase { assertTrue(nodeAttrs == null || nodeAttrs.isEmpty()); else { - Map<String, Attribute> entryAttributes = new LinkedHashMap<String, Attribute>(); - attributesNode.getAttributes(pathName, false, entryAttributes); + Attributes entryAttributes = new Attributes(); + attributesNode.getAttributes(pathName, + false, entryAttributes); if (nodeAttrs != null && !nodeAttrs.isEmpty()) { for (Attribute attribute : nodeAttrs) { - assertThat(entryAttributes.values(), hasItem(attribute)); + assertThat(entryAttributes.getAll(), + hasItem(attribute)); } } else { assertTrue( diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/attributes/TreeWalkAttributeTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/attributes/TreeWalkAttributeTest.java index c3d5e8752c..b044c01db6 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/attributes/TreeWalkAttributeTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/attributes/TreeWalkAttributeTest.java @@ -802,8 +802,9 @@ public class TreeWalkAttributeTest extends RepositoryTestCase { assertEquals(type, walk.getFileMode(0)); assertEquals(checkinAttributes, - asSet(ci_walk.getAttributes().values())); - assertEquals(checkoutAttributes, asSet(walk.getAttributes().values())); + asSet(ci_walk.getAttributes().getAll())); + assertEquals(checkoutAttributes, + asSet(walk.getAttributes().getAll())); if (D.equals(type)) { walk.enterSubtree(); |