Skip to content

Commit

Permalink
fix checkstyle error
Browse files Browse the repository at this point in the history
  • Loading branch information
anantdamle committed Aug 31, 2023
1 parent 615d561 commit c688b65
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ public final class PairedIterableTest {
private static final int LARGE_LIST_SIZE = 40;

private static final List<String> SMALL_STRINGS_LIST =
unmodifiableList(stringsList(SMALL_LIST_SIZE));
unmodifiableList(stringsList(SMALL_LIST_SIZE));
private static final List<String> LARGE_STRINGS_LIST =
unmodifiableList(stringsList(LARGE_LIST_SIZE));
unmodifiableList(stringsList(LARGE_LIST_SIZE));
private static final List<Integer> SMALL_INTS_LIST = unmodifiableList(intsList(SMALL_LIST_SIZE));
private static final List<Integer> LARGE_INTS_LIST = unmodifiableList(intsList(LARGE_LIST_SIZE));

Expand All @@ -56,7 +56,7 @@ public static final class ParameterizedTests<L, R> {
private final int expectedIterableSize;

public ParameterizedTests(
String testCondition, List<L> leftList, List<R> rightList, int expectedIterableSize) {
String testCondition, List<L> leftList, List<R> rightList, int expectedIterableSize) {
this.leftList = leftList;
this.rightList = rightList;
this.expectedIterableSize = expectedIterableSize;
Expand All @@ -83,49 +83,49 @@ public void testStream() {
PairedIterable<L, R> testIterable = PairedIterable.of(leftList, rightList);

assertEquals(
leftList.subList(0, expectedIterableSize),
testIterable.stream().map(PairedItem::getLeftItem).collect(toList()));
leftList.subList(0, expectedIterableSize),
testIterable.stream().map(PairedItem::getLeftItem).collect(toList()));
assertEquals(
rightList.subList(0, expectedIterableSize),
testIterable.stream().map(PairedItem::getRightItem).collect(toList()));
rightList.subList(0, expectedIterableSize),
testIterable.stream().map(PairedItem::getRightItem).collect(toList()));
}

@Parameters(name = "{0}")
public static Object[][] testingParameters() {
return new Object[][] {
new Object[] {
"left iterable (int) larger than right iterable (string)",
LARGE_INTS_LIST,
SMALL_STRINGS_LIST,
SMALL_LIST_SIZE
},
new Object[] {
"left iterable (string) larger than right iterable (int)",
LARGE_STRINGS_LIST,
SMALL_INTS_LIST,
SMALL_LIST_SIZE
},
new Object[] {
"equal sized left and right (int, string)",
LARGE_INTS_LIST,
LARGE_STRINGS_LIST,
LARGE_LIST_SIZE
},
new Object[] {
"equal sized left and right (string, int)",
SMALL_STRINGS_LIST,
SMALL_INTS_LIST,
SMALL_LIST_SIZE
},
new Object[] {
"Left empty, right small list", Collections.<Integer>emptyList(), LARGE_STRINGS_LIST, 0
},
new Object[] {
"Right empty, left small list", LARGE_STRINGS_LIST, Collections.<Integer>emptyList(), 0
},
new Object[] {
"Right and left both empty lists", Collections.emptyList(), Collections.emptyList(), 0
},
return new Object[][]{
new Object[]{
"left iterable (int) larger than right iterable (string)",
LARGE_INTS_LIST,
SMALL_STRINGS_LIST,
SMALL_LIST_SIZE
},
new Object[]{
"left iterable (string) larger than right iterable (int)",
LARGE_STRINGS_LIST,
SMALL_INTS_LIST,
SMALL_LIST_SIZE
},
new Object[]{
"equal sized left and right (int, string)",
LARGE_INTS_LIST,
LARGE_STRINGS_LIST,
LARGE_LIST_SIZE
},
new Object[]{
"equal sized left and right (string, int)",
SMALL_STRINGS_LIST,
SMALL_INTS_LIST,
SMALL_LIST_SIZE
},
new Object[]{
"Left empty, right small list", Collections.<Integer>emptyList(), LARGE_STRINGS_LIST, 0
},
new Object[]{
"Right empty, left small list", LARGE_STRINGS_LIST, Collections.<Integer>emptyList(), 0
},
new Object[]{
"Right and left both empty lists", Collections.emptyList(), Collections.emptyList(), 0
},
};
}
}
Expand All @@ -146,9 +146,9 @@ public void rightIterableNullThrowsException() {

private static List<String> stringsList(int size) {
return IntStream.range(0, size)
.boxed()
.map(x -> UUID.randomUUID().toString())
.collect(toList());
.boxed()
.map(x -> UUID.randomUUID().toString())
.collect(toList());
}

private static List<Integer> intsList(int size) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.collections4.iterators;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
package org.apache.commons.collections4.iterators;

import org.apache.commons.collections4.IteratorUtils;
import org.apache.commons.collections4.iterators.PairedIterator.PairedItem;
Expand All @@ -30,12 +27,20 @@
import java.util.Random;
import java.util.UUID;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;


/** Unit test suite for {@link PairedIterator}. */
/**
* Unit test suite for {@link PairedIterator}.
*/
public final class PairedIteratorTest
extends AbstractIteratorTest<PairedItem<String, Integer>> {
extends AbstractIteratorTest<PairedItem<String, Integer>> {

public PairedIteratorTest() { super(ObjectArrayIteratorTest.class.getSimpleName()); }
public PairedIteratorTest() {
super(ObjectArrayIteratorTest.class.getSimpleName());
}

private ArrayList<String> smallStringsList;
private ArrayList<String> largeStringsList;
Expand Down Expand Up @@ -85,7 +90,7 @@ public Iterator<PairedItem<String, Integer>> makeObject() {
@Test
public void testLeftIteratorLargerThanRight() {
Iterator<PairedItem<String, Integer>> zipPairIterator =
PairedIterator.ofIterables(largeStringsList, smallIntsList);
PairedIterator.ofIterables(largeStringsList, smallIntsList);


for (int i = 0; i < SMALL_LIST_SIZE; i++) {
Expand All @@ -102,7 +107,7 @@ public void testLeftIteratorLargerThanRight() {
@Test
public void testRightIteratorLargerThanLeft() {
Iterator<PairedItem<String, Integer>> zipPairIterator =
PairedIterator.ofIterables(smallStringsList, largeIntsList);
PairedIterator.ofIterables(smallStringsList, largeIntsList);


for (int i = 0; i < SMALL_LIST_SIZE; i++) {
Expand All @@ -119,32 +124,32 @@ public void testRightIteratorLargerThanLeft() {
@Test
public void testEmptyLeftIterator() {
Iterator<PairedItem<String, Integer>> zipPairIterator =
PairedIterator.of(IteratorUtils.emptyIterator(), largeIntsList.iterator());
PairedIterator.of(IteratorUtils.emptyIterator(), largeIntsList.iterator());

assertFalse(zipPairIterator.hasNext());
}

@Test
public void testEmptyRightIterator() {
Iterator<PairedItem<String, Integer>> zipPairIterator =
PairedIterator.of(largeStringsList.iterator(), IteratorUtils.emptyIterator());
PairedIterator.of(largeStringsList.iterator(), IteratorUtils.emptyIterator());

assertFalse(zipPairIterator.hasNext());
}

@Test
public void testValidTupleString() {
Iterator<PairedItem<String, Integer>> zipPairIterator =
PairedIterator.ofIterables(smallStringsList, largeIntsList);
PairedIterator.ofIterables(smallStringsList, largeIntsList);


for (int i = 0; i < SMALL_LIST_SIZE; i++) {
assertTrue(zipPairIterator.hasNext());
PairedItem<String, Integer> zippedItem = zipPairIterator.next();

assertEquals(
String.format("{%s, %s}", zippedItem.getLeftItem(), zippedItem.getRightItem()),
zippedItem.toString());
String.format("{%s, %s}", zippedItem.getLeftItem(), zippedItem.getRightItem()),
zippedItem.toString());
}

assertFalse(zipPairIterator.hasNext());
Expand Down

0 comments on commit c688b65

Please sign in to comment.