This is an automated email from the ASF dual-hosted git repository. sebb pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-jxpath.git
The following commit(s) were added to refs/heads/master by this push: new 7714436 Normalise EOL 7714436 is described below commit 771443602176b0c84cfd513fc8b1b32f555632c0 Author: Sebb <s...@apache.org> AuthorDate: Sat Jan 18 22:40:06 2025 +0000 Normalise EOL --- .gitattributes | 17 ++ README.md | 204 ++++++++--------- .../commons/jxpath/issues/JXPath118Test.java | 168 +++++++------- .../commons/jxpath/issues/JXPath177Test.java | 254 ++++++++++----------- .../apache/commons/jxpath/util/ValueUtilsTest.java | 180 +++++++-------- 5 files changed, 420 insertions(+), 403 deletions(-) diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..0304f7e --- /dev/null +++ b/.gitattributes @@ -0,0 +1,17 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +* text=auto +*.bat -text \ No newline at end of file diff --git a/README.md b/README.md index feb2488..2b5853a 100644 --- a/README.md +++ b/README.md @@ -1,103 +1,103 @@ -<!--- - Licensed to the Apache Software Foundation (ASF) under one or more - contributor license agreements. See the NOTICE file distributed with - this work for additional information regarding copyright ownership. - The ASF licenses this file to You under the Apache License, Version 2.0 - (the "License"); you may not use this file except in compliance with - the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. ---> -<!--- - +======================================================================+ - |**** ****| - |**** THIS FILE IS GENERATED BY THE COMMONS BUILD PLUGIN ****| - |**** DO NOT EDIT DIRECTLY ****| - |**** ****| - +======================================================================+ - | TEMPLATE FILE: readme-md-template.md | - | commons-build-plugin/trunk/src/main/resources/commons-xdoc-templates | - +======================================================================+ - | | - | 1) Re-generate using: mvn commons:readme-md | - | | - | 2) Set the following properties in the component's pom: | - | - commons.componentid (required, alphabetic, lower case) | - | - commons.release.version (required) | - | | - | 3) Example Properties | - | | - | <properties> | - | <commons.componentid>math</commons.componentid> | - | <commons.release.version>1.2</commons.release.version> | - | </properties> | - | | - +======================================================================+ ----> -Apache Commons JXPath -=================== - +<!--- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> +<!--- + +======================================================================+ + |**** ****| + |**** THIS FILE IS GENERATED BY THE COMMONS BUILD PLUGIN ****| + |**** DO NOT EDIT DIRECTLY ****| + |**** ****| + +======================================================================+ + | TEMPLATE FILE: readme-md-template.md | + | commons-build-plugin/trunk/src/main/resources/commons-xdoc-templates | + +======================================================================+ + | | + | 1) Re-generate using: mvn commons:readme-md | + | | + | 2) Set the following properties in the component's pom: | + | - commons.componentid (required, alphabetic, lower case) | + | - commons.release.version (required) | + | | + | 3) Example Properties | + | | + | <properties> | + | <commons.componentid>math</commons.componentid> | + | <commons.release.version>1.2</commons.release.version> | + | </properties> | + | | + +======================================================================+ +---> +Apache Commons JXPath +=================== + [](https://github.com/apache/commons-jxpath/actions/workflows/maven.yml) -[](https://search.maven.org/artifact/commons-jxpath/commons-jxpath) - -A Java-based implementation of XPath 1.0 that, in addition to XML processing, can inspect/modify Java object graphs (the library's explicit purpose) and even mixed Java/XML structures. - -Documentation -------------- - -More information can be found on the [Apache Commons JXPath homepage](https://commons.apache.org/proper/commons-jxpath). -The [Javadoc](https://commons.apache.org/proper/commons-jxpath/javadocs/api-release) can be browsed. -Questions related to the usage of Apache Commons JXPath should be posted to the [user mailing list](https://commons.apache.org/mail-lists.html). - -Where can I get the latest release? ------------------------------------ -You can download source and binaries from our [download page](https://commons.apache.org/proper/commons-jxpath/download_jxpath.cgi). - -Alternatively, you can pull it from the central Maven repositories: - -```xml -<dependency> - <groupId>commons-jxpath</groupId> - <artifactId>commons-jxpath</artifactId> - <version>1.3</version> -</dependency> -``` - -Contributing ------------- - -We accept Pull Requests via GitHub. The [developer mailing list][ml] is the main channel of communication for contributors. -There are some guidelines which will make applying PRs easier for us: -+ No tabs! Please use spaces for indentation. -+ Respect the code style. -+ Create minimal diffs - disable on save actions like reformat source code or organize imports. If you feel the source code should be reformatted create a separate PR for this change. -+ Provide JUnit tests for your changes and make sure your changes don't break any existing tests by running ```mvn clean test```. - -If you plan to contribute on a regular basis, please consider filing a [contributor license agreement](https://www.apache.org/licenses/#clas). -You can learn more about contributing via GitHub in our [contribution guidelines](CONTRIBUTING.md). - -License -------- -This code is under the [Apache Licence v2](https://www.apache.org/licenses/LICENSE-2.0). - -See the `NOTICE.txt` file for required notices and attributions. - -Donations ---------- -You like Apache Commons JXPath? Then [donate back to the ASF](https://www.apache.org/foundation/contributing.html) to support the development. - -Additional Resources --------------------- - -+ [Apache Commons Homepage](https://commons.apache.org/) -+ [Apache Issue Tracker (JIRA)](https://issues.apache.org/jira/browse/JXPATH) -+ [Apache Commons Twitter Account](https://twitter.com/ApacheCommons) -+ `#apache-commons` IRC channel on `irc.freenode.org` - -[ml]:https://commons.apache.org/mail-lists.html +[](https://search.maven.org/artifact/commons-jxpath/commons-jxpath) + +A Java-based implementation of XPath 1.0 that, in addition to XML processing, can inspect/modify Java object graphs (the library's explicit purpose) and even mixed Java/XML structures. + +Documentation +------------- + +More information can be found on the [Apache Commons JXPath homepage](https://commons.apache.org/proper/commons-jxpath). +The [Javadoc](https://commons.apache.org/proper/commons-jxpath/javadocs/api-release) can be browsed. +Questions related to the usage of Apache Commons JXPath should be posted to the [user mailing list](https://commons.apache.org/mail-lists.html). + +Where can I get the latest release? +----------------------------------- +You can download source and binaries from our [download page](https://commons.apache.org/proper/commons-jxpath/download_jxpath.cgi). + +Alternatively, you can pull it from the central Maven repositories: + +```xml +<dependency> + <groupId>commons-jxpath</groupId> + <artifactId>commons-jxpath</artifactId> + <version>1.3</version> +</dependency> +``` + +Contributing +------------ + +We accept Pull Requests via GitHub. The [developer mailing list][ml] is the main channel of communication for contributors. +There are some guidelines which will make applying PRs easier for us: ++ No tabs! Please use spaces for indentation. ++ Respect the code style. ++ Create minimal diffs - disable on save actions like reformat source code or organize imports. If you feel the source code should be reformatted create a separate PR for this change. ++ Provide JUnit tests for your changes and make sure your changes don't break any existing tests by running ```mvn clean test```. + +If you plan to contribute on a regular basis, please consider filing a [contributor license agreement](https://www.apache.org/licenses/#clas). +You can learn more about contributing via GitHub in our [contribution guidelines](CONTRIBUTING.md). + +License +------- +This code is under the [Apache Licence v2](https://www.apache.org/licenses/LICENSE-2.0). + +See the `NOTICE.txt` file for required notices and attributions. + +Donations +--------- +You like Apache Commons JXPath? Then [donate back to the ASF](https://www.apache.org/foundation/contributing.html) to support the development. + +Additional Resources +-------------------- + ++ [Apache Commons Homepage](https://commons.apache.org/) ++ [Apache Issue Tracker (JIRA)](https://issues.apache.org/jira/browse/JXPATH) ++ [Apache Commons Twitter Account](https://twitter.com/ApacheCommons) ++ `#apache-commons` IRC channel on `irc.freenode.org` + +[ml]:https://commons.apache.org/mail-lists.html diff --git a/src/test/java/org/apache/commons/jxpath/issues/JXPath118Test.java b/src/test/java/org/apache/commons/jxpath/issues/JXPath118Test.java index d1c2b8f..d2e7585 100644 --- a/src/test/java/org/apache/commons/jxpath/issues/JXPath118Test.java +++ b/src/test/java/org/apache/commons/jxpath/issues/JXPath118Test.java @@ -1,84 +1,84 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.commons.jxpath.issues; - -import java.util.Iterator; - -import org.apache.commons.jxpath.JXPathContext; -import org.apache.commons.jxpath.Pointer; - -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -/** - * Testcase proving JXPATH-118 issue with asPath() returning wrong names. - */ -public class JXPath118Test -{ - - @Test - public void testJXPATH118IssueWithAsPath() throws Exception - { - final Object contextBean = new SomeChildClass(); - final JXPathContext context = JXPathContext.newContext(contextBean); - final Iterator<Pointer> iteratePointers = context.iteratePointers("//*"); - assertEquals("/bar", iteratePointers.next().asPath()); - assertEquals("/baz", iteratePointers.next().asPath()); - assertEquals("/foo", iteratePointers.next().asPath()); - } - - public static class SomeChildClass - { - - private int foo = 1; - private int bar = 2; - private int baz = 3; - - public int getFoo() - { - return foo; - } - - public void setFoo(final int foo) - { - this.foo = foo; - } - - public int getBar() - { - return bar; - } - - public void setBar(final int bar) - { - this.bar = bar; - } - - public int getBaz() - { - return baz; - } - - public void setBaz(final int baz) - { - this.baz = baz; - } - - } - -} +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.commons.jxpath.issues; + +import java.util.Iterator; + +import org.apache.commons.jxpath.JXPathContext; +import org.apache.commons.jxpath.Pointer; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +/** + * Testcase proving JXPATH-118 issue with asPath() returning wrong names. + */ +public class JXPath118Test +{ + + @Test + public void testJXPATH118IssueWithAsPath() throws Exception + { + final Object contextBean = new SomeChildClass(); + final JXPathContext context = JXPathContext.newContext(contextBean); + final Iterator<Pointer> iteratePointers = context.iteratePointers("//*"); + assertEquals("/bar", iteratePointers.next().asPath()); + assertEquals("/baz", iteratePointers.next().asPath()); + assertEquals("/foo", iteratePointers.next().asPath()); + } + + public static class SomeChildClass + { + + private int foo = 1; + private int bar = 2; + private int baz = 3; + + public int getFoo() + { + return foo; + } + + public void setFoo(final int foo) + { + this.foo = foo; + } + + public int getBar() + { + return bar; + } + + public void setBar(final int bar) + { + this.bar = bar; + } + + public int getBaz() + { + return baz; + } + + public void setBaz(final int baz) + { + this.baz = baz; + } + + } + +} diff --git a/src/test/java/org/apache/commons/jxpath/issues/JXPath177Test.java b/src/test/java/org/apache/commons/jxpath/issues/JXPath177Test.java index fae75b5..d440e2e 100644 --- a/src/test/java/org/apache/commons/jxpath/issues/JXPath177Test.java +++ b/src/test/java/org/apache/commons/jxpath/issues/JXPath177Test.java @@ -1,127 +1,127 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.commons.jxpath.issues; - -import java.util.HashMap; -import java.util.Map; - -import org.apache.commons.jxpath.JXPathContext; -import org.apache.commons.jxpath.Pointer; -import org.apache.commons.jxpath.Variables; - -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; - -public class JXPath177Test -{ - Map model = new HashMap(); - { - - model.put("name", "ROOT name"); - final HashMap x = new HashMap(); - model.put("x", x); - x.put("name", "X name"); - } - - @Test - public void testJx177() - { - doTest("name", "ROOT name"); - doTest("/x/name", "X name"); - doTest("$__root/x/name", "X name"); - } - - @Test - public void testJx177_Union1() - { - doTest("$__root/x/name|name", "X name"); - - } - - @Test - public void testJx177_Union2() - { - doTest("$__root/x/unexisting|name", "ROOT name"); - - } - - private void doTest(final String xp, final String expected) - { - final JXPathContext xpathContext = JXPathContext.newContext(model); - xpathContext.setVariables(new JXPathVariablesResolver(model)); - final Pointer p = xpathContext.getPointer(xp); - final Object result = p.getNode(); - assertNotNull(result); - assertEquals(expected, result); - - } - - private static final class JXPathVariablesResolver implements Variables - { - - private static final long serialVersionUID = -1106360826446119597L; - - public static final String ROOT_VAR = "__root"; - - private final Object root; - - public JXPathVariablesResolver(final Object root) - { - this.root = root; - } - - @Override - public boolean isDeclaredVariable(final String varName) - { - if (varName == null) - { - throw new IllegalArgumentException("varName"); - } - return varName.equals(ROOT_VAR); - } - - @Override - public Object getVariable(final String varName) - { - if (varName == null) - { - throw new IllegalArgumentException("varName"); - } - if (!varName.equals(ROOT_VAR)) - { - throw new IllegalArgumentException("Variable is not declared: " + varName); - } - - return root; - } - - @Override - public void declareVariable(final String varName, final Object value) - { - throw new UnsupportedOperationException(); - } - - @Override - public void undeclareVariable(final String varName) - { - throw new UnsupportedOperationException(); - } - - } -} +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.commons.jxpath.issues; + +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.jxpath.JXPathContext; +import org.apache.commons.jxpath.Pointer; +import org.apache.commons.jxpath.Variables; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +public class JXPath177Test +{ + Map model = new HashMap(); + { + + model.put("name", "ROOT name"); + final HashMap x = new HashMap(); + model.put("x", x); + x.put("name", "X name"); + } + + @Test + public void testJx177() + { + doTest("name", "ROOT name"); + doTest("/x/name", "X name"); + doTest("$__root/x/name", "X name"); + } + + @Test + public void testJx177_Union1() + { + doTest("$__root/x/name|name", "X name"); + + } + + @Test + public void testJx177_Union2() + { + doTest("$__root/x/unexisting|name", "ROOT name"); + + } + + private void doTest(final String xp, final String expected) + { + final JXPathContext xpathContext = JXPathContext.newContext(model); + xpathContext.setVariables(new JXPathVariablesResolver(model)); + final Pointer p = xpathContext.getPointer(xp); + final Object result = p.getNode(); + assertNotNull(result); + assertEquals(expected, result); + + } + + private static final class JXPathVariablesResolver implements Variables + { + + private static final long serialVersionUID = -1106360826446119597L; + + public static final String ROOT_VAR = "__root"; + + private final Object root; + + public JXPathVariablesResolver(final Object root) + { + this.root = root; + } + + @Override + public boolean isDeclaredVariable(final String varName) + { + if (varName == null) + { + throw new IllegalArgumentException("varName"); + } + return varName.equals(ROOT_VAR); + } + + @Override + public Object getVariable(final String varName) + { + if (varName == null) + { + throw new IllegalArgumentException("varName"); + } + if (!varName.equals(ROOT_VAR)) + { + throw new IllegalArgumentException("Variable is not declared: " + varName); + } + + return root; + } + + @Override + public void declareVariable(final String varName, final Object value) + { + throw new UnsupportedOperationException(); + } + + @Override + public void undeclareVariable(final String varName) + { + throw new UnsupportedOperationException(); + } + + } +} diff --git a/src/test/java/org/apache/commons/jxpath/util/ValueUtilsTest.java b/src/test/java/org/apache/commons/jxpath/util/ValueUtilsTest.java index d8e07bb..cc1e01b 100644 --- a/src/test/java/org/apache/commons/jxpath/util/ValueUtilsTest.java +++ b/src/test/java/org/apache/commons/jxpath/util/ValueUtilsTest.java @@ -1,90 +1,90 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.commons.jxpath.util; - -import java.util.Arrays; -import java.util.Collections; -import java.util.HashSet; -import java.util.Set; - -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.assertNull; -import static org.junit.jupiter.api.Assertions.assertSame; - -public class ValueUtilsTest { - - @Test - public void testGetValueFromArrayTooSmall() { - assertNull(ValueUtils.getValue(new Object[0], 2)); - } - - @Test - public void testGetValueFromListTooSmall() { - assertNull(ValueUtils.getValue(Collections.EMPTY_LIST, 2)); - } - - /* - * This test would break without the patch and an NoSuchElementException being - * thrown instead. - */ - @Test - public void testGetValueFromSetTooSmall() { - assertNull(ValueUtils.getValue(Collections.EMPTY_SET, 2)); - } - - @Test - public void testGetValueFromArray() { - final Object data = new Object(); - assertSame(data, ValueUtils.getValue(new Object[] {data}, 0)); - } - - @Test - public void testGetValueFromList() { - final Object data = new Object(); - assertSame(data, ValueUtils.getValue(Arrays.asList(data), 0)); - } - - @Test - public void testGetValueFromSet() { - final Object data = new Object(); - final Set dataSet = new HashSet(); - dataSet.add(data); - assertSame(data, ValueUtils.getValue(dataSet, 0)); - } - - @Test - public void testGetValueFromArrayNegativeIndex() { - final Object data = new Object(); - assertNull(ValueUtils.getValue(new Object[] {data}, -1)); - } - - @Test - public void testGetValueFromListNegativeIndex() { - final Object data = new Object(); - final Object res = ValueUtils.getValue(Arrays.asList(data), -1); - assertNull(res, "Expected null, is " + res); - } - - @Test - public void testGetValueFromSetNegativeIndex() { - final Object data = new Object(); - final Set dataSet = new HashSet(); - dataSet.add(data); - assertNull(ValueUtils.getValue(dataSet, -1)); - } -} +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.commons.jxpath.util; + +import java.util.Arrays; +import java.util.Collections; +import java.util.HashSet; +import java.util.Set; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertSame; + +public class ValueUtilsTest { + + @Test + public void testGetValueFromArrayTooSmall() { + assertNull(ValueUtils.getValue(new Object[0], 2)); + } + + @Test + public void testGetValueFromListTooSmall() { + assertNull(ValueUtils.getValue(Collections.EMPTY_LIST, 2)); + } + + /* + * This test would break without the patch and an NoSuchElementException being + * thrown instead. + */ + @Test + public void testGetValueFromSetTooSmall() { + assertNull(ValueUtils.getValue(Collections.EMPTY_SET, 2)); + } + + @Test + public void testGetValueFromArray() { + final Object data = new Object(); + assertSame(data, ValueUtils.getValue(new Object[] {data}, 0)); + } + + @Test + public void testGetValueFromList() { + final Object data = new Object(); + assertSame(data, ValueUtils.getValue(Arrays.asList(data), 0)); + } + + @Test + public void testGetValueFromSet() { + final Object data = new Object(); + final Set dataSet = new HashSet(); + dataSet.add(data); + assertSame(data, ValueUtils.getValue(dataSet, 0)); + } + + @Test + public void testGetValueFromArrayNegativeIndex() { + final Object data = new Object(); + assertNull(ValueUtils.getValue(new Object[] {data}, -1)); + } + + @Test + public void testGetValueFromListNegativeIndex() { + final Object data = new Object(); + final Object res = ValueUtils.getValue(Arrays.asList(data), -1); + assertNull(res, "Expected null, is " + res); + } + + @Test + public void testGetValueFromSetNegativeIndex() { + final Object data = new Object(); + final Set dataSet = new HashSet(); + dataSet.add(data); + assertNull(ValueUtils.getValue(dataSet, -1)); + } +}