From f9564e053da8e524693c8b4ae9fb8020a3668e65 Mon Sep 17 00:00:00 2001 From: Ahmed Ashour Date: Fri, 24 May 2019 10:45:09 +0200 Subject: [PATCH] java: test: use assertNotNull and assertFalse --- .../calib3d/misc/java/test/Calib3dTest.java | 6 ++-- modules/core/misc/java/test/MatTest.java | 4 +-- .../core/misc/java/test/RotatedRectTest.java | 28 +++++++++---------- .../misc/java/test/ImgcodecsTest.java | 4 +-- .../src/org/opencv/test/OpenCVTestCase.java | 2 +- .../src/org/opencv/test/OpenCVTestRunner.java | 2 +- .../org/opencv/test/android/UtilsTest.java | 6 ++-- .../src/org/opencv/test/OpenCVTestCase.java | 2 +- .../misc/java/test/CascadeClassifierTest.java | 6 ++-- 9 files changed, 30 insertions(+), 30 deletions(-) diff --git a/modules/calib3d/misc/java/test/Calib3dTest.java b/modules/calib3d/misc/java/test/Calib3dTest.java index 99153dfb21..3929e29f01 100644 --- a/modules/calib3d/misc/java/test/Calib3dTest.java +++ b/modules/calib3d/misc/java/test/Calib3dTest.java @@ -177,7 +177,7 @@ public class Calib3dTest extends OpenCVTestCase { Size patternSize = new Size(9, 6); MatOfPoint2f corners = new MatOfPoint2f(); Calib3d.findChessboardCorners(grayChess, patternSize, corners); - assertTrue(!corners.empty()); + assertFalse(corners.empty()); } public void testFindChessboardCornersMatSizeMatInt() { @@ -185,7 +185,7 @@ public class Calib3dTest extends OpenCVTestCase { MatOfPoint2f corners = new MatOfPoint2f(); Calib3d.findChessboardCorners(grayChess, patternSize, corners, Calib3d.CALIB_CB_ADAPTIVE_THRESH + Calib3d.CALIB_CB_NORMALIZE_IMAGE + Calib3d.CALIB_CB_FAST_CHECK); - assertTrue(!corners.empty()); + assertFalse(corners.empty()); } public void testFind4QuadCornerSubpix() { @@ -194,7 +194,7 @@ public class Calib3dTest extends OpenCVTestCase { Size region_size = new Size(5, 5); Calib3d.findChessboardCorners(grayChess, patternSize, corners); Calib3d.find4QuadCornerSubpix(grayChess, corners, region_size); - assertTrue(!corners.empty()); + assertFalse(corners.empty()); } public void testFindCirclesGridMatSizeMat() { diff --git a/modules/core/misc/java/test/MatTest.java b/modules/core/misc/java/test/MatTest.java index 4c8c52b09c..cdd7950843 100644 --- a/modules/core/misc/java/test/MatTest.java +++ b/modules/core/misc/java/test/MatTest.java @@ -266,7 +266,7 @@ public class MatTest extends OpenCVTestCase { public void testEmpty() { assertTrue(dst.empty()); - assertTrue(!gray0.empty()); + assertFalse(gray0.empty()); } public void testEyeIntIntInt() { @@ -1194,7 +1194,7 @@ public class MatTest extends OpenCVTestCase { } public void testToString() { - assertTrue(null != gray0.toString()); + assertNotNull(gray0.toString()); } public void testTotal() { diff --git a/modules/core/misc/java/test/RotatedRectTest.java b/modules/core/misc/java/test/RotatedRectTest.java index b1b4a677d3..76966ff4ae 100644 --- a/modules/core/misc/java/test/RotatedRectTest.java +++ b/modules/core/misc/java/test/RotatedRectTest.java @@ -48,7 +48,7 @@ public class RotatedRectTest extends OpenCVTestCase { RotatedRect rrect = new RotatedRect(center, size, angle); RotatedRect clone = rrect.clone(); - assertTrue(clone != null); + assertNotNull(clone); assertTrue(rrect.center.equals(clone.center)); assertTrue(rrect.size.equals(clone.size)); assertTrue(rrect.angle == clone.angle); @@ -66,24 +66,24 @@ public class RotatedRectTest extends OpenCVTestCase { RotatedRect clone2 = rrect2.clone(); assertTrue(rrect1.equals(rrect3)); - assertTrue(!rrect1.equals(rrect2)); + assertFalse(rrect1.equals(rrect2)); assertTrue(rrect2.equals(clone2)); clone2.angle = 10; - assertTrue(!rrect2.equals(clone2)); + assertFalse(rrect2.equals(clone2)); assertTrue(rrect1.equals(clone1)); clone1.center.x += 1; - assertTrue(!rrect1.equals(clone1)); + assertFalse(rrect1.equals(clone1)); clone1.center.x -= 1; assertTrue(rrect1.equals(clone1)); clone1.size.width += 1; - assertTrue(!rrect1.equals(clone1)); + assertFalse(rrect1.equals(clone1)); - assertTrue(!rrect1.equals(size)); + assertFalse(rrect1.equals(size)); } public void testHashCode() { @@ -140,10 +140,10 @@ public class RotatedRectTest extends OpenCVTestCase { public void testRotatedRect() { RotatedRect rr = new RotatedRect(); - assertTrue(rr != null); - assertTrue(rr.center != null); - assertTrue(rr.size != null); - assertTrue(rr.angle == 0.0); + assertNotNull(rr); + assertNotNull(rr.center); + assertNotNull(rr.size); + assertEquals(0.0, rr.angle); } public void testRotatedRectDoubleArray() { @@ -161,10 +161,10 @@ public class RotatedRectTest extends OpenCVTestCase { public void testRotatedRectPointSizeDouble() { RotatedRect rr = new RotatedRect(center, size, 40); - assertTrue(rr != null); - assertTrue(rr.center != null); - assertTrue(rr.size != null); - assertTrue(rr.angle == 40.0); + assertNotNull(rr); + assertNotNull(rr.center); + assertNotNull(rr.size); + assertEquals(40.0, rr.angle); } public void testSet() { diff --git a/modules/imgcodecs/misc/java/test/ImgcodecsTest.java b/modules/imgcodecs/misc/java/test/ImgcodecsTest.java index 50ef147b22..8fe15d2536 100644 --- a/modules/imgcodecs/misc/java/test/ImgcodecsTest.java +++ b/modules/imgcodecs/misc/java/test/ImgcodecsTest.java @@ -38,7 +38,7 @@ public class ImgcodecsTest extends OpenCVTestCase { public void testImreadString() { dst = Imgcodecs.imread(OpenCVTestRunner.LENA_PATH); - assertTrue(!dst.empty()); + assertFalse(dst.empty()); assertEquals(3, dst.channels()); assertTrue(512 == dst.cols()); assertTrue(512 == dst.rows()); @@ -46,7 +46,7 @@ public class ImgcodecsTest extends OpenCVTestCase { public void testImreadStringInt() { dst = Imgcodecs.imread(OpenCVTestRunner.LENA_PATH, 0); - assertTrue(!dst.empty()); + assertFalse(dst.empty()); assertEquals(1, dst.channels()); assertTrue(512 == dst.cols()); assertTrue(512 == dst.rows()); diff --git a/modules/java/test/android_test/src/org/opencv/test/OpenCVTestCase.java b/modules/java/test/android_test/src/org/opencv/test/OpenCVTestCase.java index cc7eb9dca7..e9f6d43f31 100644 --- a/modules/java/test/android_test/src/org/opencv/test/OpenCVTestCase.java +++ b/modules/java/test/android_test/src/org/opencv/test/OpenCVTestCase.java @@ -581,7 +581,7 @@ public class OpenCVTestCase extends TestCase { message = TAG + " :: " + "could not instantiate " + cname + "! Exception: " + ex.getMessage(); } - assertTrue(message, instance!=null); + assertNotNull(message, instance); return instance; } diff --git a/modules/java/test/android_test/src/org/opencv/test/OpenCVTestRunner.java b/modules/java/test/android_test/src/org/opencv/test/OpenCVTestRunner.java index d5c1ecd206..c924cabe3f 100644 --- a/modules/java/test/android_test/src/org/opencv/test/OpenCVTestRunner.java +++ b/modules/java/test/android_test/src/org/opencv/test/OpenCVTestRunner.java @@ -96,7 +96,7 @@ public class OpenCVTestRunner extends InstrumentationTestRunner { } context = getContext(); - Assert.assertTrue("Context can't be 'null'", context != null); + Assert.assertNotNull("Context can't be 'null'", context); LENA_PATH = Utils.exportResource(context, R.drawable.lena); CHESS_PATH = Utils.exportResource(context, R.drawable.chessboard); LBPCASCADE_FRONTALFACE_PATH = Utils.exportResource(context, R.raw.lbpcascade_frontalface); diff --git a/modules/java/test/android_test/src/org/opencv/test/android/UtilsTest.java b/modules/java/test/android_test/src/org/opencv/test/android/UtilsTest.java index 5494513158..6e6acf8193 100644 --- a/modules/java/test/android_test/src/org/opencv/test/android/UtilsTest.java +++ b/modules/java/test/android_test/src/org/opencv/test/android/UtilsTest.java @@ -74,7 +74,7 @@ public class UtilsTest extends OpenCVTestCase { // RGBA Mat imgRGBA = new Mat(); Imgproc.cvtColor(imgBGR, imgRGBA, Imgproc.COLOR_BGR2RGBA); - assertTrue(!imgRGBA.empty() && imgRGBA.channels() == 4); + assertFalse(imgRGBA.empty() && imgRGBA.channels() == 4); bmp16.eraseColor(Color.BLACK); m16.setTo(s0); Utils.matToBitmap(imgRGBA, bmp16); Utils.bitmapToMat(bmp16, m16); @@ -92,7 +92,7 @@ public class UtilsTest extends OpenCVTestCase { // RGB Mat imgRGB = new Mat(); Imgproc.cvtColor(imgBGR, imgRGB, Imgproc.COLOR_BGR2RGB); - assertTrue(!imgRGB.empty() && imgRGB.channels() == 3); + assertFalse(imgRGB.empty() && imgRGB.channels() == 3); bmp16.eraseColor(Color.BLACK); m16.setTo(s0); Utils.matToBitmap(imgRGB, bmp16); Utils.bitmapToMat(bmp16, m16); @@ -110,7 +110,7 @@ public class UtilsTest extends OpenCVTestCase { // Gray Mat imgGray = new Mat(); Imgproc.cvtColor(imgBGR, imgGray, Imgproc.COLOR_BGR2GRAY); - assertTrue(!imgGray.empty() && imgGray.channels() == 1); + assertFalse(imgGray.empty() && imgGray.channels() == 1); Mat tmp = new Mat(); bmp16.eraseColor(Color.BLACK); m16.setTo(s0); diff --git a/modules/java/test/pure_test/src/org/opencv/test/OpenCVTestCase.java b/modules/java/test/pure_test/src/org/opencv/test/OpenCVTestCase.java index 7dc3432add..ccc96ffd2b 100644 --- a/modules/java/test/pure_test/src/org/opencv/test/OpenCVTestCase.java +++ b/modules/java/test/pure_test/src/org/opencv/test/OpenCVTestCase.java @@ -607,7 +607,7 @@ public class OpenCVTestCase extends TestCase { message = TAG + " :: " + "could not instantiate " + cname + "! Exception: " + ex.getMessage(); } - assertTrue(message, instance!=null); + assertNotNull(message, instance); return instance; } diff --git a/modules/objdetect/misc/java/test/CascadeClassifierTest.java b/modules/objdetect/misc/java/test/CascadeClassifierTest.java index 5304fac21e..de7b095414 100644 --- a/modules/objdetect/misc/java/test/CascadeClassifierTest.java +++ b/modules/objdetect/misc/java/test/CascadeClassifierTest.java @@ -22,12 +22,12 @@ public class CascadeClassifierTest extends OpenCVTestCase { public void testCascadeClassifier() { cc = new CascadeClassifier(); - assertTrue(null != cc); + assertNotNull(cc); } public void testCascadeClassifierString() { cc = new CascadeClassifier(OpenCVTestRunner.LBPCASCADE_FRONTALFACE_PATH); - assertTrue(null != cc); + assertNotNull(cc); } public void testDetectMultiScaleMatListOfRect() { @@ -98,7 +98,7 @@ public class CascadeClassifierTest extends OpenCVTestCase { public void testLoad() { cc = new CascadeClassifier(); cc.load(OpenCVTestRunner.LBPCASCADE_FRONTALFACE_PATH); - assertTrue(!cc.empty()); + assertFalse(cc.empty()); } }