From 7b1df5c438b7d9c774c906b0f2ba8e7f0ddbf1f8 Mon Sep 17 00:00:00 2001 From: dan-s1 Date: Mon, 13 Jan 2025 16:14:57 +0000 Subject: [PATCH] NIFI-14153 Applied PMD's SimplifiableTestAssertion across the code base and fixed the violations. --- .../expression/language/TestQuery.java | 5 +- .../apache/nifi/hl7/query/TestHL7Query.java | 3 +- .../serialization/record/TestMapRecord.java | 7 +-- .../schema/TestSchemaRecordReader.java | 6 +-- .../schema/TestSchemaRecordReaderWriter.java | 8 ++-- .../stream/io/util/StreamDemarcatorTest.java | 48 +++++++++---------- .../classloader/TestClassLoaderUtils.java | 11 ++--- .../processors/aws/dynamodb/ItemKeysTest.java | 4 +- .../evtx/XmlBxmlNodeVisitorTest.java | 4 +- .../evtx/parser/ChunkHeaderTest.java | 3 +- .../processors/evtx/parser/RecordTest.java | 4 +- .../evtx/parser/bxml/AttributeNodeTest.java | 6 +-- .../parser/bxml/OpenStartElementNodeTest.java | 3 +- .../evtx/parser/bxml/RootNodeTest.java | 4 +- .../evtx/parser/bxml/ValueNodeTest.java | 4 +- .../parser/bxml/value/BXmlTypeNodeTest.java | 4 +- .../apache/nifi/util/db/TestJdbcCommon.java | 7 +-- .../util/pattern/TestExceptionHandler.java | 4 +- .../apache/nifi/avro/TestAvroTypeUtil.java | 40 ++++++++-------- .../access/InferenceSchemaStrategyTest.java | 4 +- .../ExternalHazelcastCacheManagerTest.java | 4 +- .../processors/JMSPublisherConsumerIT.java | 7 +-- .../nifi/jms/processors/PublishJMSIT.java | 31 ++++++------ .../api/processor/TestProcessorResource.java | 3 +- .../api/processor/TestProcessorWebUtils.java | 4 +- .../processors/PublishKafkaValueRecordIT.java | 4 +- .../additional/PublishKafkaContentX1IT.java | 3 +- .../additional/PublishKafkaWrapperX1IT.java | 3 +- .../additional/PublishKafkaWrapperX2IT.java | 3 +- .../additional/PublishKafkaWrapperX3IT.java | 3 +- .../additional/PublishKafkaWrapperX4IT.java | 3 +- .../additional/PublishKafkaWrapperX5IT.java | 3 +- .../nifi/processors/mongodb/GetMongoIT.java | 3 +- .../mongodb/RunMongoAggregationIT.java | 2 +- .../nifi/mongodb/MongoDBLookupServiceIT.java | 8 ++-- .../standard/TestExecuteSQLRecord.java | 8 ++-- .../processors/standard/TestFetchFile.java | 10 ++-- .../processors/standard/TestFlattenJson.java | 3 +- .../standard/TestGenerateRecord.java | 10 ++-- .../nifi/processors/standard/TestNotify.java | 3 +- .../processors/standard/TestReplaceText.java | 2 +- .../processors/standard/TestSplitRecord.java | 3 +- .../TestInsertRecordFieldsJoinStrategy.java | 3 +- .../dbcp/TestDBCPConnectionPoolLookup.java | 6 +-- .../sink/db/DatabaseRecordSinkTest.java | 9 ++-- .../apache/nifi/avro/TestWriteAvroResult.java | 8 ++-- .../org/apache/nifi/cef/TestCEFReader.java | 15 +++--- .../json/TestJsonPathRowRecordReader.java | 14 +++--- .../TestWindowsEventLogRecordReader.java | 32 ++++++------- .../apache/nifi/xml/TestInferXmlSchema.java | 4 +- .../yaml/TestYamlTreeRowRecordReader.java | 21 ++++---- .../authorization/AuthorizerFactoryTest.java | 8 ++-- .../StandardManagedAuthorizerTest.java | 5 +- .../jaxb/message/TestJaxbProtocolUtils.java | 13 ++--- .../node/TestNodeClusterCoordinator.java | 19 ++++---- ...ardControllerServiceInvocationHandler.java | 5 +- .../nifi/nar/LoadNativeLibAspectTest.java | 3 +- .../http/TestHttpFlowFileServerProtocol.java | 3 +- .../StandardAuthorizableLookupTest.java | 24 +++++----- .../web/api/TestDataTransferResource.java | 4 +- .../apache/nifi/web/api/TestFlowResource.java | 11 +++-- .../TestFlowContentSerializer.java | 2 +- .../registry/service/TestRegistryService.java | 2 +- .../nifi/registry/web/api/BucketsIT.java | 3 +- .../web/api/SecureNiFiRegistryClientIT.java | 12 ++--- .../basics/RollbackOnExceptionIT.java | 6 +-- pmd-ruleset.xml | 1 + 67 files changed, 284 insertions(+), 251 deletions(-) diff --git a/nifi-commons/nifi-expression-language/src/test/java/org/apache/nifi/attribute/expression/language/TestQuery.java b/nifi-commons/nifi-expression-language/src/test/java/org/apache/nifi/attribute/expression/language/TestQuery.java index 07115dab63ec..bf999e0d7525 100644 --- a/nifi-commons/nifi-expression-language/src/test/java/org/apache/nifi/attribute/expression/language/TestQuery.java +++ b/nifi-commons/nifi-expression-language/src/test/java/org/apache/nifi/attribute/expression/language/TestQuery.java @@ -58,6 +58,7 @@ import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; import static org.junit.jupiter.api.Assertions.assertNotEquals; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -2560,14 +2561,14 @@ private void verifyEquals(final String expression, final Map att if (expectedResult instanceof Long) { if (ResultType.NUMBER.equals(result.getResultType())) { final Number resultNumber = ((NumberQueryResult) result).getValue(); - assertTrue(resultNumber instanceof Long); + assertInstanceOf(Long.class, resultNumber); } else { assertEquals(ResultType.WHOLE_NUMBER, result.getResultType()); } } else if (expectedResult instanceof Double) { if (ResultType.NUMBER.equals(result.getResultType())) { final Number resultNumber = ((NumberQueryResult) result).getValue(); - assertTrue(resultNumber instanceof Double); + assertInstanceOf(Double.class, resultNumber); } else { assertEquals(ResultType.DECIMAL, result.getResultType()); } diff --git a/nifi-commons/nifi-hl7-query-language/src/test/java/org/apache/nifi/hl7/query/TestHL7Query.java b/nifi-commons/nifi-hl7-query-language/src/test/java/org/apache/nifi/hl7/query/TestHL7Query.java index ce944e6b9f4a..6cccbdb45b40 100644 --- a/nifi-commons/nifi-hl7-query-language/src/test/java/org/apache/nifi/hl7/query/TestHL7Query.java +++ b/nifi-commons/nifi-hl7-query-language/src/test/java/org/apache/nifi/hl7/query/TestHL7Query.java @@ -35,6 +35,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; import static org.junit.jupiter.api.Assertions.assertTrue; @SuppressWarnings("resource") @@ -136,7 +137,7 @@ public void testSelectField() { assertEquals(1, result.getHitCount()); final Object names = result.nextHit().getValue("PID.5"); - assertTrue(names instanceof List); + assertInstanceOf(List.class, names); final List nameList = (List) names; assertEquals(1, nameList.size()); final HL7Field nameField = (HL7Field) nameList.get(0); diff --git a/nifi-commons/nifi-record/src/test/java/org/apache/nifi/serialization/record/TestMapRecord.java b/nifi-commons/nifi-record/src/test/java/org/apache/nifi/serialization/record/TestMapRecord.java index 02f0a3100d2b..928e1c996527 100644 --- a/nifi-commons/nifi-record/src/test/java/org/apache/nifi/serialization/record/TestMapRecord.java +++ b/nifi-commons/nifi-record/src/test/java/org/apache/nifi/serialization/record/TestMapRecord.java @@ -42,6 +42,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertSame; import static org.junit.jupiter.api.Assertions.assertThrows; @@ -315,17 +316,17 @@ void testNestedSchema() { Map fullConversion = ((MapRecord) record).toMap(true); assertEquals(FOO_TEST_VAL, fullConversion.get("foo")); - assertTrue(fullConversion.get("nested") instanceof Map); + assertInstanceOf(Map.class, fullConversion.get("nested")); Map nested = (Map) fullConversion.get("nested"); assertEquals(1, nested.size()); assertEquals(NESTED_RECORD_VALUE, nested.get("test")); - assertTrue(fullConversion.get("list") instanceof List); + assertInstanceOf(List.class, fullConversion.get("list")); List recordList = (List) fullConversion.get("list"); assertEquals(5, recordList.size()); for (Object rec : recordList) { - assertTrue(rec instanceof Map); + assertInstanceOf(Map.class, rec); Map map = (Map) rec; assertEquals(1, map.size()); assertEquals(NESTED_RECORD_VALUE, map.get("test")); diff --git a/nifi-commons/nifi-schema-utils/src/test/java/org/apache/nifi/repository/schema/TestSchemaRecordReader.java b/nifi-commons/nifi-schema-utils/src/test/java/org/apache/nifi/repository/schema/TestSchemaRecordReader.java index 497e5c984316..d51dc4fd5344 100644 --- a/nifi-commons/nifi-schema-utils/src/test/java/org/apache/nifi/repository/schema/TestSchemaRecordReader.java +++ b/nifi-commons/nifi-schema-utils/src/test/java/org/apache/nifi/repository/schema/TestSchemaRecordReader.java @@ -25,11 +25,11 @@ import java.io.IOException; import java.nio.charset.StandardCharsets; import java.util.ArrayList; -import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotNull; @@ -109,7 +109,7 @@ public void testReadExactlyOnceFields() throws IOException { assertEquals(42, record.getFieldValue("int")); assertTrue((boolean) record.getFieldValue("boolean")); - assertTrue(Arrays.equals("hello".getBytes(), (byte[]) record.getFieldValue("byte array"))); + assertArrayEquals("hello".getBytes(), (byte[]) record.getFieldValue("byte array")); assertEquals(42L, record.getFieldValue("long")); assertEquals("hello", record.getFieldValue("string")); assertEquals("hello", record.getFieldValue("long string")); @@ -251,7 +251,7 @@ public void testReadZeroOrOneFields() throws IOException { assertEquals(42, valueMap.get("int present")); assertTrue((boolean) valueMap.get("boolean present")); - assertTrue(Arrays.equals("hello".getBytes(), (byte[]) valueMap.get("byte array present"))); + assertArrayEquals("hello".getBytes(), (byte[]) valueMap.get("byte array present")); assertEquals(42L, valueMap.get("long present")); assertEquals("hello", valueMap.get("string present")); assertEquals("hello", valueMap.get("long string present")); diff --git a/nifi-commons/nifi-schema-utils/src/test/java/org/apache/nifi/repository/schema/TestSchemaRecordReaderWriter.java b/nifi-commons/nifi-schema-utils/src/test/java/org/apache/nifi/repository/schema/TestSchemaRecordReaderWriter.java index 52b7461a20e9..92ab6034ac2c 100644 --- a/nifi-commons/nifi-schema-utils/src/test/java/org/apache/nifi/repository/schema/TestSchemaRecordReaderWriter.java +++ b/nifi-commons/nifi-schema-utils/src/test/java/org/apache/nifi/repository/schema/TestSchemaRecordReaderWriter.java @@ -26,13 +26,13 @@ import java.io.InputStream; import java.nio.charset.StandardCharsets; import java.util.ArrayList; -import java.util.Arrays; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import static org.apache.nifi.repository.schema.SchemaRecordWriter.MAX_ALLOWED_UTF_LENGTH; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; @@ -152,7 +152,7 @@ public void testRoundTrip() throws IOException { assertEquals(42, record.getFieldValue("int")); assertEquals(42, record.getFieldValue("int present")); assertEquals(true, record.getFieldValue("boolean present")); - assertTrue(Arrays.equals("Hello".getBytes(), (byte[]) record.getFieldValue("byte array present"))); + assertArrayEquals("Hello".getBytes(), (byte[]) record.getFieldValue("byte array present")); assertEquals(42L, record.getFieldValue("long present")); assertEquals("Hello", record.getFieldValue("string present")); assertEquals("Long Hello", record.getFieldValue("long string present")); @@ -197,8 +197,8 @@ public void testUTFLargerThan64k() throws IOException { values.put(createField("int present", FieldType.INT), 42); final String utfString = utfStringOneByte + utfStringTwoByte + utfStringThreeByte; // 3 chars and 6 utf8 bytes final String seventyK = StringUtils.repeat(utfString, 21845); // 65,535 chars and 131070 utf8 bytes - assertTrue(seventyK.length() == 65535); - assertTrue(seventyK.getBytes(StandardCharsets.UTF_8).length == 131070); + assertEquals(65535, seventyK.length()); + assertEquals(131070, seventyK.getBytes(StandardCharsets.UTF_8).length); values.put(createField("string present", FieldType.STRING), seventyK); final FieldMapRecord originalRecord = new FieldMapRecord(values, schema); diff --git a/nifi-commons/nifi-utils/src/test/java/org/apache/nifi/stream/io/util/StreamDemarcatorTest.java b/nifi-commons/nifi-utils/src/test/java/org/apache/nifi/stream/io/util/StreamDemarcatorTest.java index 1397fda01a6d..d9f1805943cf 100644 --- a/nifi-commons/nifi-utils/src/test/java/org/apache/nifi/stream/io/util/StreamDemarcatorTest.java +++ b/nifi-commons/nifi-utils/src/test/java/org/apache/nifi/stream/io/util/StreamDemarcatorTest.java @@ -22,14 +22,12 @@ import java.io.IOException; import java.io.InputStream; import java.nio.charset.StandardCharsets; -import java.util.Arrays; import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Mockito.mock; @@ -86,7 +84,7 @@ public void validateNoDelimiter() throws IOException { String data = "Learn from yesterday, live for today, hope for tomorrow. The important thing is not to stop questioning."; ByteArrayInputStream is = new ByteArrayInputStream(data.getBytes(StandardCharsets.UTF_8)); StreamDemarcator scanner = new StreamDemarcator(is, null, 1000); - assertTrue(Arrays.equals(data.getBytes(StandardCharsets.UTF_8), scanner.nextToken())); + assertArrayEquals(data.getBytes(StandardCharsets.UTF_8), scanner.nextToken()); // validate that subsequent invocations of nextToken() do not result in exception assertNull(scanner.nextToken()); assertNull(scanner.nextToken()); @@ -97,7 +95,7 @@ public void validateNoDelimiterSmallInitialBuffer() throws IOException { String data = "Learn from yesterday, live for today, hope for tomorrow. The important thing is not to stop questioning."; ByteArrayInputStream is = new ByteArrayInputStream(data.getBytes(StandardCharsets.UTF_8)); StreamDemarcator scanner = new StreamDemarcator(is, null, 1000, 1); - assertTrue(Arrays.equals(data.getBytes(StandardCharsets.UTF_8), scanner.nextToken())); + assertArrayEquals(data.getBytes(StandardCharsets.UTF_8), scanner.nextToken()); } @Test @@ -105,9 +103,9 @@ public void validateSingleByteDelimiter() throws IOException { String data = "Learn from yesterday, live for today, hope for tomorrow. The important thing is not to stop questioning."; ByteArrayInputStream is = new ByteArrayInputStream(data.getBytes(StandardCharsets.UTF_8)); StreamDemarcator scanner = new StreamDemarcator(is, ",".getBytes(StandardCharsets.UTF_8), 1000); - assertTrue(Arrays.equals("Learn from yesterday".getBytes(StandardCharsets.UTF_8), scanner.nextToken())); - assertTrue(Arrays.equals(" live for today".getBytes(StandardCharsets.UTF_8), scanner.nextToken())); - assertTrue(Arrays.equals(" hope for tomorrow. The important thing is not to stop questioning.".getBytes(StandardCharsets.UTF_8), scanner.nextToken())); + assertArrayEquals("Learn from yesterday".getBytes(StandardCharsets.UTF_8), scanner.nextToken()); + assertArrayEquals(" live for today".getBytes(StandardCharsets.UTF_8), scanner.nextToken()); + assertArrayEquals(" hope for tomorrow. The important thing is not to stop questioning.".getBytes(StandardCharsets.UTF_8), scanner.nextToken()); assertNull(scanner.nextToken()); } @@ -116,9 +114,9 @@ public void validateDelimiterAtTheBeginning() throws IOException { String data = ",Learn from yesterday, live for today, hope for tomorrow. The important thing is not to stop questioning."; ByteArrayInputStream is = new ByteArrayInputStream(data.getBytes(StandardCharsets.UTF_8)); StreamDemarcator scanner = new StreamDemarcator(is, ",".getBytes(StandardCharsets.UTF_8), 1000); - assertTrue(Arrays.equals("Learn from yesterday".getBytes(StandardCharsets.UTF_8), scanner.nextToken())); - assertTrue(Arrays.equals(" live for today".getBytes(StandardCharsets.UTF_8), scanner.nextToken())); - assertTrue(Arrays.equals(" hope for tomorrow. The important thing is not to stop questioning.".getBytes(StandardCharsets.UTF_8), scanner.nextToken())); + assertArrayEquals("Learn from yesterday".getBytes(StandardCharsets.UTF_8), scanner.nextToken()); + assertArrayEquals(" live for today".getBytes(StandardCharsets.UTF_8), scanner.nextToken()); + assertArrayEquals(" hope for tomorrow. The important thing is not to stop questioning.".getBytes(StandardCharsets.UTF_8), scanner.nextToken()); assertNull(scanner.nextToken()); } @@ -127,9 +125,9 @@ public void validateEmptyDelimiterSegments() throws IOException { String data = ",,,,,Learn from yesterday, live for today, hope for tomorrow. The important thing is not to stop questioning."; ByteArrayInputStream is = new ByteArrayInputStream(data.getBytes(StandardCharsets.UTF_8)); StreamDemarcator scanner = new StreamDemarcator(is, ",".getBytes(StandardCharsets.UTF_8), 1000); - assertTrue(Arrays.equals("Learn from yesterday".getBytes(StandardCharsets.UTF_8), scanner.nextToken())); - assertTrue(Arrays.equals(" live for today".getBytes(StandardCharsets.UTF_8), scanner.nextToken())); - assertTrue(Arrays.equals(" hope for tomorrow. The important thing is not to stop questioning.".getBytes(StandardCharsets.UTF_8), scanner.nextToken())); + assertArrayEquals("Learn from yesterday".getBytes(StandardCharsets.UTF_8), scanner.nextToken()); + assertArrayEquals(" live for today".getBytes(StandardCharsets.UTF_8), scanner.nextToken()); + assertArrayEquals(" hope for tomorrow. The important thing is not to stop questioning.".getBytes(StandardCharsets.UTF_8), scanner.nextToken()); assertNull(scanner.nextToken()); } @@ -138,9 +136,9 @@ public void validateSingleByteDelimiterSmallInitialBuffer() throws IOException { String data = "Learn from yesterday, live for today, hope for tomorrow. The important thing is not to stop questioning."; ByteArrayInputStream is = new ByteArrayInputStream(data.getBytes(StandardCharsets.UTF_8)); StreamDemarcator scanner = new StreamDemarcator(is, ",".getBytes(StandardCharsets.UTF_8), 1000, 2); - assertTrue(Arrays.equals("Learn from yesterday".getBytes(StandardCharsets.UTF_8), scanner.nextToken())); - assertTrue(Arrays.equals(" live for today".getBytes(StandardCharsets.UTF_8), scanner.nextToken())); - assertTrue(Arrays.equals(" hope for tomorrow. The important thing is not to stop questioning.".getBytes(StandardCharsets.UTF_8), scanner.nextToken())); + assertArrayEquals("Learn from yesterday".getBytes(StandardCharsets.UTF_8), scanner.nextToken()); + assertArrayEquals(" live for today".getBytes(StandardCharsets.UTF_8), scanner.nextToken()); + assertArrayEquals(" hope for tomorrow. The important thing is not to stop questioning.".getBytes(StandardCharsets.UTF_8), scanner.nextToken()); assertNull(scanner.nextToken()); } @@ -149,9 +147,9 @@ public void validateWithMultiByteDelimiter() throws IOException { String data = "foodaabardaabazzz"; ByteArrayInputStream is = new ByteArrayInputStream(data.getBytes(StandardCharsets.UTF_8)); StreamDemarcator scanner = new StreamDemarcator(is, "daa".getBytes(StandardCharsets.UTF_8), 1000); - assertTrue(Arrays.equals("foo".getBytes(StandardCharsets.UTF_8), scanner.nextToken())); - assertTrue(Arrays.equals("bar".getBytes(StandardCharsets.UTF_8), scanner.nextToken())); - assertTrue(Arrays.equals("bazzz".getBytes(StandardCharsets.UTF_8), scanner.nextToken())); + assertArrayEquals("foo".getBytes(StandardCharsets.UTF_8), scanner.nextToken()); + assertArrayEquals("bar".getBytes(StandardCharsets.UTF_8), scanner.nextToken()); + assertArrayEquals("bazzz".getBytes(StandardCharsets.UTF_8), scanner.nextToken()); assertNull(scanner.nextToken()); } @@ -160,9 +158,9 @@ public void validateWithMultiByteDelimiterAtTheBeginning() throws IOException { String data = "daafoodaabardaabazzz"; ByteArrayInputStream is = new ByteArrayInputStream(data.getBytes(StandardCharsets.UTF_8)); StreamDemarcator scanner = new StreamDemarcator(is, "daa".getBytes(StandardCharsets.UTF_8), 1000); - assertTrue(Arrays.equals("foo".getBytes(StandardCharsets.UTF_8), scanner.nextToken())); - assertTrue(Arrays.equals("bar".getBytes(StandardCharsets.UTF_8), scanner.nextToken())); - assertTrue(Arrays.equals("bazzz".getBytes(StandardCharsets.UTF_8), scanner.nextToken())); + assertArrayEquals("foo".getBytes(StandardCharsets.UTF_8), scanner.nextToken()); + assertArrayEquals("bar".getBytes(StandardCharsets.UTF_8), scanner.nextToken()); + assertArrayEquals("bazzz".getBytes(StandardCharsets.UTF_8), scanner.nextToken()); assertNull(scanner.nextToken()); } @@ -171,9 +169,9 @@ public void validateWithMultiByteDelimiterSmallInitialBuffer() throws IOExceptio String data = "foodaabarffdaabazz"; ByteArrayInputStream is = new ByteArrayInputStream(data.getBytes(StandardCharsets.UTF_8)); StreamDemarcator scanner = new StreamDemarcator(is, "daa".getBytes(StandardCharsets.UTF_8), 1000, 1); - assertTrue(Arrays.equals("foo".getBytes(StandardCharsets.UTF_8), scanner.nextToken())); - assertTrue(Arrays.equals("barff".getBytes(StandardCharsets.UTF_8), scanner.nextToken())); - assertTrue(Arrays.equals("bazz".getBytes(StandardCharsets.UTF_8), scanner.nextToken())); + assertArrayEquals("foo".getBytes(StandardCharsets.UTF_8), scanner.nextToken()); + assertArrayEquals("barff".getBytes(StandardCharsets.UTF_8), scanner.nextToken()); + assertArrayEquals("bazz".getBytes(StandardCharsets.UTF_8), scanner.nextToken()); assertNull(scanner.nextToken()); } diff --git a/nifi-commons/nifi-utils/src/test/java/org/apache/nifi/util/file/classloader/TestClassLoaderUtils.java b/nifi-commons/nifi-utils/src/test/java/org/apache/nifi/util/file/classloader/TestClassLoaderUtils.java index 5c11257411c7..4b267058d877 100644 --- a/nifi-commons/nifi-utils/src/test/java/org/apache/nifi/util/file/classloader/TestClassLoaderUtils.java +++ b/nifi-commons/nifi-utils/src/test/java/org/apache/nifi/util/file/classloader/TestClassLoaderUtils.java @@ -29,7 +29,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.jupiter.api.Assertions.assertTrue; public class TestClassLoaderUtils { @@ -37,17 +36,17 @@ public class TestClassLoaderUtils { public void testGetCustomClassLoader() throws MalformedURLException, ClassNotFoundException { final String jarFilePath = "src/test/resources/TestClassLoaderUtils"; ClassLoader customClassLoader = ClassLoaderUtils.getCustomClassLoader(jarFilePath, this.getClass().getClassLoader(), getJarFilenameFilter()); - assertTrue(customClassLoader != null); - assertTrue(customClassLoader.loadClass("TestSuccess") != null); + assertNotNull(customClassLoader); + assertNotNull(customClassLoader.loadClass("TestSuccess")); } @Test public void testGetCustomClassLoaderNoPathSpecified() throws MalformedURLException { final ClassLoader originalClassLoader = this.getClass().getClassLoader(); ClassLoader customClassLoader = ClassLoaderUtils.getCustomClassLoader(null, originalClassLoader, getJarFilenameFilter()); - assertTrue(customClassLoader != null); + assertNotNull(customClassLoader); ClassNotFoundException cex = assertThrows(ClassNotFoundException.class, () -> customClassLoader.loadClass("TestSuccess")); - assertTrue(cex.getLocalizedMessage().equals("TestSuccess")); + assertEquals("TestSuccess", cex.getLocalizedMessage()); } @Test @@ -55,7 +54,7 @@ public void testGetCustomClassLoaderWithInvalidPath() { final String jarFilePath = "src/test/resources/FakeTestClassLoaderUtils/TestSuccess.jar"; MalformedURLException mex = assertThrows(MalformedURLException.class, () -> ClassLoaderUtils.getCustomClassLoader(jarFilePath, this.getClass().getClassLoader(), getJarFilenameFilter())); - assertTrue(mex.getLocalizedMessage().equals("Path specified does not exist")); + assertEquals("Path specified does not exist", mex.getLocalizedMessage()); } @Test diff --git a/nifi-extension-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/dynamodb/ItemKeysTest.java b/nifi-extension-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/dynamodb/ItemKeysTest.java index b26273cfb77e..e31cf2abb2c2 100644 --- a/nifi-extension-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/dynamodb/ItemKeysTest.java +++ b/nifi-extension-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/dynamodb/ItemKeysTest.java @@ -20,7 +20,7 @@ import software.amazon.awssdk.services.dynamodb.model.AttributeValue; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotEquals; public class ItemKeysTest { @@ -64,7 +64,7 @@ public void testHashNotNullRangeNotNullEquals() { public void testHashNotNullRangeNotNullForOtherNotEquals() { ItemKeys ik1 = new ItemKeys(null, string("ab")); ItemKeys ik2 = new ItemKeys(string("ab"), null); - assertFalse(ik1.equals(ik2)); + assertNotEquals(ik1, ik2); } private static AttributeValue string(final String s) { diff --git a/nifi-extension-bundles/nifi-evtx-bundle/nifi-evtx-processors/src/test/java/org/apache/nifi/processors/evtx/XmlBxmlNodeVisitorTest.java b/nifi-extension-bundles/nifi-evtx-bundle/nifi-evtx-processors/src/test/java/org/apache/nifi/processors/evtx/XmlBxmlNodeVisitorTest.java index 67c3c033e699..41ca0d59bda4 100644 --- a/nifi-extension-bundles/nifi-evtx-bundle/nifi-evtx-processors/src/test/java/org/apache/nifi/processors/evtx/XmlBxmlNodeVisitorTest.java +++ b/nifi-extension-bundles/nifi-evtx-bundle/nifi-evtx-processors/src/test/java/org/apache/nifi/processors/evtx/XmlBxmlNodeVisitorTest.java @@ -46,8 +46,8 @@ import java.util.Arrays; import java.util.List; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; import static org.junit.jupiter.api.Assertions.assertNotEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Mockito.any; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.inOrder; @@ -319,7 +319,7 @@ public void testVisitRootNode() throws IOException { verify(child).accept(captor.capture()); BxmlNodeVisitor value = captor.getValue(); - assertTrue(value instanceof XmlBxmlNodeVisitor); + assertInstanceOf(XmlBxmlNodeVisitor.class, value); assertNotEquals(xmlBxmlNodeVisitor, value); } } diff --git a/nifi-extension-bundles/nifi-evtx-bundle/nifi-evtx-processors/src/test/java/org/apache/nifi/processors/evtx/parser/ChunkHeaderTest.java b/nifi-extension-bundles/nifi-evtx-bundle/nifi-evtx-processors/src/test/java/org/apache/nifi/processors/evtx/parser/ChunkHeaderTest.java index 7376852445bd..5d34cdf395f7 100644 --- a/nifi-extension-bundles/nifi-evtx-bundle/nifi-evtx-processors/src/test/java/org/apache/nifi/processors/evtx/parser/ChunkHeaderTest.java +++ b/nifi-extension-bundles/nifi-evtx-bundle/nifi-evtx-processors/src/test/java/org/apache/nifi/processors/evtx/parser/ChunkHeaderTest.java @@ -41,6 +41,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Mockito.mock; @@ -137,7 +138,7 @@ public void testInit() throws IOException { RootNode rootNode = next.getRootNode(); List children = rootNode.getChildren(); assertEquals(1, children.size()); - assertTrue(children.get(0) instanceof EndOfStreamNode); + assertInstanceOf(EndOfStreamNode.class, children.get(0)); assertEquals(0, rootNode.getSubstitutions().size()); assertFalse(chunkHeader.hasNext()); diff --git a/nifi-extension-bundles/nifi-evtx-bundle/nifi-evtx-processors/src/test/java/org/apache/nifi/processors/evtx/parser/RecordTest.java b/nifi-extension-bundles/nifi-evtx-bundle/nifi-evtx-processors/src/test/java/org/apache/nifi/processors/evtx/parser/RecordTest.java index e03ea2022fc7..9f1de61fe44e 100644 --- a/nifi-extension-bundles/nifi-evtx-bundle/nifi-evtx-processors/src/test/java/org/apache/nifi/processors/evtx/parser/RecordTest.java +++ b/nifi-extension-bundles/nifi-evtx-bundle/nifi-evtx-processors/src/test/java/org/apache/nifi/processors/evtx/parser/RecordTest.java @@ -31,7 +31,7 @@ import java.util.List; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; @ExtendWith(MockitoExtension.class) public class RecordTest { @@ -67,7 +67,7 @@ public void testInit() { RootNode rootNode = record.getRootNode(); List children = rootNode.getChildren(); assertEquals(1, children.size()); - assertTrue(children.get(0) instanceof EndOfStreamNode); + assertInstanceOf(EndOfStreamNode.class, children.get(0)); assertEquals(0, rootNode.getSubstitutions().size()); } } diff --git a/nifi-extension-bundles/nifi-evtx-bundle/nifi-evtx-processors/src/test/java/org/apache/nifi/processors/evtx/parser/bxml/AttributeNodeTest.java b/nifi-extension-bundles/nifi-evtx-bundle/nifi-evtx-processors/src/test/java/org/apache/nifi/processors/evtx/parser/bxml/AttributeNodeTest.java index ae5137e0f23d..8876c671f671 100644 --- a/nifi-extension-bundles/nifi-evtx-bundle/nifi-evtx-processors/src/test/java/org/apache/nifi/processors/evtx/parser/bxml/AttributeNodeTest.java +++ b/nifi-extension-bundles/nifi-evtx-bundle/nifi-evtx-processors/src/test/java/org/apache/nifi/processors/evtx/parser/bxml/AttributeNodeTest.java @@ -26,7 +26,7 @@ import java.util.List; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoMoreInteractions; @@ -58,10 +58,10 @@ protected String getString() { public void testInit() { assertEquals(ATTRIBUTE_NAME, attributeNode.getAttributeName()); BxmlNode attributeNodeValue = attributeNode.getValue(); - assertTrue(attributeNodeValue instanceof ValueNode); + assertInstanceOf(ValueNode.class, attributeNodeValue); List children = ((ValueNode) attributeNodeValue).getChildren(); assertEquals(1, children.size()); - assertTrue(children.get(0) instanceof NullTypeNode); + assertInstanceOf(NullTypeNode.class, children.get(0)); } @Test diff --git a/nifi-extension-bundles/nifi-evtx-bundle/nifi-evtx-processors/src/test/java/org/apache/nifi/processors/evtx/parser/bxml/OpenStartElementNodeTest.java b/nifi-extension-bundles/nifi-evtx-bundle/nifi-evtx-processors/src/test/java/org/apache/nifi/processors/evtx/parser/bxml/OpenStartElementNodeTest.java index 4d1337d211b4..894f53817874 100644 --- a/nifi-extension-bundles/nifi-evtx-bundle/nifi-evtx-processors/src/test/java/org/apache/nifi/processors/evtx/parser/bxml/OpenStartElementNodeTest.java +++ b/nifi-extension-bundles/nifi-evtx-bundle/nifi-evtx-processors/src/test/java/org/apache/nifi/processors/evtx/parser/bxml/OpenStartElementNodeTest.java @@ -27,6 +27,7 @@ import java.util.List; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; @@ -58,7 +59,7 @@ public void testInit() { assertEquals(tagName, openStartElementNode.getTagName()); List children = openStartElementNode.getChildren(); assertEquals(1, children.size()); - assertTrue(children.get(0) instanceof CloseEmptyElementNode); + assertInstanceOf(CloseEmptyElementNode.class, children.get(0)); } @Test diff --git a/nifi-extension-bundles/nifi-evtx-bundle/nifi-evtx-processors/src/test/java/org/apache/nifi/processors/evtx/parser/bxml/RootNodeTest.java b/nifi-extension-bundles/nifi-evtx-bundle/nifi-evtx-processors/src/test/java/org/apache/nifi/processors/evtx/parser/bxml/RootNodeTest.java index f415402dedeb..020e705395af 100644 --- a/nifi-extension-bundles/nifi-evtx-bundle/nifi-evtx-processors/src/test/java/org/apache/nifi/processors/evtx/parser/bxml/RootNodeTest.java +++ b/nifi-extension-bundles/nifi-evtx-bundle/nifi-evtx-processors/src/test/java/org/apache/nifi/processors/evtx/parser/bxml/RootNodeTest.java @@ -26,7 +26,7 @@ import java.util.List; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoMoreInteractions; @@ -55,7 +55,7 @@ public void setup() throws IOException { public void testInit() { List children = rootNode.getChildren(); assertEquals(1, children.size()); - assertTrue(children.get(0) instanceof EndOfStreamNode); + assertInstanceOf(EndOfStreamNode.class, children.get(0)); List substitutions = rootNode.getSubstitutions(); assertEquals(1, substitutions.size()); diff --git a/nifi-extension-bundles/nifi-evtx-bundle/nifi-evtx-processors/src/test/java/org/apache/nifi/processors/evtx/parser/bxml/ValueNodeTest.java b/nifi-extension-bundles/nifi-evtx-bundle/nifi-evtx-processors/src/test/java/org/apache/nifi/processors/evtx/parser/bxml/ValueNodeTest.java index 7b15361fbc44..2e8684ff6bb0 100644 --- a/nifi-extension-bundles/nifi-evtx-bundle/nifi-evtx-processors/src/test/java/org/apache/nifi/processors/evtx/parser/bxml/ValueNodeTest.java +++ b/nifi-extension-bundles/nifi-evtx-bundle/nifi-evtx-processors/src/test/java/org/apache/nifi/processors/evtx/parser/bxml/ValueNodeTest.java @@ -26,7 +26,7 @@ import java.util.List; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoMoreInteractions; @@ -52,7 +52,7 @@ public void testInit() { assertEquals(getToken(), valueNode.getToken()); List children = valueNode.getChildren(); assertEquals(1, children.size()); - assertTrue(children.get(0) instanceof NullTypeNode); + assertInstanceOf(NullTypeNode.class, children.get(0)); } @Test diff --git a/nifi-extension-bundles/nifi-evtx-bundle/nifi-evtx-processors/src/test/java/org/apache/nifi/processors/evtx/parser/bxml/value/BXmlTypeNodeTest.java b/nifi-extension-bundles/nifi-evtx-bundle/nifi-evtx-processors/src/test/java/org/apache/nifi/processors/evtx/parser/bxml/value/BXmlTypeNodeTest.java index d0a27c00c550..34a842034e85 100644 --- a/nifi-extension-bundles/nifi-evtx-bundle/nifi-evtx-processors/src/test/java/org/apache/nifi/processors/evtx/parser/bxml/value/BXmlTypeNodeTest.java +++ b/nifi-extension-bundles/nifi-evtx-bundle/nifi-evtx-processors/src/test/java/org/apache/nifi/processors/evtx/parser/bxml/value/BXmlTypeNodeTest.java @@ -28,7 +28,7 @@ import java.util.List; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; public class BXmlTypeNodeTest extends BxmlNodeTestBase { private BXmlTypeNode bXmlTypeNode; @@ -47,7 +47,7 @@ public void testInit() { RootNode rootNode = bXmlTypeNode.getRootNode(); List children = rootNode.getChildren(); assertEquals(1, children.size()); - assertTrue(children.get(0) instanceof EndOfStreamNode); + assertInstanceOf(EndOfStreamNode.class, children.get(0)); assertEquals(0, rootNode.getSubstitutions().size()); assertEquals(rootNode.toString(), bXmlTypeNode.getValue()); } diff --git a/nifi-extension-bundles/nifi-extension-utils/nifi-database-utils/src/test/java/org/apache/nifi/util/db/TestJdbcCommon.java b/nifi-extension-bundles/nifi-extension-utils/nifi-database-utils/src/test/java/org/apache/nifi/util/db/TestJdbcCommon.java index 19cdd334febf..ed154ef7e0d2 100644 --- a/nifi-extension-bundles/nifi-extension-utils/nifi-database-utils/src/test/java/org/apache/nifi/util/db/TestJdbcCommon.java +++ b/nifi-extension-bundles/nifi-extension-utils/nifi-database-utils/src/test/java/org/apache/nifi/util/db/TestJdbcCommon.java @@ -81,6 +81,7 @@ import static org.apache.nifi.util.db.JdbcCommon.MASKED_LOG_VALUE; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertThrows; @@ -609,7 +610,7 @@ record = dataFileReader.next(record); assertNull(o); } else { assertNotNull(o); - assertTrue(o instanceof ByteBuffer); + assertInstanceOf(ByteBuffer.class, o); final byte[] blob = ((ByteBuffer) o).array(); assertEquals(4002, blob.length); // Third byte should be 67 ('C') @@ -647,7 +648,7 @@ public void testConvertToAvroStreamForClob_FreeNotSupported() throws SQLExceptio while (dataFileReader.hasNext()) { record = dataFileReader.next(record); Object o = record.get("t_clob"); - assertTrue(o instanceof Utf8); + assertInstanceOf(Utf8.class, o); assertEquals("test clob", o.toString()); } } @@ -681,7 +682,7 @@ public void testConvertToAvroStreamForBlob_FreeNotSupported() throws SQLExceptio while (dataFileReader.hasNext()) { record = dataFileReader.next(record); Object o = record.get("t_blob"); - assertTrue(o instanceof ByteBuffer); + assertInstanceOf(ByteBuffer.class, o); ByteBuffer bb = (ByteBuffer) o; assertEquals("test blob", new String(bb.array(), StandardCharsets.UTF_8)); } diff --git a/nifi-extension-bundles/nifi-extension-utils/nifi-put-pattern/src/test/java/org/apache/nifi/processor/util/pattern/TestExceptionHandler.java b/nifi-extension-bundles/nifi-extension-utils/nifi-put-pattern/src/test/java/org/apache/nifi/processor/util/pattern/TestExceptionHandler.java index a7ff33e5f0d6..fedf666bb93d 100644 --- a/nifi-extension-bundles/nifi-extension-utils/nifi-put-pattern/src/test/java/org/apache/nifi/processor/util/pattern/TestExceptionHandler.java +++ b/nifi-extension-bundles/nifi-extension-utils/nifi-put-pattern/src/test/java/org/apache/nifi/processor/util/pattern/TestExceptionHandler.java @@ -29,8 +29,8 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.fail; public class TestExceptionHandler { @@ -90,7 +90,7 @@ public void testBasicUsage() { final Integer nullInput = null; ProcessException pe = assertThrows(ProcessException.class, () -> handler.execute(context, nullInput, i -> r.set(p.divide(i, 2))), "Exception should be thrown because input is null."); - assertTrue(pe.getCause() instanceof NullPointerException); + assertInstanceOf(NullPointerException.class, pe.getCause()); } // Reusable Exception mapping function. diff --git a/nifi-extension-bundles/nifi-extension-utils/nifi-record-utils/nifi-avro-record-utils/src/test/java/org/apache/nifi/avro/TestAvroTypeUtil.java b/nifi-extension-bundles/nifi-extension-utils/nifi-record-utils/nifi-avro-record-utils/src/test/java/org/apache/nifi/avro/TestAvroTypeUtil.java index d629518caed5..dbc53dd147e7 100644 --- a/nifi-extension-bundles/nifi-extension-utils/nifi-record-utils/nifi-avro-record-utils/src/test/java/org/apache/nifi/avro/TestAvroTypeUtil.java +++ b/nifi-extension-bundles/nifi-extension-utils/nifi-record-utils/nifi-avro-record-utils/src/test/java/org/apache/nifi/avro/TestAvroTypeUtil.java @@ -63,8 +63,10 @@ import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertSame; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.fail; @@ -221,7 +223,7 @@ public void testAvroUUIDToRecordApiUUID() { Optional uuidField = recordSchema.getField("uuid_test"); assertTrue(uuidField.isPresent()); RecordField field = uuidField.get(); - assertTrue(field.getDataType() == RecordFieldType.UUID.getDataType()); + assertSame(field.getDataType(), RecordFieldType.UUID.getDataType()); } @Test @@ -307,7 +309,7 @@ public void testDefaultArrayValue1() throws IOException { RecordSchema record = AvroTypeUtil.createSchema(avroSchema); RecordField field = record.getField("listOfInt").get(); assertEquals(RecordFieldType.ARRAY, field.getDataType().getFieldType()); - assertTrue(field.getDefaultValue() instanceof Object[]); + assertInstanceOf(Object[].class, field.getDefaultValue()); assertEquals(1, ((Object[]) field.getDefaultValue()).length); } @@ -329,7 +331,7 @@ public void testDefaultArrayValue2() throws IOException { RecordSchema record = AvroTypeUtil.createSchema(avroSchema); RecordField field = record.getField("listOfInt").get(); assertEquals(RecordFieldType.ARRAY, field.getDataType().getFieldType()); - assertTrue(field.getDefaultValue() instanceof Object[]); + assertInstanceOf(Object[].class, field.getDefaultValue()); assertArrayEquals(new Object[] {1, 2}, ((Object[]) field.getDefaultValue())); } @@ -359,7 +361,7 @@ public void testDefaultArrayValuesInRecordsCase1() throws IOException { RecordSchema childSchema = data.getChildSchema(); RecordField childField = childSchema.getField("listOfInt").get(); assertEquals(RecordFieldType.ARRAY, childField.getDataType().getFieldType()); - assertTrue(childField.getDefaultValue() instanceof Object[]); + assertInstanceOf(Object[].class, childField.getDefaultValue()); assertArrayEquals(new Object[] {0}, ((Object[]) childField.getDefaultValue())); } @@ -389,7 +391,7 @@ public void testDefaultArrayValuesInRecordsCase2() throws IOException { RecordSchema childSchema = data.getChildSchema(); RecordField childField = childSchema.getField("listOfInt").get(); assertEquals(RecordFieldType.ARRAY, childField.getDataType().getFieldType()); - assertTrue(childField.getDefaultValue() instanceof Object[]); + assertInstanceOf(Object[].class, childField.getDefaultValue()); assertArrayEquals(new Object[] {1, 2, 3}, ((Object[]) childField.getDefaultValue())); } @Test @@ -587,7 +589,7 @@ public void testToDecimalConversion() { return; } - assertTrue(convertedValue instanceof ByteBuffer); + assertInstanceOf(ByteBuffer.class, convertedValue); final ByteBuffer serializedBytes = (ByteBuffer) convertedValue; final BigDecimal bigDecimal = new Conversions.DecimalConversion().fromBytes(serializedBytes, fieldSchema, @@ -652,7 +654,7 @@ private void thenConvertAvroSchemaToRecordSchema(Schema avroSchema, BigDecimal e final Object resultObject = convertedMap.get("amount"); assertNotNull(resultObject); - assertTrue(resultObject instanceof BigDecimal); + assertInstanceOf(BigDecimal.class, resultObject); final BigDecimal resultBigDecimal = (BigDecimal) resultObject; assertEquals(expectedBigDecimal, resultBigDecimal); @@ -664,7 +666,7 @@ public void testBytesDecimalConversion() { final Schema fieldSchema = Schema.create(Type.BYTES); decimalType.addToSchema(fieldSchema); final Object convertedValue = AvroTypeUtil.convertToAvroObject("2.5", fieldSchema, StandardCharsets.UTF_8); - assertTrue(convertedValue instanceof ByteBuffer); + assertInstanceOf(ByteBuffer.class, convertedValue); final ByteBuffer serializedBytes = (ByteBuffer) convertedValue; final BigDecimal bigDecimal = new Conversions.DecimalConversion().fromBytes(serializedBytes, fieldSchema, decimalType); assertEquals(new BigDecimal("2.5").setScale(8), bigDecimal); @@ -678,7 +680,7 @@ public void testDateConversion() { final Schema fieldSchema = Schema.create(Type.INT); dateType.addToSchema(fieldSchema); final Object convertedValue = AvroTypeUtil.convertToAvroObject(Date.valueOf(date), fieldSchema); - assertTrue(convertedValue instanceof Integer); + assertInstanceOf(Integer.class, convertedValue); final int epochDay = (int) LocalDate.parse(date).toEpochDay(); assertEquals(epochDay, convertedValue); } @@ -689,7 +691,7 @@ public void testFixedDecimalConversion() { final Schema fieldSchema = Schema.createFixed("mydecimal", "no doc", "myspace", 18); decimalType.addToSchema(fieldSchema); final Object convertedValue = AvroTypeUtil.convertToAvroObject("2.5", fieldSchema, StandardCharsets.UTF_8); - assertTrue(convertedValue instanceof GenericFixed); + assertInstanceOf(GenericFixed.class, convertedValue); final GenericFixed genericFixed = (GenericFixed) convertedValue; final BigDecimal bigDecimal = new Conversions.DecimalConversion().fromFixed(genericFixed, fieldSchema, decimalType); assertEquals(new BigDecimal("2.5").setScale(8), bigDecimal); @@ -706,14 +708,14 @@ public void testSchemaNameNotEmpty() throws IOException { @Test public void testStringToBytesConversion() { Object o = AvroTypeUtil.convertToAvroObject("Hello", Schema.create(Type.BYTES), StandardCharsets.UTF_16); - assertTrue(o instanceof ByteBuffer); + assertInstanceOf(ByteBuffer.class, o); assertEquals("Hello", new String(((ByteBuffer) o).array(), StandardCharsets.UTF_16)); } @Test public void testStringToNullableBytesConversion() { Object o = AvroTypeUtil.convertToAvroObject("Hello", Schema.createUnion(Schema.create(Type.NULL), Schema.create(Type.BYTES)), StandardCharsets.UTF_16); - assertTrue(o instanceof ByteBuffer); + assertInstanceOf(ByteBuffer.class, o); assertEquals("Hello", new String(((ByteBuffer) o).array(), StandardCharsets.UTF_16)); } @@ -721,7 +723,7 @@ public void testStringToNullableBytesConversion() { public void testBytesToStringConversion() { final Charset charset = Charset.forName("UTF_32LE"); Object o = AvroTypeUtil.convertToAvroObject("Hello".getBytes(charset), Schema.create(Type.STRING), charset); - assertTrue(o instanceof String); + assertInstanceOf(String.class, o); assertEquals("Hello", o); } @@ -764,7 +766,7 @@ public void testAliasCreatedForInvalidField() { public void testListToArrayConversion() { final Charset charset = StandardCharsets.UTF_8; Object o = AvroTypeUtil.convertToAvroObject(Collections.singletonList("Hello"), Schema.createArray(Schema.create(Type.STRING)), charset); - assertTrue(o instanceof List); + assertInstanceOf(List.class, o); assertEquals(1, ((List) o).size()); assertEquals("Hello", ((List) o).get(0)); } @@ -774,7 +776,7 @@ public void testMapToRecordConversion() { final Charset charset = StandardCharsets.UTF_8; Object o = AvroTypeUtil.convertToAvroObject(Collections.singletonMap("Hello", "World"), Schema.createRecord(null, null, null, false, Collections.singletonList(new Field("Hello", Schema.create(Type.STRING), "", ""))), charset); - assertTrue(o instanceof Record); + assertInstanceOf(Record.class, o); assertEquals("World", ((Record) o).get("Hello")); } @@ -796,12 +798,12 @@ public void testListAndMapConversion() { obj.put("List", list); Object o = AvroTypeUtil.convertToAvroObject(obj, s); - assertTrue(o instanceof Record); + assertInstanceOf(Record.class, o); List innerList = (List) ((Record) o).get("List"); assertNotNull( innerList ); assertEquals(10, innerList.size()); for (Object inner : innerList) { - assertTrue(inner instanceof Record); + assertInstanceOf(Record.class, inner); assertNotNull(((Record) inner).get("Message")); } } @@ -908,8 +910,8 @@ public void testConvertNifiRecordIntoAvroRecord() throws IOException { // then final HashMap numbers = (HashMap) result.get("numbers"); - assertTrue(Long.class.isInstance(numbers.get("number1"))); - assertTrue(Long.class.isInstance(numbers.get("number2"))); + assertInstanceOf(Long.class, numbers.get("number1")); + assertInstanceOf(Long.class, numbers.get("number2")); } @Test diff --git a/nifi-extension-bundles/nifi-extension-utils/nifi-record-utils/nifi-avro-record-utils/src/test/java/org/apache/nifi/schema/access/InferenceSchemaStrategyTest.java b/nifi-extension-bundles/nifi-extension-utils/nifi-record-utils/nifi-avro-record-utils/src/test/java/org/apache/nifi/schema/access/InferenceSchemaStrategyTest.java index 71186bc90b62..4efb6543d858 100644 --- a/nifi-extension-bundles/nifi-extension-utils/nifi-record-utils/nifi-avro-record-utils/src/test/java/org/apache/nifi/schema/access/InferenceSchemaStrategyTest.java +++ b/nifi-extension-bundles/nifi-extension-utils/nifi-record-utils/nifi-avro-record-utils/src/test/java/org/apache/nifi/schema/access/InferenceSchemaStrategyTest.java @@ -36,8 +36,8 @@ import java.util.Optional; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.fail; public class InferenceSchemaStrategyTest { @@ -89,7 +89,7 @@ public void testSchemaConversionWhenMap() throws Exception { // then assertNotNull(result); - assertTrue(RecordDataType.class.isInstance(result.getField("f1").get().getDataType())); + assertInstanceOf(RecordDataType.class, result.getField("f1").get().getDataType()); final RecordDataType recordDataType = (RecordDataType) result.getField("f1").get().getDataType(); final RecordSchema childSchema = recordDataType.getChildSchema(); diff --git a/nifi-extension-bundles/nifi-hazelcast-bundle/nifi-hazelcast-services/src/test/java/org/apache/nifi/hazelcast/services/cachemanager/ExternalHazelcastCacheManagerTest.java b/nifi-extension-bundles/nifi-hazelcast-bundle/nifi-hazelcast-services/src/test/java/org/apache/nifi/hazelcast/services/cachemanager/ExternalHazelcastCacheManagerTest.java index 437d94dc3785..6e090646e2c5 100644 --- a/nifi-extension-bundles/nifi-hazelcast-bundle/nifi-hazelcast-services/src/test/java/org/apache/nifi/hazelcast/services/cachemanager/ExternalHazelcastCacheManagerTest.java +++ b/nifi-extension-bundles/nifi-hazelcast-bundle/nifi-hazelcast-services/src/test/java/org/apache/nifi/hazelcast/services/cachemanager/ExternalHazelcastCacheManagerTest.java @@ -26,7 +26,7 @@ import java.net.InetSocketAddress; import java.net.SocketAddress; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; public class ExternalHazelcastCacheManagerTest extends AbstractHazelcastCacheManagerTest { private HazelcastInstance hazelcastInstance; @@ -55,7 +55,7 @@ public void testExecution() throws Exception { testRunner.addControllerService("hazelcast-connection-service", testSubject); final SocketAddress localAddress = hazelcastInstance.getLocalEndpoint().getSocketAddress(); - assertTrue(localAddress instanceof InetSocketAddress); + assertInstanceOf(InetSocketAddress.class, localAddress); final int port = ((InetSocketAddress) localAddress).getPort(); testRunner.setProperty(testSubject, ExternalHazelcastCacheManager.HAZELCAST_SERVER_ADDRESS, "localhost:" + port); diff --git a/nifi-extension-bundles/nifi-jms-bundle/nifi-jms-processors/src/test/java/org/apache/nifi/jms/processors/JMSPublisherConsumerIT.java b/nifi-extension-bundles/nifi-jms-bundle/nifi-jms-processors/src/test/java/org/apache/nifi/jms/processors/JMSPublisherConsumerIT.java index c42a739f6efe..babd460e14c1 100644 --- a/nifi-extension-bundles/nifi-jms-bundle/nifi-jms-processors/src/test/java/org/apache/nifi/jms/processors/JMSPublisherConsumerIT.java +++ b/nifi-extension-bundles/nifi-jms-bundle/nifi-jms-processors/src/test/java/org/apache/nifi/jms/processors/JMSPublisherConsumerIT.java @@ -51,6 +51,7 @@ import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Mockito.mock; @@ -222,7 +223,7 @@ public void validateBytesConvertedToBytesMessageOnSend() throws Exception { publisher.publish(destinationName, "hellomq".getBytes()); Message receivedMessage = jmsTemplate.receive(destinationName); - assertTrue(receivedMessage instanceof BytesMessage); + assertInstanceOf(BytesMessage.class, receivedMessage); byte[] bytes = new byte[7]; ((BytesMessage) receivedMessage).readBytes(bytes); assertEquals("hellomq", new String(bytes)); @@ -249,11 +250,11 @@ public void validateJmsHeadersAndPropertiesAreTransferredFromFFAttributes() thro publisher.publish(destinationName, "hellomq".getBytes(), flowFileAttributes); Message receivedMessage = jmsTemplate.receive(destinationName); - assertTrue(receivedMessage instanceof BytesMessage); + assertInstanceOf(BytesMessage.class, receivedMessage); assertEquals("foo", receivedMessage.getStringProperty("foo")); assertTrue(receivedMessage.propertyExists("hyphen-property")); assertTrue(receivedMessage.propertyExists("fullstop.property")); - assertTrue(receivedMessage.getJMSReplyTo() instanceof Topic); + assertInstanceOf(Topic.class, receivedMessage.getJMSReplyTo()); assertEquals(1, receivedMessage.getJMSDeliveryMode()); assertEquals(1, receivedMessage.getJMSPriority()); assertEquals("myTopic", ((Topic) receivedMessage.getJMSReplyTo()).getTopicName()); diff --git a/nifi-extension-bundles/nifi-jms-bundle/nifi-jms-processors/src/test/java/org/apache/nifi/jms/processors/PublishJMSIT.java b/nifi-extension-bundles/nifi-jms-bundle/nifi-jms-processors/src/test/java/org/apache/nifi/jms/processors/PublishJMSIT.java index 060445171c53..c67585bc0b1b 100644 --- a/nifi-extension-bundles/nifi-jms-bundle/nifi-jms-processors/src/test/java/org/apache/nifi/jms/processors/PublishJMSIT.java +++ b/nifi-extension-bundles/nifi-jms-bundle/nifi-jms-processors/src/test/java/org/apache/nifi/jms/processors/PublishJMSIT.java @@ -71,6 +71,7 @@ import static org.apache.nifi.jms.processors.ioconcept.reader.StateTrackingFlowFileReader.ATTR_READ_FAILED_INDEX_SUFFIX; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -230,7 +231,7 @@ public void validatePublishTextMessage() throws Exception { JmsTemplate jmst = new JmsTemplate(cf); Message message = jmst.receive(destinationName); - assertTrue(message instanceof TextMessage); + assertInstanceOf(TextMessage.class, message); TextMessage textMessage = (TextMessage) message; byte[] messageBytes = MessageBodyToBytesConverter.toBytes(textMessage); @@ -291,23 +292,23 @@ public void validatePublishPropertyTypes() throws Exception { byte[] messageBytes = MessageBodyToBytesConverter.toBytes(message); assertEquals("Hey dude!", new String(messageBytes)); - assertEquals(true, message.getObjectProperty("foo") instanceof String); + assertInstanceOf(String.class, message.getObjectProperty("foo")); assertEquals("foo", message.getStringProperty("foo")); - assertEquals(true, message.getObjectProperty("myboolean") instanceof Boolean); - assertEquals(true, message.getBooleanProperty("myboolean")); - assertEquals(true, message.getObjectProperty("mybyte") instanceof Byte); + assertInstanceOf(Boolean.class, message.getObjectProperty("myboolean")); + assertTrue(message.getBooleanProperty("myboolean")); + assertInstanceOf(Byte.class, message.getObjectProperty("mybyte")); assertEquals(127, message.getByteProperty("mybyte")); - assertEquals(true, message.getObjectProperty("myshort") instanceof Short); + assertInstanceOf(Short.class, message.getObjectProperty("myshort")); assertEquals(16384, message.getShortProperty("myshort")); - assertEquals(true, message.getObjectProperty("myinteger") instanceof Integer); + assertInstanceOf(Integer.class, message.getObjectProperty("myinteger")); assertEquals(1544000, message.getIntProperty("myinteger")); - assertEquals(true, message.getObjectProperty("mylong") instanceof Long); + assertInstanceOf(Long.class, message.getObjectProperty("mylong")); assertEquals(9876543210L, message.getLongProperty("mylong")); - assertEquals(true, message.getObjectProperty("myfloat") instanceof Float); + assertInstanceOf(Float.class, message.getObjectProperty("myfloat")); assertEquals(3.14F, message.getFloatProperty("myfloat"), 0.001F); - assertEquals(true, message.getObjectProperty("mydouble") instanceof Double); + assertInstanceOf(Double.class, message.getObjectProperty("mydouble")); assertEquals(3.14159265359D, message.getDoubleProperty("mydouble"), 0.00000000001D); - assertEquals(true, message.getObjectProperty("badtype") instanceof String); + assertInstanceOf(String.class, message.getObjectProperty("badtype")); assertEquals("3.14", message.getStringProperty("badtype")); assertFalse(message.propertyExists("badint")); @@ -348,7 +349,7 @@ public void validateRegexAndIllegalHeaders() throws Exception { JmsTemplate jmst = new JmsTemplate(cf); Message message = jmst.receive(destinationName); - assertTrue(message instanceof TextMessage); + assertInstanceOf(TextMessage.class, message); TextMessage textMessage = (TextMessage) message; byte[] messageBytes = MessageBodyToBytesConverter.toBytes(textMessage); @@ -473,9 +474,9 @@ public void validateNIFI7563UsingOneThread() throws Exception { runner.enqueue("hi".getBytes(), flowFileAttributes); runner.enqueue("hi".getBytes(), flowFileAttributes); runner.run(2); - assertTrue(threads == connectionFactoryProxy.openedConnections(), "It is expected at least " + threads + " Connection to be opened."); - assertTrue(threads == connectionFactoryProxy.openedSessions(), "It is expected " + threads + " Session to be opened and there are " + connectionFactoryProxy.openedSessions()); - assertTrue(threads == connectionFactoryProxy.openedProducers(), "It is expected " + threads + " MessageProducer to be opened and there are " + connectionFactoryProxy.openedProducers()); + assertEquals(threads, connectionFactoryProxy.openedConnections(), "It is expected at least " + threads + " Connection to be opened."); + assertEquals(threads, connectionFactoryProxy.openedSessions(), "It is expected " + threads + " Session to be opened and there are " + connectionFactoryProxy.openedSessions()); + assertEquals(threads, connectionFactoryProxy.openedProducers(), "It is expected " + threads + " MessageProducer to be opened and there are " + connectionFactoryProxy.openedProducers()); assertTrue(connectionFactoryProxy.isAllResourcesClosed(), "Some resources were not closed."); } finally { if (broker != null) { diff --git a/nifi-extension-bundles/nifi-jolt-bundle/nifi-jolt-transform-json-ui/src/test/java/org/apache/nifi/web/standard/api/processor/TestProcessorResource.java b/nifi-extension-bundles/nifi-jolt-bundle/nifi-jolt-transform-json-ui/src/test/java/org/apache/nifi/web/standard/api/processor/TestProcessorResource.java index 6453c5318125..e8ed4e3bf991 100644 --- a/nifi-extension-bundles/nifi-jolt-bundle/nifi-jolt-transform-json-ui/src/test/java/org/apache/nifi/web/standard/api/processor/TestProcessorResource.java +++ b/nifi-extension-bundles/nifi-jolt-bundle/nifi-jolt-transform-json-ui/src/test/java/org/apache/nifi/web/standard/api/processor/TestProcessorResource.java @@ -44,7 +44,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.isNull; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; @@ -103,7 +102,7 @@ public void testSetProperties() { assertNotNull(response); JsonNode jsonNode = response.readEntity(JsonNode.class); assertNotNull(jsonNode); - assertTrue(jsonNode.get("properties").get("Jolt Transform").asText().equals("jolt-transform-chain")); + assertEquals("jolt-transform-chain", jsonNode.get("properties").get("Jolt Transform").asText()); } diff --git a/nifi-extension-bundles/nifi-jolt-bundle/nifi-jolt-transform-json-ui/src/test/java/org/apache/nifi/web/standard/api/processor/TestProcessorWebUtils.java b/nifi-extension-bundles/nifi-jolt-bundle/nifi-jolt-transform-json-ui/src/test/java/org/apache/nifi/web/standard/api/processor/TestProcessorWebUtils.java index 503fd0011b7d..36c29258df79 100644 --- a/nifi-extension-bundles/nifi-jolt-bundle/nifi-jolt-transform-json-ui/src/test/java/org/apache/nifi/web/standard/api/processor/TestProcessorWebUtils.java +++ b/nifi-extension-bundles/nifi-jolt-bundle/nifi-jolt-transform-json-ui/src/test/java/org/apache/nifi/web/standard/api/processor/TestProcessorWebUtils.java @@ -31,8 +31,8 @@ import java.lang.reflect.Method; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; @@ -64,7 +64,7 @@ public void testGetRequestContextForProcessor() throws NoSuchMethodException, IO Method method = ProcessorWebUtils.class.getDeclaredMethod("getRequestContext", String.class, HttpServletRequest.class); method.setAccessible(true); NiFiWebRequestContext requestContext = (NiFiWebRequestContext) method.invoke(null, "1", mock(HttpServletRequest.class)); - assertTrue(requestContext instanceof HttpServletRequestContext); + assertInstanceOf(HttpServletRequestContext.class, requestContext); assertEquals("1", requestContext.getId()); } diff --git a/nifi-extension-bundles/nifi-kafka-bundle/nifi-kafka-3-integration/src/test/java/org/apache/nifi/kafka/processors/PublishKafkaValueRecordIT.java b/nifi-extension-bundles/nifi-kafka-bundle/nifi-kafka-3-integration/src/test/java/org/apache/nifi/kafka/processors/PublishKafkaValueRecordIT.java index 4c7188c22e6d..08351c02666c 100644 --- a/nifi-extension-bundles/nifi-kafka-bundle/nifi-kafka-3-integration/src/test/java/org/apache/nifi/kafka/processors/PublishKafkaValueRecordIT.java +++ b/nifi-extension-bundles/nifi-kafka-bundle/nifi-kafka-3-integration/src/test/java/org/apache/nifi/kafka/processors/PublishKafkaValueRecordIT.java @@ -40,9 +40,9 @@ import java.util.Objects; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; import static org.junit.jupiter.api.Assertions.assertNotEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; @TestMethodOrder(MethodOrderer.MethodName.class) public class PublishKafkaValueRecordIT extends AbstractPublishKafkaIT { @@ -102,7 +102,7 @@ public void test2ConsumeMultipleRecords() throws IOException { assertNotNull(kafkaValue); assertNotEquals(0, kafkaValue.get("id").asInt()); assertEquals(1, kafkaValue.get("name").asText().length()); - assertTrue(kafkaValue.get("address") instanceof ObjectNode); + assertInstanceOf(ObjectNode.class, kafkaValue.get("address")); } } } diff --git a/nifi-extension-bundles/nifi-kafka-bundle/nifi-kafka-3-integration/src/test/java/org/apache/nifi/kafka/processors/publish/additional/PublishKafkaContentX1IT.java b/nifi-extension-bundles/nifi-kafka-bundle/nifi-kafka-3-integration/src/test/java/org/apache/nifi/kafka/processors/publish/additional/PublishKafkaContentX1IT.java index f7fba11276c0..15ddd4eb75df 100644 --- a/nifi-extension-bundles/nifi-kafka-bundle/nifi-kafka-3-integration/src/test/java/org/apache/nifi/kafka/processors/publish/additional/PublishKafkaContentX1IT.java +++ b/nifi-extension-bundles/nifi-kafka-bundle/nifi-kafka-3-integration/src/test/java/org/apache/nifi/kafka/processors/publish/additional/PublishKafkaContentX1IT.java @@ -43,6 +43,7 @@ import java.util.Objects; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -97,7 +98,7 @@ public void test2ConsumeOneRecord() throws IOException { assertNotNull(kafkaValue); assertEquals("1234 First Street", kafkaValue.get("address").textValue()); assertEquals("12345", kafkaValue.get("zip").textValue()); - assertTrue(kafkaValue.get("account") instanceof ObjectNode); + assertInstanceOf(ObjectNode.class, kafkaValue.get("account")); } } } diff --git a/nifi-extension-bundles/nifi-kafka-bundle/nifi-kafka-3-integration/src/test/java/org/apache/nifi/kafka/processors/publish/additional/PublishKafkaWrapperX1IT.java b/nifi-extension-bundles/nifi-kafka-bundle/nifi-kafka-3-integration/src/test/java/org/apache/nifi/kafka/processors/publish/additional/PublishKafkaWrapperX1IT.java index 12e697381230..3c8cd8b7a57e 100644 --- a/nifi-extension-bundles/nifi-kafka-bundle/nifi-kafka-3-integration/src/test/java/org/apache/nifi/kafka/processors/publish/additional/PublishKafkaWrapperX1IT.java +++ b/nifi-extension-bundles/nifi-kafka-bundle/nifi-kafka-3-integration/src/test/java/org/apache/nifi/kafka/processors/publish/additional/PublishKafkaWrapperX1IT.java @@ -43,6 +43,7 @@ import java.util.Objects; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -88,7 +89,7 @@ public void test2ConsumeOneRecord() throws IOException { assertNotNull(kafkaValue); assertEquals("1234 First Street", kafkaValue.get("address").textValue()); assertEquals("12345", kafkaValue.get("zip").textValue()); - assertTrue(kafkaValue.get("account") instanceof ObjectNode); + assertInstanceOf(ObjectNode.class, kafkaValue.get("account")); } } } diff --git a/nifi-extension-bundles/nifi-kafka-bundle/nifi-kafka-3-integration/src/test/java/org/apache/nifi/kafka/processors/publish/additional/PublishKafkaWrapperX2IT.java b/nifi-extension-bundles/nifi-kafka-bundle/nifi-kafka-3-integration/src/test/java/org/apache/nifi/kafka/processors/publish/additional/PublishKafkaWrapperX2IT.java index 71299901d095..8f964b216b0c 100644 --- a/nifi-extension-bundles/nifi-kafka-bundle/nifi-kafka-3-integration/src/test/java/org/apache/nifi/kafka/processors/publish/additional/PublishKafkaWrapperX2IT.java +++ b/nifi-extension-bundles/nifi-kafka-bundle/nifi-kafka-3-integration/src/test/java/org/apache/nifi/kafka/processors/publish/additional/PublishKafkaWrapperX2IT.java @@ -41,6 +41,7 @@ import java.util.Objects; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -94,7 +95,7 @@ public void test2ConsumeOneRecord() throws IOException { assertNotNull(kafkaValue); assertEquals("1234 First Street", kafkaValue.get("address").textValue()); assertEquals("12345", kafkaValue.get("zip").textValue()); - assertTrue(kafkaValue.get("account") instanceof ObjectNode); + assertInstanceOf(ObjectNode.class, kafkaValue.get("account")); } } } diff --git a/nifi-extension-bundles/nifi-kafka-bundle/nifi-kafka-3-integration/src/test/java/org/apache/nifi/kafka/processors/publish/additional/PublishKafkaWrapperX3IT.java b/nifi-extension-bundles/nifi-kafka-bundle/nifi-kafka-3-integration/src/test/java/org/apache/nifi/kafka/processors/publish/additional/PublishKafkaWrapperX3IT.java index 406451f3ef4e..552ff124c407 100644 --- a/nifi-extension-bundles/nifi-kafka-bundle/nifi-kafka-3-integration/src/test/java/org/apache/nifi/kafka/processors/publish/additional/PublishKafkaWrapperX3IT.java +++ b/nifi-extension-bundles/nifi-kafka-bundle/nifi-kafka-3-integration/src/test/java/org/apache/nifi/kafka/processors/publish/additional/PublishKafkaWrapperX3IT.java @@ -43,6 +43,7 @@ import java.util.Objects; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -91,7 +92,7 @@ public void test2ConsumeOneRecord() throws IOException { assertNotNull(kafkaValue); assertEquals("1234 First Street", kafkaValue.get("address").textValue()); assertEquals("12345", kafkaValue.get("zip").textValue()); - assertTrue(kafkaValue.get("account") instanceof ObjectNode); + assertInstanceOf(ObjectNode.class, kafkaValue.get("account")); } } } diff --git a/nifi-extension-bundles/nifi-kafka-bundle/nifi-kafka-3-integration/src/test/java/org/apache/nifi/kafka/processors/publish/additional/PublishKafkaWrapperX4IT.java b/nifi-extension-bundles/nifi-kafka-bundle/nifi-kafka-3-integration/src/test/java/org/apache/nifi/kafka/processors/publish/additional/PublishKafkaWrapperX4IT.java index d16387d59bc3..3c978851ab58 100644 --- a/nifi-extension-bundles/nifi-kafka-bundle/nifi-kafka-3-integration/src/test/java/org/apache/nifi/kafka/processors/publish/additional/PublishKafkaWrapperX4IT.java +++ b/nifi-extension-bundles/nifi-kafka-bundle/nifi-kafka-3-integration/src/test/java/org/apache/nifi/kafka/processors/publish/additional/PublishKafkaWrapperX4IT.java @@ -43,6 +43,7 @@ import java.util.Objects; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -94,7 +95,7 @@ public void test2ConsumeOneRecord() throws IOException { assertNotNull(kafkaValue); assertEquals("1234 First Street", kafkaValue.get("address").textValue()); assertEquals("12345", kafkaValue.get("zip").textValue()); - assertTrue(kafkaValue.get("account") instanceof ObjectNode); + assertInstanceOf(ObjectNode.class, kafkaValue.get("account")); } } } diff --git a/nifi-extension-bundles/nifi-kafka-bundle/nifi-kafka-3-integration/src/test/java/org/apache/nifi/kafka/processors/publish/additional/PublishKafkaWrapperX5IT.java b/nifi-extension-bundles/nifi-kafka-bundle/nifi-kafka-3-integration/src/test/java/org/apache/nifi/kafka/processors/publish/additional/PublishKafkaWrapperX5IT.java index 3de3da941741..5f1b8d28b428 100644 --- a/nifi-extension-bundles/nifi-kafka-bundle/nifi-kafka-3-integration/src/test/java/org/apache/nifi/kafka/processors/publish/additional/PublishKafkaWrapperX5IT.java +++ b/nifi-extension-bundles/nifi-kafka-bundle/nifi-kafka-3-integration/src/test/java/org/apache/nifi/kafka/processors/publish/additional/PublishKafkaWrapperX5IT.java @@ -54,6 +54,7 @@ import java.util.concurrent.TimeoutException; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -135,7 +136,7 @@ public void test2ConsumeOneRecord() throws IOException { assertNotNull(kafkaValue); assertEquals("1234 First Street", kafkaValue.get("address").textValue()); assertEquals("12345", kafkaValue.get("zip").textValue()); - assertTrue(kafkaValue.get("account") instanceof ObjectNode); + assertInstanceOf(ObjectNode.class, kafkaValue.get("account")); } } } diff --git a/nifi-extension-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/test/java/org/apache/nifi/processors/mongodb/GetMongoIT.java b/nifi-extension-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/test/java/org/apache/nifi/processors/mongodb/GetMongoIT.java index 2e7edeac5e9e..cec3b812081d 100644 --- a/nifi-extension-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/test/java/org/apache/nifi/processors/mongodb/GetMongoIT.java +++ b/nifi-extension-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/test/java/org/apache/nifi/processors/mongodb/GetMongoIT.java @@ -50,6 +50,7 @@ import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertSame; import static org.junit.jupiter.api.Assertions.assertTrue; public class GetMongoIT extends AbstractMongoIT { @@ -181,7 +182,7 @@ public void testCleanJson() throws Exception { ObjectMapper mapper = new ObjectMapper(); Map parsed = mapper.readValue(raw, Map.class); - assertTrue(parsed.get("date_field").getClass() == String.class); + assertSame(parsed.get("date_field").getClass(), String.class); } @Test diff --git a/nifi-extension-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/test/java/org/apache/nifi/processors/mongodb/RunMongoAggregationIT.java b/nifi-extension-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/test/java/org/apache/nifi/processors/mongodb/RunMongoAggregationIT.java index e8738819cc40..eab684dcf461 100644 --- a/nifi-extension-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/test/java/org/apache/nifi/processors/mongodb/RunMongoAggregationIT.java +++ b/nifi-extension-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/test/java/org/apache/nifi/processors/mongodb/RunMongoAggregationIT.java @@ -202,7 +202,7 @@ public void testJsonTypes() throws IOException { for (MockFlowFile mockFlowFile : flowFiles) { byte[] raw = runner.getContentAsByteArray(mockFlowFile); Map> read = mapper.readValue(raw, Map.class); - assertTrue(read.get("myArray").get(1) == now.getTimeInMillis()); + assertEquals((long) read.get("myArray").get(1), now.getTimeInMillis()); } } diff --git a/nifi-extension-bundles/nifi-mongodb-bundle/nifi-mongodb-services/src/test/java/org/apache/nifi/mongodb/MongoDBLookupServiceIT.java b/nifi-extension-bundles/nifi-mongodb-bundle/nifi-mongodb-services/src/test/java/org/apache/nifi/mongodb/MongoDBLookupServiceIT.java index a95d22476366..fc1bed79d65a 100644 --- a/nifi-extension-bundles/nifi-mongodb-bundle/nifi-mongodb-services/src/test/java/org/apache/nifi/mongodb/MongoDBLookupServiceIT.java +++ b/nifi-extension-bundles/nifi-mongodb-bundle/nifi-mongodb-services/src/test/java/org/apache/nifi/mongodb/MongoDBLookupServiceIT.java @@ -45,6 +45,8 @@ import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -122,7 +124,7 @@ public void testLookupSingle() throws Exception { fail(); } - assertTrue(!result.isPresent()); + assertFalse(result.isPresent()); } @Test @@ -211,7 +213,7 @@ public void testLookupRecord() throws Exception { Optional result = service.lookup(criteria); assertNotNull(result.get(), "The value was null."); - assertTrue(result.get() instanceof MapRecord, "The value was wrong."); + assertInstanceOf(MapRecord.class, result.get(), "The value was wrong."); MapRecord record = (MapRecord) result.get(); RecordSchema subSchema = ((RecordDataType) record.getSchema().getField("subrecordField").get().getDataType()).getChildSchema(); @@ -238,7 +240,7 @@ public void testLookupRecord() throws Exception { fail(); } - assertTrue(!result.isPresent()); + assertFalse(result.isPresent()); } @Test diff --git a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestExecuteSQLRecord.java b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestExecuteSQLRecord.java index f4671b685b6e..ac650f5cd301 100644 --- a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestExecuteSQLRecord.java +++ b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestExecuteSQLRecord.java @@ -59,9 +59,9 @@ import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.mock; @@ -462,17 +462,17 @@ public void testWriteLOBsToAvro() throws Exception { Object imageObj = avroRecord.get("IMAGE"); assertNotNull(imageObj); - assertTrue(imageObj instanceof ByteBuffer); + assertInstanceOf(ByteBuffer.class, imageObj); assertArrayEquals(new byte[]{(byte) 0xDE, (byte) 0xAD, (byte) 0xBE, (byte) 0xEF}, ((ByteBuffer) imageObj).array()); Object wordsObj = avroRecord.get("WORDS"); assertNotNull(wordsObj); - assertTrue(wordsObj instanceof Utf8); + assertInstanceOf(Utf8.class, wordsObj); assertEquals("Hello World", wordsObj.toString()); Object natwordsObj = avroRecord.get("NATWORDS"); assertNotNull(natwordsObj); - assertTrue(natwordsObj instanceof Utf8); + assertInstanceOf(Utf8.class, natwordsObj); assertEquals("I am an NCLOB", natwordsObj.toString()); } diff --git a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestFetchFile.java b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestFetchFile.java index 79641d255ae0..05a0b5508e0c 100644 --- a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestFetchFile.java +++ b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestFetchFile.java @@ -28,8 +28,8 @@ import java.io.IOException; import java.nio.file.Files; import java.nio.file.StandardOpenOption; -import java.util.Arrays; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -250,7 +250,7 @@ public void testMoveAndReplace() throws IOException { runner.getFlowFilesForRelationship(FetchFile.REL_SUCCESS).get(0).assertContentEquals(content); final byte[] replacedContent = Files.readAllBytes(destFile.toPath()); - assertTrue(Arrays.equals(content, replacedContent)); + assertArrayEquals(content, replacedContent); assertFalse(sourceFile.exists()); assertTrue(destFile.exists()); } @@ -281,7 +281,7 @@ public void testMoveAndKeep() throws IOException { runner.getFlowFilesForRelationship(FetchFile.REL_SUCCESS).get(0).assertContentEquals(content); final byte[] replacedContent = Files.readAllBytes(destFile.toPath()); - assertTrue(Arrays.equals(goodBye, replacedContent)); + assertArrayEquals(goodBye, replacedContent); assertFalse(sourceFile.exists()); assertTrue(destFile.exists()); } @@ -311,7 +311,7 @@ public void testMoveAndFail() throws IOException { runner.assertAllFlowFilesTransferred(FetchFile.REL_FAILURE, 1); final byte[] replacedContent = Files.readAllBytes(destFile.toPath()); - assertTrue(Arrays.equals(goodBye, replacedContent)); + assertArrayEquals(goodBye, replacedContent); assertTrue(sourceFile.exists()); assertTrue(destFile.exists()); } @@ -342,7 +342,7 @@ public void testMoveAndRename() throws IOException { runner.assertAllFlowFilesTransferred(FetchFile.REL_SUCCESS, 1); final byte[] replacedContent = Files.readAllBytes(destFile.toPath()); - assertTrue(Arrays.equals(goodBye, replacedContent)); + assertArrayEquals(goodBye, replacedContent); assertFalse(sourceFile.exists()); assertTrue(destFile.exists()); diff --git a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestFlattenJson.java b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestFlattenJson.java index 1d3bc56842a6..c601818352a2 100644 --- a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestFlattenJson.java +++ b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestFlattenJson.java @@ -32,7 +32,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertInstanceOf; -import static org.junit.jupiter.api.Assertions.assertTrue; public class TestFlattenJson { private static final ObjectMapper mapper = new ObjectMapper(); @@ -86,7 +85,7 @@ void testFlattenRecordSet() throws JsonProcessingException { final List expected = Arrays.asList("Hello", "World"); final List parsed = (List) baseTest(testRunner, json, 2); - assertTrue(parsed instanceof List, "Not a list"); + assertInstanceOf(List.class, parsed, "Not a list"); for (int i = 0; i < parsed.size(); i++) { final Map map = (Map) parsed.get(i); assertEquals(map.get("first.second"), expected.get(i), "Missing values."); diff --git a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestGenerateRecord.java b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestGenerateRecord.java index cf3c46f26fed..35638332b733 100644 --- a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestGenerateRecord.java +++ b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestGenerateRecord.java @@ -25,6 +25,7 @@ import org.apache.nifi.processors.standard.faker.FakerUtils; import org.apache.nifi.serialization.RecordReader; import org.apache.nifi.serialization.record.MockRecordWriter; +import org.apache.nifi.serialization.record.Record; import org.apache.nifi.serialization.record.RecordField; import org.apache.nifi.serialization.record.RecordFieldType; import org.apache.nifi.serialization.record.RecordSchema; @@ -48,6 +49,7 @@ import java.util.stream.Collectors; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.fail; @@ -246,19 +248,19 @@ public void testGenerateNullableFieldsZeroNullPercentageSchemaText() throws Exce assertNotNull(record); final Object systemObject = record.getValue("System"); assertNotNull(systemObject); - assertTrue(systemObject instanceof org.apache.nifi.serialization.record.Record); + assertInstanceOf(Record.class, systemObject); final org.apache.nifi.serialization.record.Record systemRecord = (org.apache.nifi.serialization.record.Record) systemObject; final Object providerObject = systemRecord.getValue("Provider"); assertNotNull(providerObject); - assertTrue(providerObject instanceof org.apache.nifi.serialization.record.Record); + assertInstanceOf(Record.class, providerObject); final org.apache.nifi.serialization.record.Record providerRecord = (org.apache.nifi.serialization.record.Record) providerObject; final Object guidObject = providerRecord.getValue("Guid"); assertNotNull(guidObject); - assertTrue(guidObject instanceof Object[]); + assertInstanceOf(Object[].class, guidObject); // Check for array of Byte objects if not empty Object[] guidArray = (Object[]) guidObject; if (guidArray.length > 0) { - assertTrue(guidArray[0] instanceof Byte); + assertInstanceOf(Byte.class, guidArray[0]); } } diff --git a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestNotify.java b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestNotify.java index 6258f39dd0ef..384e5f377823 100644 --- a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestNotify.java +++ b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestNotify.java @@ -36,6 +36,7 @@ import java.util.concurrent.ConcurrentMap; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -304,7 +305,7 @@ public void testFailingCacheService() { props.put("releaseSignalAttribute", "2"); runner.enqueue(new byte[] {}, props); final AssertionError e = assertThrows(AssertionError.class, () -> runner.run()); - assertTrue(e.getCause() instanceof RuntimeException); + assertInstanceOf(RuntimeException.class, e.getCause()); service.setFailOnCalls(false); } diff --git a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestReplaceText.java b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestReplaceText.java index 50c8794f98a2..125bda88a1e2 100644 --- a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestReplaceText.java +++ b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestReplaceText.java @@ -850,7 +850,7 @@ public void testGetExistingContent() { runner.assertAllFlowFilesTransferred(ReplaceText.REL_SUCCESS, 1); final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0); final String outContent = new String(out.toByteArray(), StandardCharsets.UTF_8); - assertTrue(outContent.equals("attribute header\n\nabc.txt\n\ndata header\n\nHello\nWorld!\n\nfooter")); + assertEquals("attribute header\n\nabc.txt\n\ndata header\n\nHello\nWorld!\n\nfooter", outContent); } @Test diff --git a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestSplitRecord.java b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestSplitRecord.java index a3e4926bbfe3..1f026aa56298 100644 --- a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestSplitRecord.java +++ b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestSplitRecord.java @@ -33,6 +33,7 @@ import java.util.Optional; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertSame; import static org.junit.jupiter.api.Assertions.assertTrue; public class TestSplitRecord { @@ -193,7 +194,7 @@ public void testReadFailure() throws InitializationException { runner.assertAllFlowFilesTransferred(SplitRecord.REL_FAILURE, 1); final MockFlowFile failed = runner.getFlowFilesForRelationship(SplitRecord.REL_FAILURE).get(0); - assertTrue(original == failed); + assertSame(original, failed); final MockComponentLog logger = runner.getLogger(); final Optional logMessage = logger.getErrorMessages().stream() diff --git a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/enrichment/TestInsertRecordFieldsJoinStrategy.java b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/enrichment/TestInsertRecordFieldsJoinStrategy.java index 877760266328..edabb3f6eb70 100644 --- a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/enrichment/TestInsertRecordFieldsJoinStrategy.java +++ b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/enrichment/TestInsertRecordFieldsJoinStrategy.java @@ -37,6 +37,7 @@ import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -167,7 +168,7 @@ public void testRecordPathPointingToChildRecord() { assertEquals(555, combined.getAsInt("id")); final Object xyzValue = combined.getValue("xyz"); - assertTrue(xyzValue instanceof Record); + assertInstanceOf(Record.class, xyzValue); final Record xyzRecord = (Record) xyzValue; assertEquals("John Doe", xyzRecord.getValue("name")); diff --git a/nifi-extension-bundles/nifi-standard-services/nifi-dbcp-service-bundle/nifi-dbcp-service/src/test/java/org/apache/nifi/dbcp/TestDBCPConnectionPoolLookup.java b/nifi-extension-bundles/nifi-standard-services/nifi-dbcp-service-bundle/nifi-dbcp-service/src/test/java/org/apache/nifi/dbcp/TestDBCPConnectionPoolLookup.java index 7bd8416cb4b9..bda3bde955b0 100644 --- a/nifi-extension-bundles/nifi-standard-services/nifi-dbcp-service-bundle/nifi-dbcp-service/src/test/java/org/apache/nifi/dbcp/TestDBCPConnectionPoolLookup.java +++ b/nifi-extension-bundles/nifi-standard-services/nifi-dbcp-service-bundle/nifi-dbcp-service/src/test/java/org/apache/nifi/dbcp/TestDBCPConnectionPoolLookup.java @@ -33,9 +33,9 @@ import java.util.Map; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -88,7 +88,7 @@ public void testLookupServiceA() { final Connection connection = dbcpLookupService.getConnection(attributes); assertNotNull(connection); - assertTrue(connection instanceof MockConnection); + assertInstanceOf(MockConnection.class, connection); final MockConnection mockConnection = (MockConnection) connection; assertEquals(connectionA.getName(), mockConnection.getName()); @@ -101,7 +101,7 @@ public void testLookupServiceB() { final Connection connection = dbcpLookupService.getConnection(attributes); assertNotNull(connection); - assertTrue(connection instanceof MockConnection); + assertInstanceOf(MockConnection.class, connection); final MockConnection mockConnection = (MockConnection) connection; assertEquals(connectionB.getName(), mockConnection.getName()); diff --git a/nifi-extension-bundles/nifi-standard-services/nifi-dbcp-service-bundle/nifi-dbcp-service/src/test/java/org/apache/nifi/record/sink/db/DatabaseRecordSinkTest.java b/nifi-extension-bundles/nifi-standard-services/nifi-dbcp-service-bundle/nifi-dbcp-service/src/test/java/org/apache/nifi/record/sink/db/DatabaseRecordSinkTest.java index 239b0594b6d5..715e3c776492 100644 --- a/nifi-extension-bundles/nifi-standard-services/nifi-dbcp-service-bundle/nifi-dbcp-service/src/test/java/org/apache/nifi/record/sink/db/DatabaseRecordSinkTest.java +++ b/nifi-extension-bundles/nifi-standard-services/nifi-dbcp-service-bundle/nifi-dbcp-service/src/test/java/org/apache/nifi/record/sink/db/DatabaseRecordSinkTest.java @@ -82,6 +82,7 @@ import static org.apache.nifi.dbcp.utils.DBCPProperties.VALIDATION_QUERY; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -185,22 +186,22 @@ void testRecordFormat() throws IOException, InitializationException, SQLExceptio Object f1 = resultSet.getObject(1); assertNotNull(f1); - assertTrue(f1 instanceof Integer); + assertInstanceOf(Integer.class, f1); assertEquals(15, f1); Object f2 = resultSet.getObject(2); assertNotNull(f2); - assertTrue(f2 instanceof String); + assertInstanceOf(String.class, f2); assertEquals("Hello", f2); assertTrue(resultSet.next()); f1 = resultSet.getObject(1); assertNotNull(f1); - assertTrue(f1 instanceof Integer); + assertInstanceOf(Integer.class, f1); assertEquals(6, f1); f2 = resultSet.getObject(2); assertNotNull(f2); - assertTrue(f2 instanceof String); + assertInstanceOf(String.class, f2); assertEquals("World!", f2); assertFalse(resultSet.next()); diff --git a/nifi-extension-bundles/nifi-standard-services/nifi-record-serialization-services-bundle/nifi-record-serialization-services/src/test/java/org/apache/nifi/avro/TestWriteAvroResult.java b/nifi-extension-bundles/nifi-standard-services/nifi-record-serialization-services-bundle/nifi-record-serialization-services/src/test/java/org/apache/nifi/avro/TestWriteAvroResult.java index 6622bc5b63bd..3844774704fc 100644 --- a/nifi-extension-bundles/nifi-standard-services/nifi-record-serialization-services-bundle/nifi-record-serialization-services/src/test/java/org/apache/nifi/avro/TestWriteAvroResult.java +++ b/nifi-extension-bundles/nifi-standard-services/nifi-record-serialization-services-bundle/nifi-record-serialization-services/src/test/java/org/apache/nifi/avro/TestWriteAvroResult.java @@ -59,8 +59,8 @@ import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; public abstract class TestWriteAvroResult { @@ -342,8 +342,7 @@ protected void assertMatch(final Record record, final GenericRecord avroRecord) assertEquals(objectArray[i], bb.get()); } } else if (recordValue instanceof Object[]) { - assertTrue(avroValue instanceof Array, - fieldName + " should have been instanceof Array"); + assertInstanceOf(Array.class, avroValue, fieldName + " should have been instanceof Array"); final Array avroArray = (Array) avroValue; final Object[] recordArray = (Object[]) recordValue; assertEquals(recordArray.length, avroArray.size(), @@ -357,8 +356,7 @@ protected void assertMatch(final Record record, final GenericRecord avroRecord) assertEquals(bb, avroValue, fieldName + " not equal"); } else if (recordValue instanceof Map) { - assertTrue(avroValue instanceof Map, - fieldName + " should have been instanceof Map"); + assertInstanceOf(Map.class, avroValue, fieldName + " should have been instanceof Map"); final Map avroMap = (Map) avroValue; final Map recordMap = (Map) recordValue; assertEquals(recordMap.size(), avroMap.size(), diff --git a/nifi-extension-bundles/nifi-standard-services/nifi-record-serialization-services-bundle/nifi-record-serialization-services/src/test/java/org/apache/nifi/cef/TestCEFReader.java b/nifi-extension-bundles/nifi-standard-services/nifi-record-serialization-services-bundle/nifi-record-serialization-services/src/test/java/org/apache/nifi/cef/TestCEFReader.java index 240c68dd55f5..262fccc1d8d3 100644 --- a/nifi-extension-bundles/nifi-standard-services/nifi-record-serialization-services-bundle/nifi-record-serialization-services/src/test/java/org/apache/nifi/cef/TestCEFReader.java +++ b/nifi-extension-bundles/nifi-standard-services/nifi-record-serialization-services-bundle/nifi-record-serialization-services/src/test/java/org/apache/nifi/cef/TestCEFReader.java @@ -35,7 +35,6 @@ import org.apache.nifi.serialization.record.RecordField; import org.apache.nifi.util.TestRunner; import org.apache.nifi.util.TestRunners; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -51,6 +50,10 @@ import java.util.Map; import java.util.Set; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; +import static org.junit.jupiter.api.Assertions.assertThrows; + public class TestCEFReader { private TestRunner runner; private TestCEFProcessor processor; @@ -264,13 +267,13 @@ private void triggerProcessor(final String input) throws FileNotFoundException { private void triggerProcessorWithError(final String input) throws FileNotFoundException { runner.enqueue(new FileInputStream(input)); - final AssertionError exception = Assertions.assertThrows(AssertionError.class, () -> runner.run()); - Assertions.assertTrue(exception.getCause() instanceof RuntimeException); - Assertions.assertTrue(exception.getCause().getCause() instanceof IOException); + final AssertionError exception = assertThrows(AssertionError.class, () -> runner.run()); + assertInstanceOf(RuntimeException.class, exception.getCause()); + assertInstanceOf(IOException.class, exception.getCause().getCause()); } private void assertNumberOfResults(final int numberOfResults) { - Assertions.assertEquals(numberOfResults, processor.getRecords().size()); + assertEquals(numberOfResults, processor.getRecords().size()); } private void assertReaderIsInvalid() { @@ -278,7 +281,7 @@ private void assertReaderIsInvalid() { } private void assertFieldIsSet(final int number, final String name, final String value) { - Assertions.assertEquals(value, processor.getRecords().get(number).getValue(name)); + assertEquals(value, processor.getRecords().get(number).getValue(name)); } private void assertFieldsAre(final Map... fieldGroups) { diff --git a/nifi-extension-bundles/nifi-standard-services/nifi-record-serialization-services-bundle/nifi-record-serialization-services/src/test/java/org/apache/nifi/json/TestJsonPathRowRecordReader.java b/nifi-extension-bundles/nifi-standard-services/nifi-record-serialization-services-bundle/nifi-record-serialization-services/src/test/java/org/apache/nifi/json/TestJsonPathRowRecordReader.java index 479be941157e..99e7ee5634b0 100644 --- a/nifi-extension-bundles/nifi-standard-services/nifi-record-serialization-services-bundle/nifi-record-serialization-services/src/test/java/org/apache/nifi/json/TestJsonPathRowRecordReader.java +++ b/nifi-extension-bundles/nifi-standard-services/nifi-record-serialization-services-bundle/nifi-record-serialization-services/src/test/java/org/apache/nifi/json/TestJsonPathRowRecordReader.java @@ -34,6 +34,7 @@ import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; +import java.sql.Timestamp; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -43,6 +44,7 @@ import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -181,12 +183,10 @@ void testTimestampCoercedFromString() throws IOException, MalformedRecordExcepti final Record record = reader.nextRecord(coerceTypes, false); final Object value = record.getValue("timestamp"); - assertTrue(value instanceof java.sql.Timestamp, - "With coerceTypes set to " + coerceTypes + ", value is not a Timestamp"); + assertInstanceOf(Timestamp.class, value, "With coerceTypes set to " + coerceTypes + ", value is not a Timestamp"); final Object valueNotInSchema = record.getValue("field_not_in_schema"); - assertTrue(valueNotInSchema instanceof String, - "field_not_in_schema should be String"); + assertInstanceOf(String.class, valueNotInSchema, "field_not_in_schema should be String"); } } } @@ -220,7 +220,7 @@ void testElementWithNestedData() throws IOException, MalformedRecordException { assertArrayEquals(new Object[] {1, "John Doe", null, "123 My Street", "My City", "MS", "11111", "USA"}, simpleElements); final Object lastElement = firstRecordValues[firstRecordValues.length - 1]; - assertTrue(lastElement instanceof Record); + assertInstanceOf(Record.class, lastElement); final Record record = (Record) lastElement; assertEquals(42, record.getValue("id")); assertEquals(4750.89D, record.getValue("balance")); @@ -263,14 +263,14 @@ void testElementWithNestedArray() throws IOException, MalformedRecordException { final Object[] array = (Object[]) lastRecord; assertEquals(2, array.length); final Object firstElement = array[0]; - assertTrue(firstElement instanceof Record); + assertInstanceOf(Record.class, firstElement); final Record firstRecord = (Record) firstElement; assertEquals(42, firstRecord.getValue("id")); assertEquals(4750.89D, firstRecord.getValue("balance")); final Object secondElement = array[1]; - assertTrue(secondElement instanceof Record); + assertInstanceOf(Record.class, secondElement); final Record secondRecord = (Record) secondElement; assertEquals(43, secondRecord.getValue("id")); assertEquals(48212.38D, secondRecord.getValue("balance")); diff --git a/nifi-extension-bundles/nifi-standard-services/nifi-record-serialization-services-bundle/nifi-record-serialization-services/src/test/java/org/apache/nifi/windowsevent/TestWindowsEventLogRecordReader.java b/nifi-extension-bundles/nifi-standard-services/nifi-record-serialization-services-bundle/nifi-record-serialization-services/src/test/java/org/apache/nifi/windowsevent/TestWindowsEventLogRecordReader.java index 38d967fe5dc2..ad309660fcd8 100644 --- a/nifi-extension-bundles/nifi-standard-services/nifi-record-serialization-services-bundle/nifi-record-serialization-services/src/test/java/org/apache/nifi/windowsevent/TestWindowsEventLogRecordReader.java +++ b/nifi-extension-bundles/nifi-standard-services/nifi-record-serialization-services-bundle/nifi-record-serialization-services/src/test/java/org/apache/nifi/windowsevent/TestWindowsEventLogRecordReader.java @@ -31,10 +31,10 @@ import java.nio.charset.StandardCharsets; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.jupiter.api.Assertions.assertTrue; public class TestWindowsEventLogRecordReader { @@ -53,12 +53,12 @@ public void testSingleEvent() throws IOException, MalformedRecordException { // Verify some System fields Object childObj = r.getValue("System"); assertNotNull(childObj); - assertTrue(childObj instanceof Record); + assertInstanceOf(Record.class, childObj); Record childRecord = (Record) childObj; assertEquals(14, childRecord.getValues().length); childObj = childRecord.getValue("Provider"); assertNotNull(childObj); - assertTrue(childObj instanceof Record); + assertInstanceOf(Record.class, childObj); childRecord = (Record) childObj; assertEquals(2, childRecord.getValues().length); assertEquals("Microsoft-Windows-Security-Auditing", childRecord.getAsString("Name")); @@ -66,7 +66,7 @@ public void testSingleEvent() throws IOException, MalformedRecordException { // Verify some EventData fields, including Data fields childObj = r.getValue("EventData"); assertNotNull(childObj); - assertTrue(childObj instanceof Record); + assertInstanceOf(Record.class, childObj); childRecord = (Record) childObj; assertEquals(4, childRecord.getValues().length); assertEquals("DOMAIN", childRecord.getAsString("TargetDomainName")); @@ -85,12 +85,12 @@ public void testSingleEventNoParent() throws IOException, MalformedRecordExcepti // Verify some System fields Object childObj = r.getValue("System"); assertNotNull(childObj); - assertTrue(childObj instanceof Record); + assertInstanceOf(Record.class, childObj); Record childRecord = (Record) childObj; assertEquals(14, childRecord.getValues().length); childObj = childRecord.getValue("Provider"); assertNotNull(childObj); - assertTrue(childObj instanceof Record); + assertInstanceOf(Record.class, childObj); childRecord = (Record) childObj; assertEquals(2, childRecord.getValues().length); assertEquals("Microsoft-Windows-Security-Auditing", childRecord.getAsString("Name")); @@ -98,7 +98,7 @@ public void testSingleEventNoParent() throws IOException, MalformedRecordExcepti // Verify some EventData fields, including Data fields childObj = r.getValue("EventData"); assertNotNull(childObj); - assertTrue(childObj instanceof Record); + assertInstanceOf(Record.class, childObj); childRecord = (Record) childObj; assertEquals(4, childRecord.getValues().length); assertEquals("DOMAIN", childRecord.getAsString("TargetDomainName")); @@ -117,12 +117,12 @@ public void testMultipleEvents() throws IOException, MalformedRecordException { // Verify some System fields Object childObj = r.getValue("System"); assertNotNull(childObj); - assertTrue(childObj instanceof Record); + assertInstanceOf(Record.class, childObj); Record childRecord = (Record) childObj; assertEquals(14, childRecord.getValues().length); childObj = childRecord.getValue("Provider"); assertNotNull(childObj); - assertTrue(childObj instanceof Record); + assertInstanceOf(Record.class, childObj); childRecord = (Record) childObj; assertEquals(2, childRecord.getValues().length); assertEquals("Microsoft-Windows-Security-Auditing", childRecord.getAsString("Name")); @@ -130,7 +130,7 @@ public void testMultipleEvents() throws IOException, MalformedRecordException { // Verify some EventData fields, including Data fields childObj = r.getValue("EventData"); assertNotNull(childObj); - assertTrue(childObj instanceof Record); + assertInstanceOf(Record.class, childObj); childRecord = (Record) childObj; assertEquals(16, childRecord.getValues().length); assertEquals("DOMAIN", childRecord.getAsString("TargetDomainName")); @@ -142,12 +142,12 @@ public void testMultipleEvents() throws IOException, MalformedRecordException { assertEquals(2, r.getValues().length); childObj = r.getValue("System"); assertNotNull(childObj); - assertTrue(childObj instanceof Record); + assertInstanceOf(Record.class, childObj); childRecord = (Record) childObj; assertEquals(14, childRecord.getValues().length); childObj = childRecord.getValue("Provider"); assertNotNull(childObj); - assertTrue(childObj instanceof Record); + assertInstanceOf(Record.class, childObj); childRecord = (Record) childObj; assertEquals(2, childRecord.getValues().length); assertEquals("Microsoft-Windows-Security-Auditing", childRecord.getAsString("Name")); @@ -155,7 +155,7 @@ public void testMultipleEvents() throws IOException, MalformedRecordException { // Verify some EventData fields, including Data fields childObj = r.getValue("EventData"); assertNotNull(childObj); - assertTrue(childObj instanceof Record); + assertInstanceOf(Record.class, childObj); childRecord = (Record) childObj; assertEquals(16, childRecord.getValues().length); assertEquals("DOMAIN", childRecord.getAsString("TargetDomainName")); @@ -167,12 +167,12 @@ public void testMultipleEvents() throws IOException, MalformedRecordException { assertEquals(2, r.getValues().length); childObj = r.getValue("System"); assertNotNull(childObj); - assertTrue(childObj instanceof Record); + assertInstanceOf(Record.class, childObj); childRecord = (Record) childObj; assertEquals(14, childRecord.getValues().length); childObj = childRecord.getValue("Provider"); assertNotNull(childObj); - assertTrue(childObj instanceof Record); + assertInstanceOf(Record.class, childObj); childRecord = (Record) childObj; assertEquals(2, childRecord.getValues().length); assertEquals("Microsoft-Windows-Security-Auditing", childRecord.getAsString("Name")); @@ -180,7 +180,7 @@ public void testMultipleEvents() throws IOException, MalformedRecordException { // Verify some EventData fields, including Data fields childObj = r.getValue("EventData"); assertNotNull(childObj); - assertTrue(childObj instanceof Record); + assertInstanceOf(Record.class, childObj); childRecord = (Record) childObj; assertEquals(16, childRecord.getValues().length); assertNull(childRecord.getAsString("TargetDomainName")); diff --git a/nifi-extension-bundles/nifi-standard-services/nifi-record-serialization-services-bundle/nifi-record-serialization-services/src/test/java/org/apache/nifi/xml/TestInferXmlSchema.java b/nifi-extension-bundles/nifi-standard-services/nifi-record-serialization-services-bundle/nifi-record-serialization-services/src/test/java/org/apache/nifi/xml/TestInferXmlSchema.java index e45b9fb8f82f..a140b179b618 100644 --- a/nifi-extension-bundles/nifi-standard-services/nifi-record-serialization-services-bundle/nifi-record-serialization-services/src/test/java/org/apache/nifi/xml/TestInferXmlSchema.java +++ b/nifi-extension-bundles/nifi-standard-services/nifi-record-serialization-services-bundle/nifi-record-serialization-services/src/test/java/org/apache/nifi/xml/TestInferXmlSchema.java @@ -39,8 +39,8 @@ import java.util.Collections; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; import static org.junit.jupiter.api.Assertions.assertSame; -import static org.junit.jupiter.api.Assertions.assertTrue; public class TestInferXmlSchema { @@ -103,7 +103,7 @@ public void testStringFieldWithAttributes() throws IOException { final DataType softwareDataType = schema.getDataType("software").get(); assertSame(RecordFieldType.RECORD, softwareDataType.getFieldType()); - assertTrue(softwareDataType instanceof RecordDataType); + assertInstanceOf(RecordDataType.class, softwareDataType); final RecordSchema childSchema = ((RecordDataType) softwareDataType).getChildSchema(); assertSame(RecordFieldType.BOOLEAN, childSchema.getDataType("favorite").get().getFieldType()); diff --git a/nifi-extension-bundles/nifi-standard-services/nifi-record-serialization-services-bundle/nifi-record-serialization-services/src/test/java/org/apache/nifi/yaml/TestYamlTreeRowRecordReader.java b/nifi-extension-bundles/nifi-standard-services/nifi-record-serialization-services-bundle/nifi-record-serialization-services/src/test/java/org/apache/nifi/yaml/TestYamlTreeRowRecordReader.java index 31dd370b93f4..4b42ff75e6b0 100644 --- a/nifi-extension-bundles/nifi-standard-services/nifi-record-serialization-services-bundle/nifi-record-serialization-services/src/test/java/org/apache/nifi/yaml/TestYamlTreeRowRecordReader.java +++ b/nifi-extension-bundles/nifi-standard-services/nifi-record-serialization-services-bundle/nifi-record-serialization-services/src/test/java/org/apache/nifi/yaml/TestYamlTreeRowRecordReader.java @@ -49,6 +49,8 @@ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; +import java.sql.Date; +import java.sql.Timestamp; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -62,6 +64,7 @@ import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; import static org.junit.jupiter.api.Assertions.assertNotEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; @@ -117,16 +120,16 @@ void testReadChoiceOfStringOrArrayOfRecords() throws IOException, MalformedRecor assertEquals(2, fieldsArray.length); final Object firstElement = fieldsArray[0]; - assertTrue(firstElement instanceof Record); + assertInstanceOf(Record.class, firstElement); assertEquals("string", ((Record) firstElement).getAsString("type")); final Object secondElement = fieldsArray[1]; - assertTrue(secondElement instanceof Record); + assertInstanceOf(Record.class, secondElement); final Object[] typeArray = ((Record) secondElement).getAsArray("type"); assertEquals(1, typeArray.length); final Object firstType = typeArray[0]; - assertTrue(firstType instanceof Record); + assertInstanceOf(Record.class, firstType); final Record firstTypeRecord = (Record) firstType; assertEquals("string", firstTypeRecord.getAsString("type")); } @@ -155,7 +158,7 @@ void testChoiceOfRecordTypes() throws IOException, MalformedRecordException { // child record should have a schema with "id" as the only field final Object childObject = firstRecord.getValue("child"); - assertTrue(childObject instanceof Record); + assertInstanceOf(Record.class, childObject); final Record firstChildRecord = (Record) childObject; final RecordSchema firstChildSchema = firstChildRecord.getSchema(); @@ -177,7 +180,7 @@ void testChoiceOfRecordTypes() throws IOException, MalformedRecordException { // child record should have a schema with "name" as the only field final Object secondChildObject = secondRecord.getValue("child"); - assertTrue(secondChildObject instanceof Record); + assertInstanceOf(Record.class, secondChildObject); final Record secondChildRecord = (Record) secondChildObject; final RecordSchema secondChildSchema = secondChildRecord.getSchema(); @@ -343,7 +346,7 @@ void testDateCoercedFromString() throws IOException, MalformedRecordException { final Record record = reader.nextRecord(coerceTypes, false); final Object value = record.getValue(dateField); - assertTrue(value instanceof java.sql.Date, "With coerceTypes set to " + coerceTypes + ", value is not a Date"); + assertInstanceOf(Date.class, value, "With coerceTypes set to " + coerceTypes + ", value is not a Date"); assertEquals(date, value.toString()); } } @@ -360,7 +363,7 @@ void testTimestampCoercedFromString() throws IOException, MalformedRecordExcepti final Record record = reader.nextRecord(coerceTypes, false); final Object value = record.getValue("timestamp"); - assertTrue(value instanceof java.sql.Timestamp, "With coerceTypes set to " + coerceTypes + ", value is not a Timestamp"); + assertInstanceOf(Timestamp.class, value, "With coerceTypes set to " + coerceTypes + ", value is not a Timestamp"); } } } @@ -406,7 +409,7 @@ void testSingleJsonElementWithChoiceFields() throws IOException, MalformedRecord RecordFieldType.DOUBLE, RecordFieldType.STRING, RecordFieldType.STRING, RecordFieldType.STRING, RecordFieldType.STRING, RecordFieldType.STRING); final List fields = schema.getFields(); for (int i = 0; i < schema.getFields().size(); i++) { - assertTrue(fields.get(i).getDataType() instanceof ChoiceDataType); + assertInstanceOf(ChoiceDataType.class, fields.get(i).getDataType()); final ChoiceDataType choiceDataType = (ChoiceDataType) fields.get(i).getDataType(); assertEquals(expectedTypes.get(i), choiceDataType.getPossibleSubTypes().get(0).getFieldType()); } @@ -562,7 +565,7 @@ void testReadUnicodeCharacters() throws IOException, MalformedRecordException { final Object[] firstRecordValues = reader.nextRecord().getValues(); final Object secondValue = firstRecordValues[1]; - assertTrue(secondValue instanceof Long); + assertInstanceOf(Long.class, secondValue); assertEquals(832036744985577473L, secondValue); final Object unicodeValue = firstRecordValues[2]; diff --git a/nifi-framework-bundle/nifi-framework/nifi-authorizer/src/test/java/org/apache/nifi/authorization/AuthorizerFactoryTest.java b/nifi-framework-bundle/nifi-framework/nifi-authorizer/src/test/java/org/apache/nifi/authorization/AuthorizerFactoryTest.java index 888a3842b94d..e3d52beea790 100644 --- a/nifi-framework-bundle/nifi-framework/nifi-authorizer/src/test/java/org/apache/nifi/authorization/AuthorizerFactoryTest.java +++ b/nifi-framework-bundle/nifi-framework/nifi-authorizer/src/test/java/org/apache/nifi/authorization/AuthorizerFactoryTest.java @@ -25,7 +25,9 @@ import java.util.LinkedHashSet; import java.util.Set; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -263,7 +265,7 @@ public void testAuditInvoked() { Authorizer authorizer = AuthorizerFactory.installIntegrityChecks(mockAuthorizer); authorizer.onConfigured(context); - assertTrue(authorizer instanceof AuthorizationAuditor); + assertInstanceOf(AuthorizationAuditor.class, authorizer); final AuthorizationRequest accessAttempt = new AuthorizationRequest.Builder() .resource(new MockResource("resource1", "Resource 1")) @@ -275,7 +277,7 @@ public void testAuditInvoked() { final AuthorizationResult accessAttemptResult = authorizer.authorize(accessAttempt); - assertTrue(Result.Approved.equals(accessAttemptResult.getResult())); + assertEquals(Result.Approved, accessAttemptResult.getResult()); assertTrue(mockAuthorizer.isAudited(accessAttempt)); final AuthorizationRequest nonAccessAttempt = new AuthorizationRequest.Builder() @@ -288,7 +290,7 @@ public void testAuditInvoked() { final AuthorizationResult nonAccessAttempResult = authorizer.authorize(nonAccessAttempt); - assertTrue(Result.Approved.equals(nonAccessAttempResult.getResult())); + assertEquals(Result.Approved, nonAccessAttempResult.getResult()); assertFalse(mockAuthorizer.isAudited(nonAccessAttempt)); } diff --git a/nifi-framework-bundle/nifi-framework/nifi-framework-authorization-providers/src/test/java/org/apache/nifi/authorization/StandardManagedAuthorizerTest.java b/nifi-framework-bundle/nifi-framework/nifi-framework-authorization-providers/src/test/java/org/apache/nifi/authorization/StandardManagedAuthorizerTest.java index d3a68558813d..83c18e766acf 100644 --- a/nifi-framework-bundle/nifi-framework/nifi-framework-authorization-providers/src/test/java/org/apache/nifi/authorization/StandardManagedAuthorizerTest.java +++ b/nifi-framework-bundle/nifi-framework/nifi-framework-authorization-providers/src/test/java/org/apache/nifi/authorization/StandardManagedAuthorizerTest.java @@ -29,7 +29,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; @@ -479,7 +478,7 @@ public Set getGroups() { .build(); final StandardManagedAuthorizer managedAuthorizer = getStandardManagedAuthorizer(accessPolicyProvider); - assertTrue(AuthorizationResult.denied().getResult().equals(managedAuthorizer.authorize(request).getResult())); + assertEquals(AuthorizationResult.denied().getResult(), managedAuthorizer.authorize(request).getResult()); } @Test @@ -525,7 +524,7 @@ public Set getGroups() { .build(); final StandardManagedAuthorizer managedAuthorizer = getStandardManagedAuthorizer(accessPolicyProvider); - assertTrue(AuthorizationResult.denied().getResult().equals(managedAuthorizer.authorize(request).getResult())); + assertEquals(AuthorizationResult.denied().getResult(), managedAuthorizer.authorize(request).getResult()); } private StandardManagedAuthorizer getStandardManagedAuthorizer(final AccessPolicyProvider accessPolicyProvider) { diff --git a/nifi-framework-bundle/nifi-framework/nifi-framework-cluster-protocol/src/test/java/org/apache/nifi/cluster/protocol/jaxb/message/TestJaxbProtocolUtils.java b/nifi-framework-bundle/nifi-framework/nifi-framework-cluster-protocol/src/test/java/org/apache/nifi/cluster/protocol/jaxb/message/TestJaxbProtocolUtils.java index fa3da9ad4e11..b7730718782d 100644 --- a/nifi-framework-bundle/nifi-framework/nifi-framework-cluster-protocol/src/test/java/org/apache/nifi/cluster/protocol/jaxb/message/TestJaxbProtocolUtils.java +++ b/nifi-framework-bundle/nifi-framework/nifi-framework-cluster-protocol/src/test/java/org/apache/nifi/cluster/protocol/jaxb/message/TestJaxbProtocolUtils.java @@ -48,6 +48,7 @@ import java.util.stream.IntStream; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; import static org.junit.jupiter.api.Assertions.assertTrue; public class TestJaxbProtocolUtils { @@ -73,7 +74,7 @@ public void testRoundTripConnectionResponse() throws JAXBException { JaxbProtocolUtils.JAXB_CONTEXT.createMarshaller().marshal(msg, baos); final Object unmarshalled = JaxbProtocolUtils.JAXB_CONTEXT.createUnmarshaller().unmarshal(new ByteArrayInputStream(baos.toByteArray())); - assertTrue(unmarshalled instanceof ConnectionResponseMessage); + assertInstanceOf(ConnectionResponseMessage.class, unmarshalled); final ComponentRevisionSnapshot receivedSnapshot = msg.getConnectionResponse().getComponentRevisions(); final List revisions = receivedSnapshot.getComponentRevisions(); @@ -94,7 +95,7 @@ public void testRoundTripConnectionStatusRequest() throws JAXBException { JaxbProtocolUtils.JAXB_CONTEXT.createMarshaller().marshal(msg, baos); final Object unmarshalled = JaxbProtocolUtils.JAXB_CONTEXT.createUnmarshaller().unmarshal(new ByteArrayInputStream(baos.toByteArray())); - assertTrue(unmarshalled instanceof NodeConnectionStatusRequestMessage); + assertInstanceOf(NodeConnectionStatusRequestMessage.class, unmarshalled); } @@ -109,7 +110,7 @@ public void testRoundTripConnectionStatusResponse() throws JAXBException { JaxbProtocolUtils.JAXB_CONTEXT.createMarshaller().marshal(msg, baos); final Object unmarshalled = JaxbProtocolUtils.JAXB_CONTEXT.createUnmarshaller().unmarshal(new ByteArrayInputStream(baos.toByteArray())); - assertTrue(unmarshalled instanceof NodeConnectionStatusResponseMessage); + assertInstanceOf(NodeConnectionStatusResponseMessage.class, unmarshalled); final NodeConnectionStatusResponseMessage unmarshalledMsg = (NodeConnectionStatusResponseMessage) unmarshalled; final NodeConnectionStatus unmarshalledStatus = unmarshalledMsg.getNodeConnectionStatus(); @@ -138,7 +139,7 @@ public void testRoundTripHeartbeat() throws JAXBException { final ByteArrayOutputStream baos = new ByteArrayOutputStream(); JaxbProtocolUtils.JAXB_CONTEXT.createMarshaller().marshal(msg, baos); final Object unmarshalled = JaxbProtocolUtils.JAXB_CONTEXT.createUnmarshaller().unmarshal(new ByteArrayInputStream(baos.toByteArray())); - assertTrue(unmarshalled instanceof HeartbeatMessage); + assertInstanceOf(HeartbeatMessage.class, unmarshalled); } @Test @@ -147,7 +148,7 @@ public void testRoundTripClusterWorkloadRequest() throws JAXBException { final ByteArrayOutputStream baos = new ByteArrayOutputStream(); JaxbProtocolUtils.JAXB_CONTEXT.createMarshaller().marshal(msg, baos); final Object unmarshalled = JaxbProtocolUtils.JAXB_CONTEXT.createUnmarshaller().unmarshal(new ByteArrayInputStream(baos.toByteArray())); - assertTrue(unmarshalled instanceof ClusterWorkloadRequestMessage); + assertInstanceOf(ClusterWorkloadRequestMessage.class, unmarshalled); } @Test @@ -174,7 +175,7 @@ public void testRoundTripClusterWorkloadResponse() throws JAXBException { // Un-marshall. final Object unmarshalled = JaxbProtocolUtils.JAXB_CONTEXT.createUnmarshaller().unmarshal(new ByteArrayInputStream(baos.toByteArray())); - assertTrue(unmarshalled instanceof ClusterWorkloadResponseMessage); + assertInstanceOf(ClusterWorkloadResponseMessage.class, unmarshalled); // Assert result. final ClusterWorkloadResponseMessage response = (ClusterWorkloadResponseMessage) unmarshalled; diff --git a/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/coordination/node/TestNodeClusterCoordinator.java b/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/coordination/node/TestNodeClusterCoordinator.java index 68a4b1f9f983..dd5b6fde6a03 100644 --- a/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/coordination/node/TestNodeClusterCoordinator.java +++ b/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/coordination/node/TestNodeClusterCoordinator.java @@ -45,7 +45,6 @@ import java.io.IOException; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; @@ -55,7 +54,9 @@ import java.util.concurrent.atomic.AtomicReference; import java.util.stream.Collectors; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertThrows; @@ -121,7 +122,7 @@ public void testConnectionResponseIndicatesAllNodes() { final NodeIdentifier requestedNodeId = createNodeId(6); final ProtocolMessage protocolResponse = requestConnection(requestedNodeId, coordinator); assertNotNull(protocolResponse); - assertTrue(protocolResponse instanceof ConnectionResponseMessage); + assertInstanceOf(ConnectionResponseMessage.class, protocolResponse); final ConnectionResponse response = ((ConnectionResponseMessage) protocolResponse).getConnectionResponse(); assertNotNull(response); @@ -166,7 +167,7 @@ void notifyOthersOfNodeStatusChange(NodeConnectionStatus updatedStatus, boolean final ProtocolMessage protocolResponse = coordinator.handle(requestMsg, Collections.emptySet()); assertNotNull(protocolResponse); - assertTrue(protocolResponse instanceof ConnectionResponseMessage); + assertInstanceOf(ConnectionResponseMessage.class, protocolResponse); final ConnectionResponse response = ((ConnectionResponseMessage) protocolResponse).getConnectionResponse(); assertNotNull(response); @@ -214,8 +215,8 @@ void notifyOthersOfNodeStatusChange(NodeConnectionStatus updatedStatus, boolean final StandardDataFlow df = msg.getDataFlow(); assertNotNull(df); - assertTrue(Arrays.equals(dataFlow.getFlow(), df.getFlow())); - assertTrue(Arrays.equals(dataFlow.getSnippets(), df.getSnippets())); + assertArrayEquals(dataFlow.getFlow(), df.getFlow()); + assertArrayEquals(dataFlow.getSnippets(), df.getSnippets()); } @Test @@ -429,7 +430,7 @@ public void testProposedIdentifierResolvedIfConflict() { final ProtocolMessage response = coordinator.handle(crm, Collections.emptySet()); assertNotNull(response); - assertTrue(response instanceof ConnectionResponseMessage); + assertInstanceOf(ConnectionResponseMessage.class, response); final ConnectionResponseMessage responseMessage = (ConnectionResponseMessage) response; final NodeIdentifier resolvedNodeId = responseMessage.getConnectionResponse().getNodeIdentifier(); assertEquals(id1, resolvedNodeId); @@ -440,7 +441,7 @@ public void testProposedIdentifierResolvedIfConflict() { final ProtocolMessage conflictingResponse = coordinator.handle(crm2, Collections.emptySet()); assertNotNull(conflictingResponse); - assertTrue(conflictingResponse instanceof ConnectionResponseMessage); + assertInstanceOf(ConnectionResponseMessage.class, conflictingResponse); final ConnectionResponseMessage conflictingResponseMessage = (ConnectionResponseMessage) conflictingResponse; final NodeIdentifier conflictingNodeId = conflictingResponseMessage.getConnectionResponse().getNodeIdentifier(); assertEquals(id1.getId(), conflictingNodeId.getId()); @@ -463,7 +464,7 @@ public void testAddNodeIdentifierWithSameAddressDifferentLoadBalanceEndpoint() { final ProtocolMessage response = coordinator.handle(crm, Collections.emptySet()); assertNotNull(response); - assertTrue(response instanceof ConnectionResponseMessage); + assertInstanceOf(ConnectionResponseMessage.class, response); final ConnectionResponseMessage responseMessage = (ConnectionResponseMessage) response; final NodeIdentifier resolvedNodeId = responseMessage.getConnectionResponse().getNodeIdentifier(); assertEquals(id1, resolvedNodeId); @@ -476,7 +477,7 @@ public void testAddNodeIdentifierWithSameAddressDifferentLoadBalanceEndpoint() { final ProtocolMessage conflictingResponse = coordinator.handle(crm2, Collections.emptySet()); assertNotNull(conflictingResponse); - assertTrue(conflictingResponse instanceof ConnectionResponseMessage); + assertInstanceOf(ConnectionResponseMessage.class, conflictingResponse); final ConnectionResponseMessage conflictingResponseMessage = (ConnectionResponseMessage) conflictingResponse; final NodeIdentifier conflictingNodeId = conflictingResponseMessage.getConnectionResponse().getNodeIdentifier(); assertEquals(id1.getId(), conflictingNodeId.getId()); diff --git a/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/test/java/org/apache/nifi/controller/service/TestStandardControllerServiceInvocationHandler.java b/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/test/java/org/apache/nifi/controller/service/TestStandardControllerServiceInvocationHandler.java index 77614ecd24fd..57cdf2fc41b6 100644 --- a/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/test/java/org/apache/nifi/controller/service/TestStandardControllerServiceInvocationHandler.java +++ b/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/test/java/org/apache/nifi/controller/service/TestStandardControllerServiceInvocationHandler.java @@ -31,6 +31,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -155,7 +156,7 @@ public void assertNotProxied() { BaseControllerService nextLevel = getNextLevel(); for (int i = 0; i < 5; i++) { assertEquals(level + i + 1, nextLevel.getLevel()); - assertTrue(nextLevel instanceof TestService); + assertInstanceOf(TestService.class, nextLevel); assertFalse(Proxy.isProxyClass(nextLevel.getClass())); nextLevel = nextLevel.getNextLevel(); @@ -164,7 +165,7 @@ public void assertNotProxied() { @Override public void assertNotProxied(final BaseControllerService service) { - assertTrue(service instanceof TestService); + assertInstanceOf(TestService.class, service); assertFalse(Proxy.isProxyClass(service.getClass())); } } diff --git a/nifi-framework-bundle/nifi-framework/nifi-nar-utils/src/test/java/org/apache/nifi/nar/LoadNativeLibAspectTest.java b/nifi-framework-bundle/nifi-framework/nifi-nar-utils/src/test/java/org/apache/nifi/nar/LoadNativeLibAspectTest.java index 0a9e6d87808a..20cbdda0017b 100644 --- a/nifi-framework-bundle/nifi-framework/nifi-nar-utils/src/test/java/org/apache/nifi/nar/LoadNativeLibAspectTest.java +++ b/nifi-framework-bundle/nifi-framework/nifi-nar-utils/src/test/java/org/apache/nifi/nar/LoadNativeLibAspectTest.java @@ -27,6 +27,7 @@ import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Mockito.mock; @@ -107,7 +108,7 @@ public void testWhenNativeLibraryFileExistsThenCreateATempCopyAndProceedWithThat assertNotNull(args); assertEquals(1, args.length); assertNotNull(args[0]); - assertTrue(args[0] instanceof String); + assertInstanceOf(String.class, args[0]); String tempLibFilePathStr = (String) args[0]; Path tempLibFilePath = Paths.get(tempLibFilePathStr); diff --git a/nifi-framework-bundle/nifi-framework/nifi-site-to-site/src/test/java/org/apache/nifi/remote/protocol/http/TestHttpFlowFileServerProtocol.java b/nifi-framework-bundle/nifi-framework/nifi-site-to-site/src/test/java/org/apache/nifi/remote/protocol/http/TestHttpFlowFileServerProtocol.java index 356cd4265cb0..5ef549eebfbb 100644 --- a/nifi-framework-bundle/nifi-framework/nifi-site-to-site/src/test/java/org/apache/nifi/remote/protocol/http/TestHttpFlowFileServerProtocol.java +++ b/nifi-framework-bundle/nifi-framework/nifi-site-to-site/src/test/java/org/apache/nifi/remote/protocol/http/TestHttpFlowFileServerProtocol.java @@ -70,6 +70,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.any; @@ -223,7 +224,7 @@ public void testShutdown() throws Exception { assertTrue(serverProtocol.isHandshakeSuccessful()); final FlowFileCodec negotiatedCoded = serverProtocol.negotiateCodec(peer); - assertTrue(negotiatedCoded instanceof StandardFlowFileCodec); + assertInstanceOf(StandardFlowFileCodec.class, negotiatedCoded); assertEquals(negotiatedCoded, serverProtocol.getPreNegotiatedCodec()); assertEquals(1234, serverProtocol.getRequestExpiration()); diff --git a/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/test/java/org/apache/nifi/authorization/StandardAuthorizableLookupTest.java b/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/test/java/org/apache/nifi/authorization/StandardAuthorizableLookupTest.java index 5576cdec0334..319b4aab6ec2 100644 --- a/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/test/java/org/apache/nifi/authorization/StandardAuthorizableLookupTest.java +++ b/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/test/java/org/apache/nifi/authorization/StandardAuthorizableLookupTest.java @@ -29,7 +29,7 @@ import org.apache.nifi.web.dao.ProcessorDAO; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -52,26 +52,26 @@ public void testGetAuthorizableFromResource() { lookup.setControllerFacade(controllerFacade); Authorizable authorizable = lookup.getAuthorizableFromResource("/processors/id"); - assertTrue(authorizable instanceof ProcessorNode); + assertInstanceOf(ProcessorNode.class, authorizable); authorizable = lookup.getAuthorizableFromResource("/policies/processors/id"); - assertTrue(authorizable instanceof AccessPolicyAuthorizable); - assertTrue(((AccessPolicyAuthorizable) authorizable).getBaseAuthorizable() instanceof ProcessorNode); + assertInstanceOf(AccessPolicyAuthorizable.class, authorizable); + assertInstanceOf(ProcessorNode.class, ((AccessPolicyAuthorizable) authorizable).getBaseAuthorizable()); authorizable = lookup.getAuthorizableFromResource("/data/processors/id"); - assertTrue(authorizable instanceof DataAuthorizable); - assertTrue(((DataAuthorizable) authorizable).getBaseAuthorizable() instanceof ProcessorNode); + assertInstanceOf(DataAuthorizable.class, authorizable); + assertInstanceOf(ProcessorNode.class, ((DataAuthorizable) authorizable).getBaseAuthorizable()); authorizable = lookup.getAuthorizableFromResource("/data-transfer/processors/id"); - assertTrue(authorizable instanceof DataTransferAuthorizable); - assertTrue(((DataTransferAuthorizable) authorizable).getBaseAuthorizable() instanceof ProcessorNode); + assertInstanceOf(DataTransferAuthorizable.class, authorizable); + assertInstanceOf(ProcessorNode.class, ((DataTransferAuthorizable) authorizable).getBaseAuthorizable()); authorizable = lookup.getAuthorizableFromResource("/provenance-data/processors/id"); - assertTrue(authorizable instanceof ProvenanceDataAuthorizable); - assertTrue(((ProvenanceDataAuthorizable) authorizable).getBaseAuthorizable() instanceof ProcessorNode); + assertInstanceOf(ProvenanceDataAuthorizable.class, authorizable); + assertInstanceOf(ProcessorNode.class, ((ProvenanceDataAuthorizable) authorizable).getBaseAuthorizable()); authorizable = lookup.getAuthorizableFromResource("/operation/processors/id"); - assertTrue(authorizable instanceof OperationAuthorizable); - assertTrue(((OperationAuthorizable) authorizable).getBaseAuthorizable() instanceof ProcessorNode); + assertInstanceOf(OperationAuthorizable.class, authorizable); + assertInstanceOf(ProcessorNode.class, ((OperationAuthorizable) authorizable).getBaseAuthorizable()); } } diff --git a/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/test/java/org/apache/nifi/web/api/TestDataTransferResource.java b/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/test/java/org/apache/nifi/web/api/TestDataTransferResource.java index af1eec32259e..ce4dfb17d775 100644 --- a/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/test/java/org/apache/nifi/web/api/TestDataTransferResource.java +++ b/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/test/java/org/apache/nifi/web/api/TestDataTransferResource.java @@ -48,7 +48,7 @@ import java.net.URL; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.doAnswer; @@ -344,7 +344,7 @@ public void testTransferFlowFiles() { final Object entity = response.getEntity(); assertEquals(202, response.getStatus()); - assertTrue(entity instanceof StreamingOutput); + assertInstanceOf(StreamingOutput.class, entity); } @Test diff --git a/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/test/java/org/apache/nifi/web/api/TestFlowResource.java b/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/test/java/org/apache/nifi/web/api/TestFlowResource.java index f7e0a45dbf3c..e447f6b81ed2 100644 --- a/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/test/java/org/apache/nifi/web/api/TestFlowResource.java +++ b/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/test/java/org/apache/nifi/web/api/TestFlowResource.java @@ -65,6 +65,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -307,7 +308,7 @@ public void testGetVersionDifferencesWithoutLimitations() { SAMPLE_REGISTRY_ID, SAMPLE_BRANCH_ID_A, SAMPLE_BUCKET_ID_A, SAMPLE_FLOW_ID_A, "1", SAMPLE_BRANCH_ID_B, SAMPLE_BUCKET_ID_B, SAMPLE_FLOW_ID_B, "2", 0, 0); assertNotNull(response); assertEquals(MediaType.valueOf(MediaType.APPLICATION_JSON), response.getMediaType()); - assertTrue(FlowComparisonEntity.class.isInstance(response.getEntity())); + assertInstanceOf(FlowComparisonEntity.class, response.getEntity()); final FlowComparisonEntity entity = (FlowComparisonEntity) response.getEntity(); final List differences = entity.getComponentDifferences().stream().map(ComponentDifferenceDTO::getDifferences).flatMap(Collection::stream).collect(Collectors.toList()); @@ -324,7 +325,7 @@ public void testGetVersionDifferencesFromBeginningWithPartialResults() { assertNotNull(response); assertEquals(MediaType.valueOf(MediaType.APPLICATION_JSON), response.getMediaType()); - assertTrue(FlowComparisonEntity.class.isInstance(response.getEntity())); + assertInstanceOf(FlowComparisonEntity.class, response.getEntity()); final FlowComparisonEntity entity = (FlowComparisonEntity) response.getEntity(); final List differences = entity.getComponentDifferences().stream().map(ComponentDifferenceDTO::getDifferences).flatMap(Collection::stream).collect(Collectors.toList()); @@ -343,7 +344,7 @@ public void testGetVersionDifferencesFromBeginningExtendedWithPartialResults() { assertNotNull(response); assertEquals(MediaType.valueOf(MediaType.APPLICATION_JSON), response.getMediaType()); - assertTrue(FlowComparisonEntity.class.isInstance(response.getEntity())); + assertInstanceOf(FlowComparisonEntity.class, response.getEntity()); final FlowComparisonEntity entity = (FlowComparisonEntity) response.getEntity(); final List differences = entity.getComponentDifferences().stream().map(ComponentDifferenceDTO::getDifferences).flatMap(Collection::stream).collect(Collectors.toList()); @@ -363,7 +364,7 @@ public void testGetVersionDifferencesWithOffsetAndPartialResults() { assertNotNull(response); assertEquals(MediaType.valueOf(MediaType.APPLICATION_JSON), response.getMediaType()); - assertTrue(FlowComparisonEntity.class.isInstance(response.getEntity())); + assertInstanceOf(FlowComparisonEntity.class, response.getEntity()); final FlowComparisonEntity entity = (FlowComparisonEntity) response.getEntity(); final List differences = entity.getComponentDifferences().stream().map(ComponentDifferenceDTO::getDifferences).flatMap(Collection::stream).collect(Collectors.toList()); @@ -383,7 +384,7 @@ public void testGetVersionDifferencesWithOffsetAndOnlyPartialResult() { assertNotNull(response); assertEquals(MediaType.valueOf(MediaType.APPLICATION_JSON), response.getMediaType()); - assertTrue(FlowComparisonEntity.class.isInstance(response.getEntity())); + assertInstanceOf(FlowComparisonEntity.class, response.getEntity()); final FlowComparisonEntity entity = (FlowComparisonEntity) response.getEntity(); final List differences = entity.getComponentDifferences().stream().map(ComponentDifferenceDTO::getDifferences).flatMap(Collection::stream).collect(Collectors.toList()); diff --git a/nifi-registry/nifi-registry-core/nifi-registry-framework/src/test/java/org/apache/nifi/registry/serialization/TestFlowContentSerializer.java b/nifi-registry/nifi-registry-core/nifi-registry-framework/src/test/java/org/apache/nifi/registry/serialization/TestFlowContentSerializer.java index 9ad2f8ee9943..a53ba13f43dd 100644 --- a/nifi-registry/nifi-registry-core/nifi-registry-framework/src/test/java/org/apache/nifi/registry/serialization/TestFlowContentSerializer.java +++ b/nifi-registry/nifi-registry-core/nifi-registry-framework/src/test/java/org/apache/nifi/registry/serialization/TestFlowContentSerializer.java @@ -70,7 +70,7 @@ public void testSerializeDeserializeFlowContent() { // make sure we can read the version from the input stream and it should be the current version final Integer version = serializer.readDataModelVersion(in); assertEquals(serializer.getCurrentDataModelVersion(), version); - assertEquals(false, serializer.isProcessGroupVersion(version)); + assertFalse(serializer.isProcessGroupVersion(version)); // make sure we can deserialize back to FlowContent final FlowContent deserializedFlowContent = serializer.deserializeFlowContent(version, in); diff --git a/nifi-registry/nifi-registry-core/nifi-registry-framework/src/test/java/org/apache/nifi/registry/service/TestRegistryService.java b/nifi-registry/nifi-registry-core/nifi-registry-framework/src/test/java/org/apache/nifi/registry/service/TestRegistryService.java index 7cbd856d473c..0635c671c432 100644 --- a/nifi-registry/nifi-registry-core/nifi-registry-framework/src/test/java/org/apache/nifi/registry/service/TestRegistryService.java +++ b/nifi-registry/nifi-registry-core/nifi-registry-framework/src/test/java/org/apache/nifi/registry/service/TestRegistryService.java @@ -1359,7 +1359,7 @@ public void testGetDiffReturnsRemovedComponentChanges() { .filter(p -> p.getComponentId().equals("ID-pg1")).findFirst(); assertTrue(removedComponent.isPresent()); - assertTrue(removedComponent.get().getDifferences().iterator().next().getDifferenceType().equals("COMPONENT_REMOVED")); + assertEquals("COMPONENT_REMOVED", removedComponent.get().getDifferences().iterator().next().getDifferenceType()); } @Test diff --git a/nifi-registry/nifi-registry-core/nifi-registry-web-api/src/test/java/org/apache/nifi/registry/web/api/BucketsIT.java b/nifi-registry/nifi-registry-core/nifi-registry-web-api/src/test/java/org/apache/nifi/registry/web/api/BucketsIT.java index 1ecf2c9c9cbf..d22f0b1a9aaf 100644 --- a/nifi-registry/nifi-registry-core/nifi-registry-web-api/src/test/java/org/apache/nifi/registry/web/api/BucketsIT.java +++ b/nifi-registry/nifi-registry-core/nifi-registry-web-api/src/test/java/org/apache/nifi/registry/web/api/BucketsIT.java @@ -31,6 +31,7 @@ import static org.apache.nifi.registry.web.api.IntegrationTestUtils.assertBucketsEqual; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -93,7 +94,7 @@ public void testGetBuckets() throws Exception { // Then: the pre-populated list of buckets is returned JSONAssert.assertEquals(expected, bucketsJson, false); - assertTrue(!bucketsJson.contains("null")); // JSON serialization from the server should not include null fields, such as "versionedFlows": null + assertFalse(bucketsJson.contains("null")); // JSON serialization from the server should not include null fields, such as "versionedFlows": null } @Test diff --git a/nifi-registry/nifi-registry-core/nifi-registry-web-api/src/test/java/org/apache/nifi/registry/web/api/SecureNiFiRegistryClientIT.java b/nifi-registry/nifi-registry-core/nifi-registry-web-api/src/test/java/org/apache/nifi/registry/web/api/SecureNiFiRegistryClientIT.java index 430f0a5e7ee9..431f6bbab53d 100644 --- a/nifi-registry/nifi-registry-core/nifi-registry-web-api/src/test/java/org/apache/nifi/registry/web/api/SecureNiFiRegistryClientIT.java +++ b/nifi-registry/nifi-registry-core/nifi-registry-web-api/src/test/java/org/apache/nifi/registry/web/api/SecureNiFiRegistryClientIT.java @@ -46,8 +46,8 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.fail; @ExtendWith(SpringExtension.class) @@ -134,35 +134,35 @@ public void testDirectFlowAccess() throws IOException { proxiedFlowClient.get("1"); fail("Shouldn't have been able to retrieve flow"); } catch (NiFiRegistryException e) { - assertTrue(e.getCause() instanceof ForbiddenException); + assertInstanceOf(ForbiddenException.class, e.getCause()); } try { proxiedFlowSnapshotClient.getLatest("1"); fail("Shouldn't have been able to retrieve flow"); } catch (NiFiRegistryException e) { - assertTrue(e.getCause() instanceof ForbiddenException); + assertInstanceOf(ForbiddenException.class, e.getCause()); } try { proxiedFlowSnapshotClient.getLatestMetadata("1"); fail("Shouldn't have been able to retrieve flow"); } catch (NiFiRegistryException e) { - assertTrue(e.getCause() instanceof ForbiddenException); + assertInstanceOf(ForbiddenException.class, e.getCause()); } try { proxiedFlowSnapshotClient.get("1", 1); fail("Shouldn't have been able to retrieve flow"); } catch (NiFiRegistryException e) { - assertTrue(e.getCause() instanceof ForbiddenException); + assertInstanceOf(ForbiddenException.class, e.getCause()); } try { proxiedFlowSnapshotClient.getSnapshotMetadata("1"); fail("Shouldn't have been able to retrieve flow"); } catch (NiFiRegistryException e) { - assertTrue(e.getCause() instanceof ForbiddenException); + assertInstanceOf(ForbiddenException.class, e.getCause()); } } diff --git a/nifi-system-tests/nifi-stateless-system-test-suite/src/test/java/org/apache/nifi/stateless/basics/RollbackOnExceptionIT.java b/nifi-system-tests/nifi-stateless-system-test-suite/src/test/java/org/apache/nifi/stateless/basics/RollbackOnExceptionIT.java index 8105d8a3b89b..59fc9d700415 100644 --- a/nifi-system-tests/nifi-stateless-system-test-suite/src/test/java/org/apache/nifi/stateless/basics/RollbackOnExceptionIT.java +++ b/nifi-system-tests/nifi-stateless-system-test-suite/src/test/java/org/apache/nifi/stateless/basics/RollbackOnExceptionIT.java @@ -33,7 +33,7 @@ import java.util.Collections; import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; public class RollbackOnExceptionIT extends StatelessSystemIT { private static final String EXCEPTION_TEXT = "Intentional Exception to verify behavior in RollbackOnExceptionIT"; @@ -54,7 +54,7 @@ public void testFlowFileCompletelyRemovedWhenExceptionThrown() throws IOExceptio final DataflowTrigger trigger = dataflow.trigger(); final TriggerResult result = trigger.getResult(); assertFalse(result.isSuccessful()); - assertTrue(result.getFailureCause().get() instanceof ProcessException); + assertInstanceOf(ProcessException.class, result.getFailureCause().get()); // Wait for dataflow to be purged while (dataflow.isFlowFileQueued()) { @@ -79,7 +79,7 @@ public void testFlowFileCompletelyRemovedWhenTransferredToFailurePort() throws I final DataflowTrigger trigger = dataflow.trigger(); final TriggerResult result = trigger.getResult(); assertFalse(result.isSuccessful()); - assertTrue(result.getFailureCause().get() instanceof FailurePortEncounteredException); + assertInstanceOf(FailurePortEncounteredException.class, result.getFailureCause().get()); assertFalse(dataflow.isFlowFileQueued()); } diff --git a/pmd-ruleset.xml b/pmd-ruleset.xml index 116f149709a9..e263ae1518cc 100644 --- a/pmd-ruleset.xml +++ b/pmd-ruleset.xml @@ -36,6 +36,7 @@ under the License. +