From b3a7da18820b156ae03ee91c6eb3ad638a60709a Mon Sep 17 00:00:00 2001 From: emopers Date: Wed, 17 Jul 2019 10:29:52 -0300 Subject: [PATCH 1/2] Fixing hasNext violation in a public class. --- src/test/java/net/imglib2/img/array/ArrayImgsTest.java | 4 ++++ src/test/java/net/imglib2/img/cell/CopyTest.java | 5 +++++ .../imglib2/view/RandomAccessibleIntervalCursorTest.java | 8 ++++++++ 3 files changed, 17 insertions(+) diff --git a/src/test/java/net/imglib2/img/array/ArrayImgsTest.java b/src/test/java/net/imglib2/img/array/ArrayImgsTest.java index b87bd00b79..99aeafffbf 100644 --- a/src/test/java/net/imglib2/img/array/ArrayImgsTest.java +++ b/src/test/java/net/imglib2/img/array/ArrayImgsTest.java @@ -479,6 +479,10 @@ public static < T extends NativeType< T > & IntegerType< T > > void testRange( f final ArrayCursor< T > r = ref.cursor(); for ( int s = start; s < stop; ++s ) { + if ( !c.hasNext() || !r.hasNext() ) + { + Assert.fail( "Invalid iterators for test range" ); + } Assert.assertEquals( c.next().getInteger(), s ); Assert.assertEquals( r.next().getInteger(), s ); } diff --git a/src/test/java/net/imglib2/img/cell/CopyTest.java b/src/test/java/net/imglib2/img/cell/CopyTest.java index ff5509c686..c2874253db 100644 --- a/src/test/java/net/imglib2/img/cell/CopyTest.java +++ b/src/test/java/net/imglib2/img/cell/CopyTest.java @@ -36,6 +36,7 @@ import static org.junit.Assert.assertArrayEquals; +import java.util.NoSuchElementException; import java.util.Random; import org.junit.Before; @@ -130,6 +131,10 @@ public void copyWithIterationBoth( final Img< IntType > srcImg, final Img< IntTy final Cursor< IntType > dst = dstImg.cursor(); while ( src.hasNext() ) { + if ( !dst.hasNext() ) + { + throw new NoSuchElementException("Cursor does not have next element"); + } dst.next().set( src.next().get() ); } } diff --git a/src/test/java/net/imglib2/view/RandomAccessibleIntervalCursorTest.java b/src/test/java/net/imglib2/view/RandomAccessibleIntervalCursorTest.java index d4707cb2d4..b897d4179a 100644 --- a/src/test/java/net/imglib2/view/RandomAccessibleIntervalCursorTest.java +++ b/src/test/java/net/imglib2/view/RandomAccessibleIntervalCursorTest.java @@ -37,6 +37,7 @@ import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; +import java.util.NoSuchElementException; import java.util.Random; import org.junit.Before; @@ -103,7 +104,14 @@ public void setUp() public void copy( final Cursor< IntType > src, final Cursor< IntType > dst ) { while ( src.hasNext() ) + { + if ( !dst.hasNext() ) + { + throw new NoSuchElementException("Cursor dst does not have next element"); + } + dst.next().set( src.next().get() ); + } } int[] getImgAsInts( final Img< IntType > img ) From c485c35578bbf27f394b22f13166d0a1723ae084 Mon Sep 17 00:00:00 2001 From: emopers Date: Wed, 17 Jul 2019 10:46:34 -0300 Subject: [PATCH 2/2] fix spacing --- src/test/java/net/imglib2/img/cell/CopyTest.java | 2 +- .../net/imglib2/view/RandomAccessibleIntervalCursorTest.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/java/net/imglib2/img/cell/CopyTest.java b/src/test/java/net/imglib2/img/cell/CopyTest.java index c2874253db..63d769f33a 100644 --- a/src/test/java/net/imglib2/img/cell/CopyTest.java +++ b/src/test/java/net/imglib2/img/cell/CopyTest.java @@ -133,7 +133,7 @@ public void copyWithIterationBoth( final Img< IntType > srcImg, final Img< IntTy { if ( !dst.hasNext() ) { - throw new NoSuchElementException("Cursor does not have next element"); + throw new NoSuchElementException(" Cursor dst does not have next element" ); } dst.next().set( src.next().get() ); } diff --git a/src/test/java/net/imglib2/view/RandomAccessibleIntervalCursorTest.java b/src/test/java/net/imglib2/view/RandomAccessibleIntervalCursorTest.java index b897d4179a..3ffaaf6f75 100644 --- a/src/test/java/net/imglib2/view/RandomAccessibleIntervalCursorTest.java +++ b/src/test/java/net/imglib2/view/RandomAccessibleIntervalCursorTest.java @@ -107,7 +107,7 @@ public void copy( final Cursor< IntType > src, final Cursor< IntType > dst ) { if ( !dst.hasNext() ) { - throw new NoSuchElementException("Cursor dst does not have next element"); + throw new NoSuchElementException( "Cursor dst does not have next element" ); } dst.next().set( src.next().get() );