[ 
https://issues.apache.org/jira/browse/OPENNLP-1519?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Sujithra Rajan updated OPENNLP-1519:
------------------------------------
    Description: 
Three tests
 * `opennlp.tools.dictionary.DictionaryAsSetCaseInsensitiveTest.testEquals`
 * 
`opennlp.tools.dictionary.DictionaryAsSetCaseInsensitiveTest.testEqualsDifferentCase`
 * `opennlp.tools.dictionary.DictionaryAsSetCaseInsensitiveTest.testEquals`

The tests fail because in the `equals` method for comparing elements within a 
Set also handles the ordering of elements as well.

The `entrySet` here is a HashSet which doesn't maintain a constant order as 
mentioned in the 
[Java_17_documentation][https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/util/HashSet.html].

/opennlp-tools/src/main/java/opennlp/tools/dictionary/Dictionary.java:95

Encountered the following error messages:
{quote}org.opentest4j.AssertionFailedError: expected: <[1a, 1b]> but was: <[1b, 
1a]>
at 
opennlp.tools.dictionary.DictionaryAsSetCaseInsensitiveTest.testEquals(DictionaryAsSetCaseInsensitiveTest.java:121)
{quote}
{quote}org.opentest4j.AssertionFailedError: expected: <[1a, 1b]> but was: <[1B, 
1A]>
at 
opennlp.tools.dictionary.DictionaryAsSetCaseInsensitiveTest.testEqualsDifferentCase(DictionaryAsSetCaseInsensitiveTest.java:142)
{quote}
{quote}org.opentest4j.AssertionFailedError: expected: <[1a, 1b]> but was: <[1b, 
1a]>
at 
opennlp.tools.dictionary.DictionaryAsSetCaseSensitiveTest.testEquals(DictionaryAsSetCaseInsensitiveTest.java:121)
{quote}
 

The solution involves updating the assert statements to validate the presence 
of all elements regardless of their order.

{*}REPRODUCE{*}:

```

mvn edu.illinois:nondex-maven-plugin:2.1.7-SNAPSHOT:nondex 
-Dtest=opennlp.tools.dictionary.DictionaryAsSetCaseInsensitiveTest#testEquals

```

 Can I proceed and create PR ?

  was:
Two tests
 * `opennlp.tools.dictionary.DictionaryAsSetCaseInsensitiveTest.testEquals`
 * 
`opennlp.tools.dictionary.DictionaryAsSetCaseInsensitiveTest.testEqualsDifferentCase`
 * `opennlp.tools.dictionary.DictionaryAsSetCaseSensitiveTest.testEquals`

uses HashSet for entrySet while initializing the 'Dictionary' and thus the 
order is not constant all the time.

This was found by using the 
[NonDex][https://github.com/TestingResearchIllinois/NonDex] tool.

Encountered the following error messages:
{quote}org.opentest4j.AssertionFailedError: expected: <[1a, 1b]> but was: <[1b, 
1a]>
at 
opennlp.tools.dictionary.DictionaryAsSetCaseInsensitiveTest.testEquals(DictionaryAsSetCaseInsensitiveTest.java:121)
{quote}
{quote}org.opentest4j.AssertionFailedError: expected: <[1a, 1b]> but was: <[1B, 
1A]>
at 
opennlp.tools.dictionary.DictionaryAsSetCaseInsensitiveTest.testEqualsDifferentCase(DictionaryAsSetCaseInsensitiveTest.java:142)
{quote}
{quote}org.opentest4j.AssertionFailedError: expected: <[[Berlin], [Stockholm], 
[New,York], [London], [Copenhagen], [Paris]]> but was: <[[Copenhagen], 
[London], [New,York], [Stockholm], [Paris], [Berlin]]>
at 
opennlp.uima.dictionary.DictionaryResourceTest.testDictionaryWasLoaded(DictionaryResourceTest.java:76)
{quote}
 

The fix is to change HashSet to LinkedHashSet so that the iteration order 
remains stable all the time. 

Assertion statement of 'testDictionaryWasLoaded' was modified to match the 
exact ordering of dictionary.dic.

 

{*}REPRODUCE{*}:

```

mvn edu.illinois:nondex-maven-plugin:2.1.7-SNAPSHOT:nondex 
-Dtest=opennlp.tools.dictionary.DictionaryAsSetCaseInsensitiveTest#testEquals

```

 Can I proceed and create PR ?


> Modified 3 tests in opennlp-tools to handle any iteration order
> ---------------------------------------------------------------
>
>                 Key: OPENNLP-1519
>                 URL: https://issues.apache.org/jira/browse/OPENNLP-1519
>             Project: OpenNLP
>          Issue Type: Improvement
>            Reporter: Sujithra Rajan
>            Priority: Minor
>
> Three tests
>  * `opennlp.tools.dictionary.DictionaryAsSetCaseInsensitiveTest.testEquals`
>  * 
> `opennlp.tools.dictionary.DictionaryAsSetCaseInsensitiveTest.testEqualsDifferentCase`
>  * `opennlp.tools.dictionary.DictionaryAsSetCaseInsensitiveTest.testEquals`
> The tests fail because in the `equals` method for comparing elements within a 
> Set also handles the ordering of elements as well.
> The `entrySet` here is a HashSet which doesn't maintain a constant order as 
> mentioned in the 
> [Java_17_documentation][https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/util/HashSet.html].
> /opennlp-tools/src/main/java/opennlp/tools/dictionary/Dictionary.java:95
> Encountered the following error messages:
> {quote}org.opentest4j.AssertionFailedError: expected: <[1a, 1b]> but was: 
> <[1b, 1a]>
> at 
> opennlp.tools.dictionary.DictionaryAsSetCaseInsensitiveTest.testEquals(DictionaryAsSetCaseInsensitiveTest.java:121)
> {quote}
> {quote}org.opentest4j.AssertionFailedError: expected: <[1a, 1b]> but was: 
> <[1B, 1A]>
> at 
> opennlp.tools.dictionary.DictionaryAsSetCaseInsensitiveTest.testEqualsDifferentCase(DictionaryAsSetCaseInsensitiveTest.java:142)
> {quote}
> {quote}org.opentest4j.AssertionFailedError: expected: <[1a, 1b]> but was: 
> <[1b, 1a]>
> at 
> opennlp.tools.dictionary.DictionaryAsSetCaseSensitiveTest.testEquals(DictionaryAsSetCaseInsensitiveTest.java:121)
> {quote}
>  
> The solution involves updating the assert statements to validate the presence 
> of all elements regardless of their order.
> {*}REPRODUCE{*}:
> ```
> mvn edu.illinois:nondex-maven-plugin:2.1.7-SNAPSHOT:nondex 
> -Dtest=opennlp.tools.dictionary.DictionaryAsSetCaseInsensitiveTest#testEquals
> ```
>  Can I proceed and create PR ?



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to