[ 
https://issues.apache.org/jira/browse/OPENNLP-1519?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17787695#comment-17787695
 ] 

ASF GitHub Bot commented on OPENNLP-1519:
-----------------------------------------

Sujishark opened a new pull request, #556:
URL: https://github.com/apache/opennlp/pull/556

   This PR aims to fix three tests. 
   
   Module: opennlp-tools
   ```
   opennlp.tools.dictionary.DictionaryAsSetCaseInsensitiveTest.testEquals
   
opennlp.tools.dictionary.DictionaryAsSetCaseInsensitiveTest.testEqualsDifferentCase
   ```
   Module: opennlp-uima
   ```
   opennlp.uima.dictionary.DictionaryResourceTest.testDictionaryWasLoaded
   ```
   The tests fail because of the use of HashSet for entrySet while initializing 
the Dictionary as it doesn't maintain a constant order as mentioned in the 
[documentation](https://docs.oracle.com/javase/8/docs/api/java/util/HashSet.html).
   
   
https://github.com/apache/opennlp/blob/dab19af803e9139b57b972eb4e1af4c978d2ff3f/opennlp-tools/src/main/java/opennlp/tools/dictionary/Dictionary.java#L95
   
   The error message is as follows:
   
   > org.opentest4j.AssertionFailedError: expected: <[1a, 1b]> but was: <[1b, 
1a]>
   at 
opennlp.tools.dictionary.DictionaryAsSetCaseInsensitiveTest.testEquals(DictionaryAsSetCaseInsensitiveTest.java:121)
   
   > org.opentest4j.AssertionFailedError: expected: <[1a, 1b]> but was: <[1B, 
1A]>
   at 
opennlp.tools.dictionary.DictionaryAsSetCaseInsensitiveTest.testEqualsDifferentCase(DictionaryAsSetCaseInsensitiveTest.java:142)
   
   > 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)
   
   The fix is to change HashSet to LinkedHashSet so that the insertion order 
remains stable. Due to this change, the expected value in the assert statement 
should be adjusted according to the sequence of entries found in the 
'dictionary.dic' document
   
   **Reproduce:**
   
   This was found by using the 
[NonDex](https://github.com/TestingResearchIllinois/NonDex) tool.
   
   The following command can be used to replicate the failures and validate the 
fix:
   
   ```
   mvn edu.illinois:nondex-maven-plugin:2.1.7-SNAPSHOT:nondex 
-Dtest=opennlp.tools.dictionary.DictionaryAsSetCaseInsensitiveTest#testEquals
   ```
   
   **Environment:**
   
   > Java: openjdk version "17.0.9"
   > Maven: Apache Maven 3.6.3
   
   In order to streamline the review of the contribution we ask you
   to ensure the following steps have been taken:
   
   ### For all changes:
   - [x] Is there a JIRA ticket associated with this PR? Is it referenced 
        in the commit message?
   
   - [x] Does your PR title start with OPENNLP-XXXX where XXXX is the JIRA 
number you are trying to resolve? Pay particular attention to the hyphen "-" 
character.
   
   - [x] Has your PR been rebased against the latest commit within the target 
branch (typically main)?
   
   - [ ] Is your initial contribution a single, squashed commit?
   
   ### For code changes:
   - [x] Have you ensured that the full suite of tests is executed via mvn 
clean install at the root opennlp folder?
   - [x] Have you written or updated unit tests to verify your changes?
   - [] If adding new dependencies to the code, are these dependencies licensed 
in a way that is compatible for inclusion under [ASF 
2.0](http://www.apache.org/legal/resolved.html#category-a)? 
   - [ ] If applicable, have you updated the LICENSE file, including the main 
LICENSE file in opennlp folder?
   - [ ] If applicable, have you updated the NOTICE file, including the main 
NOTICE file found in opennlp folder?
   
   ### For documentation related changes:
   - [ ] Have you ensured that format looks appropriate for the output in which 
it is rendered?
   




> Use LinkedHashSet for deterministic iteration order
> ---------------------------------------------------
>
>                 Key: OPENNLP-1519
>                 URL: https://issues.apache.org/jira/browse/OPENNLP-1519
>             Project: OpenNLP
>          Issue Type: Improvement
>            Reporter: Sujithra Rajan
>            Priority: Minor
>
> Two tests
>  * `opennlp.tools.dictionary.DictionaryAsSetCaseInsensitiveTest.testEquals`
>  * 
> `opennlp.tools.dictionary.DictionaryAsSetCaseInsensitiveTest.testEqualsDifferentCase`
> 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 ?



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

Reply via email to