This is an automated email from the ASF dual-hosted git repository. rec pushed a commit to branch bugfix/320-Copy-of-FsIterator_set_sorted_pear-does-not-retain-position in repository https://gitbox.apache.org/repos/asf/uima-uimaj.git
commit 42c92c65d49ccba3da8bfde4571322a724f27ea7 Author: Richard Eckart de Castilho <r...@apache.org> AuthorDate: Fri Jul 7 14:47:49 2023 +0200 Issue #320: Copy of FsIterator_set_sorted_pear does not retain position - Fix issue in FsIterator_set_sorted_pear - Added unit test --- uimaj-core/pom.xml | 15 +++++++ .../uima/cas/impl/FsIterator_set_sorted2.java | 6 ++- .../uima/cas/impl/FsIterator_set_sorted_pear.java | 5 ++- .../cas/impl/FsIterator_set_sorted_pearTest.java | 49 ++++++++++++++++++++++ uimaj-parent/pom.xml | 25 +++++------ 5 files changed, 83 insertions(+), 17 deletions(-) diff --git a/uimaj-core/pom.xml b/uimaj-core/pom.xml index 910d94087..d82b532a5 100644 --- a/uimaj-core/pom.xml +++ b/uimaj-core/pom.xml @@ -128,6 +128,21 @@ <artifactId>assertj-core</artifactId> <scope>test</scope> </dependency> + <dependency> + <groupId>org.mockito</groupId> + <artifactId>mockito-core</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.mockito</groupId> + <artifactId>mockito-inline</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.mockito</groupId> + <artifactId>mockito-junit-jupiter</artifactId> + <scope>test</scope> + </dependency> <dependency> <groupId>commons-io</groupId> <artifactId>commons-io</artifactId> diff --git a/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIterator_set_sorted2.java b/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIterator_set_sorted2.java index 6dbad0f5b..47bc260a0 100644 --- a/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIterator_set_sorted2.java +++ b/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIterator_set_sorted2.java @@ -177,10 +177,14 @@ class FsIterator_set_sorted2<T extends FeatureStructure> extends FsIterator_sing public FsIterator_singletype<T> copy() { FsIterator_set_sorted2<T> r = new FsIterator_set_sorted2<>(ll_index, ofsa, comparatorMaybeNoTypeWithoutID); - r.pos = pos; + copyCommonSetup(r); return r; } + protected void copyCommonSetup(FsIterator_set_sorted2<T> copy) { + copy.pos = pos; + } + // /* (non-Javadoc) // * @see org.apache.uima.cas.FSIterator#getType() // */ diff --git a/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIterator_set_sorted_pear.java b/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIterator_set_sorted_pear.java index 1cc799b0c..f97c3e77a 100644 --- a/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIterator_set_sorted_pear.java +++ b/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIterator_set_sorted_pear.java @@ -47,6 +47,9 @@ class FsIterator_set_sorted_pear<T extends FeatureStructure> extends FsIterator_ @Override public FsIterator_set_sorted_pear<T> copy() { - return new FsIterator_set_sorted_pear<>(ll_index, ofsa, this.comparatorMaybeNoTypeWithoutID); + FsIterator_set_sorted_pear<T> r = new FsIterator_set_sorted_pear<>(ll_index, ofsa, + this.comparatorMaybeNoTypeWithoutID); + copyCommonSetup(r); + return r; } } \ No newline at end of file diff --git a/uimaj-core/src/test/java/org/apache/uima/cas/impl/FsIterator_set_sorted_pearTest.java b/uimaj-core/src/test/java/org/apache/uima/cas/impl/FsIterator_set_sorted_pearTest.java new file mode 100644 index 000000000..646a18717 --- /dev/null +++ b/uimaj-core/src/test/java/org/apache/uima/cas/impl/FsIterator_set_sorted_pearTest.java @@ -0,0 +1,49 @@ +/* + * 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.uima.cas.impl; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.util.Comparator; + +import org.apache.uima.cas.FeatureStructure; +import org.apache.uima.internal.util.CopyOnWriteOrderedFsSet_array; +import org.apache.uima.jcas.cas.TOP; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.Mockito; +import org.mockito.junit.jupiter.MockitoExtension; + +@ExtendWith(MockitoExtension.class) +class FsIterator_set_sorted_pearTest { + + @SuppressWarnings({ "unchecked", "rawtypes" }) + @Test + void thatCopyRetainsPosition() throws Exception { + FsIndex_set_sorted<FeatureStructure> ll_index = Mockito.mock(FsIndex_set_sorted.class); + CopyOnWriteIndexPart cow_wrapper = Mockito.mock(CopyOnWriteOrderedFsSet_array.class); + Comparator<TOP> comparatorMaybeNoTypeWithoutID = Mockito.mock(Comparator.class); + + FsIterator_set_sorted_pear<FeatureStructure> sut = Mockito.spy(new FsIterator_set_sorted_pear<>( + ll_index, cow_wrapper, comparatorMaybeNoTypeWithoutID)); + sut.pos = 1; + FsIterator_set_sorted_pear<FeatureStructure> sutCopy = sut.copy(); + assertThat(sutCopy.pos).isEqualTo(sut.pos); + } +} diff --git a/uimaj-parent/pom.xml b/uimaj-parent/pom.xml index 2269eec0f..0ac2be38a 100644 --- a/uimaj-parent/pom.xml +++ b/uimaj-parent/pom.xml @@ -145,6 +145,7 @@ <commons-csv-version>1.10.0</commons-csv-version> <jackson-version>2.15.2</jackson-version> <junit-version>5.9.3</junit-version> + <mockito-version>4.11.0</mockito-version> <assertj-version>3.24.2</assertj-version> <xmlunit-version>2.9.1</xmlunit-version> <maven.version>3.2.5</maven.version> @@ -166,24 +167,18 @@ <dependencyManagement> <dependencies> <dependency> - <groupId>org.junit.jupiter</groupId> - <artifactId>junit-jupiter-engine</artifactId> - <version>${junit-version}</version> - </dependency> - <dependency> - <groupId>org.junit.jupiter</groupId> - <artifactId>junit-jupiter-migrationsupport</artifactId> - <version>${junit-version}</version> - </dependency> - <dependency> - <groupId>org.junit.jupiter</groupId> - <artifactId>junit-jupiter-params</artifactId> - <version>${junit-version}</version> + <groupId>org.mockito</groupId> + <artifactId>mockito-bom</artifactId> + <version>${mockito-version}</version> + <type>pom</type> + <scope>import</scope> </dependency> <dependency> - <groupId>org.junit.vintage</groupId> - <artifactId>junit-vintage-engine</artifactId> + <groupId>org.junit</groupId> + <artifactId>junit-bom</artifactId> <version>${junit-version}</version> + <type>pom</type> + <scope>import</scope> </dependency> <dependency> <groupId>org.assertj</groupId>