Skip to content

Commit

Permalink
NIFI-11035 Replaced remaining JUnit 4 assertions in nifi-commons with…
Browse files Browse the repository at this point in the history
… JUnit 5

- Replaced Groovy asserts with JUnit 5 assertions and Groovy shouldFail method Junit 5 with assertThrow method

This closes apache#6880

Signed-off-by: David Handermann <[email protected]>
  • Loading branch information
dan-s1 authored and exceptionfactory committed Jan 24, 2023
1 parent 84f48b5 commit 5337184
Show file tree
Hide file tree
Showing 44 changed files with 935 additions and 1,113 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ import org.junit.jupiter.api.Test
import org.slf4j.Logger
import org.slf4j.LoggerFactory

class QueryGroovyTest extends GroovyTestCase {
import static org.junit.jupiter.api.Assertions.assertEquals
import static org.junit.jupiter.api.Assertions.assertNotEquals

class QueryGroovyTest {
private static final Logger logger = LoggerFactory.getLogger(QueryGroovyTest.class)

@BeforeAll
Expand Down Expand Up @@ -79,11 +82,11 @@ class QueryGroovyTest extends GroovyTestCase {
logger.info("Replace repeating result: ${replaceRepeatingResult.value}")

// Assert
assert replaceSingleResult.value == EXPECTED_SINGLE_RESULT
assert replaceSingleResult.resultType == AttributeExpression.ResultType.STRING
assertEquals(EXPECTED_SINGLE_RESULT, replaceSingleResult.value)
assertEquals(AttributeExpression.ResultType.STRING, replaceSingleResult.resultType)

assert replaceRepeatingResult.value == EXPECTED_REPEATING_RESULT
assert replaceRepeatingResult.resultType == AttributeExpression.ResultType.STRING
assertEquals(EXPECTED_REPEATING_RESULT, replaceRepeatingResult.value)
assertEquals(AttributeExpression.ResultType.STRING, replaceRepeatingResult.resultType)
}

@Test
Expand Down Expand Up @@ -119,11 +122,11 @@ class QueryGroovyTest extends GroovyTestCase {
logger.info("Replace repeating result: ${replaceRepeatingResult.value}")

// Assert
assert replaceSingleResult.value == EXPECTED_SINGLE_RESULT
assert replaceSingleResult.resultType == AttributeExpression.ResultType.STRING
assertEquals(EXPECTED_SINGLE_RESULT, replaceSingleResult.value)
assertEquals(AttributeExpression.ResultType.STRING, replaceSingleResult.resultType)

assert replaceRepeatingResult.value == EXPECTED_REPEATING_RESULT
assert replaceRepeatingResult.resultType == AttributeExpression.ResultType.STRING
assertEquals(EXPECTED_REPEATING_RESULT, replaceRepeatingResult.value)
assertEquals(AttributeExpression.ResultType.STRING, replaceRepeatingResult.resultType)
}

@Test
Expand Down Expand Up @@ -159,11 +162,11 @@ class QueryGroovyTest extends GroovyTestCase {
logger.info("Replace repeating result: ${replaceRepeatingResult.value}")

// Assert
assert replaceSingleResult.value == EXPECTED_SINGLE_RESULT
assert replaceSingleResult.resultType == AttributeExpression.ResultType.STRING
assertEquals(EXPECTED_SINGLE_RESULT, replaceSingleResult.value)
assertEquals(AttributeExpression.ResultType.STRING, replaceSingleResult.resultType)

assert replaceRepeatingResult.value == EXPECTED_REPEATING_RESULT
assert replaceRepeatingResult.resultType == AttributeExpression.ResultType.STRING
assertEquals(EXPECTED_REPEATING_RESULT, replaceRepeatingResult.value)
assertEquals(AttributeExpression.ResultType.STRING, replaceRepeatingResult.resultType)
}

@Test
Expand Down Expand Up @@ -200,10 +203,10 @@ class QueryGroovyTest extends GroovyTestCase {
logger.info("Replace repeating result: ${replaceFirstRepeatingResult}")

// Assert
assert replaceSingleResult != EXPECTED_SINGLE_RESULT
assert replaceRepeatingResult != EXPECTED_REPEATING_RESULT
assertNotEquals(EXPECTED_SINGLE_RESULT, replaceSingleResult)
assertNotEquals(EXPECTED_REPEATING_RESULT, replaceRepeatingResult)

assert replaceFirstSingleResult == EXPECTED_SINGLE_RESULT
assert replaceFirstRepeatingResult == EXPECTED_REPEATING_RESULT
assertEquals(EXPECTED_SINGLE_RESULT, replaceFirstSingleResult)
assertEquals(EXPECTED_REPEATING_RESULT, replaceFirstRepeatingResult)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
import java.util.HashMap;
import java.util.Map;

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

public class TestValueLookup {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.Arrays;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;

public class TestPackageUnpackageV3 {

Expand All @@ -35,7 +35,7 @@ public void test() throws IOException {
final FlowFilePackager packager = new FlowFilePackagerV3();
final FlowFileUnpackager unpackager = new FlowFileUnpackagerV3();

final byte[] data = "Hello, World!".getBytes("UTF-8");
final byte[] data = "Hello, World!".getBytes(StandardCharsets.UTF_8);
final Map<String, String> map = new HashMap<>();
map.put("abc", "cba");

Expand All @@ -50,7 +50,7 @@ public void test() throws IOException {
final byte[] decoded = decodedOut.toByteArray();

assertEquals(map, unpackagedAttributes);
assertTrue(Arrays.equals(data, decoded));
assertArrayEquals(data, decoded);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,14 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

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

@SuppressWarnings("resource")
public class TestHL7Query {
Expand All @@ -60,7 +59,7 @@ public class TestHL7Query {
private HL7Message hypoglycemia;

@BeforeEach
public void init() throws IOException, HL7Exception {
public void init() throws HL7Exception {
this.hyperglycemia = createMessage(HYPERGLYCEMIA);
this.hypoglycemia = createMessage(HYPOGLYCEMIA);
}
Expand Down Expand Up @@ -116,7 +115,7 @@ private void verifyAssignments(final Map<String, Object> map, final String a, fi
}

@Test
public void testSelectMessage() throws HL7Exception, IOException {
public void testSelectMessage() {
final HL7Query query = HL7Query.compile("SELECT MESSAGE");
final HL7Message msg = hypoglycemia;
final QueryResult result = query.evaluate(msg);
Expand All @@ -131,7 +130,7 @@ public void testSelectMessage() throws HL7Exception, IOException {

@Test
@SuppressWarnings({"unchecked", "rawtypes"})
public void testSelectField() throws HL7Exception, IOException {
public void testSelectField() {
final HL7Query query = HL7Query.compile("SELECT PID.5");
final HL7Message msg = hypoglycemia;
final QueryResult result = query.evaluate(msg);
Expand All @@ -149,7 +148,7 @@ public void testSelectField() throws HL7Exception, IOException {
}

@Test
public void testSelectAbnormalTestResult() throws HL7Exception, IOException {
public void testSelectAbnormalTestResult() {
final String query = "DECLARE result AS REQUIRED OBX SELECT result WHERE result.7 != 'N' AND result.1 = 1";

final HL7Query hl7Query = HL7Query.compile(query);
Expand All @@ -158,7 +157,7 @@ public void testSelectAbnormalTestResult() throws HL7Exception, IOException {
}

@Test
public void testFieldEqualsString() throws HL7Exception, IOException {
public void testFieldEqualsString() {
HL7Query hl7Query = HL7Query.compile("DECLARE result AS REQUIRED OBX SELECT MESSAGE WHERE result.7 = 'L'");
QueryResult result = hl7Query.evaluate(hypoglycemia);
assertTrue(result.isMatch());
Expand All @@ -169,7 +168,7 @@ public void testFieldEqualsString() throws HL7Exception, IOException {
}

@Test
public void testLessThan() throws HL7Exception, IOException {
public void testLessThan() {
HL7Query hl7Query = HL7Query.compile("DECLARE result AS REQUIRED OBX SELECT MESSAGE WHERE result.4 < 600");
QueryResult result = hl7Query.evaluate(hypoglycemia);
assertTrue(result.isMatch());
Expand All @@ -180,7 +179,7 @@ public void testLessThan() throws HL7Exception, IOException {
}

@Test
public void testCompareTwoFields() throws HL7Exception, IOException {
public void testCompareTwoFields() {
HL7Query hl7Query = HL7Query.compile("DECLARE result AS REQUIRED OBX SELECT MESSAGE WHERE result.4 < result.6.2");
QueryResult result = hl7Query.evaluate(hypoglycemia);
assertTrue(result.isMatch());
Expand All @@ -191,7 +190,7 @@ public void testCompareTwoFields() throws HL7Exception, IOException {
}

@Test
public void testLessThanOrEqual() throws HL7Exception, IOException {
public void testLessThanOrEqual() {
HL7Query hl7Query = HL7Query.compile("DECLARE result AS REQUIRED OBX SELECT MESSAGE WHERE result.4 <= 59");
QueryResult result = hl7Query.evaluate(hypoglycemia);
assertTrue(result.isMatch());
Expand All @@ -206,7 +205,7 @@ public void testLessThanOrEqual() throws HL7Exception, IOException {
}

@Test
public void testGreaterThanOrEqual() throws HL7Exception, IOException {
public void testGreaterThanOrEqual() {
HL7Query hl7Query = HL7Query.compile("DECLARE result AS REQUIRED OBX SELECT MESSAGE WHERE result.4 >= 59");
QueryResult result = hl7Query.evaluate(hypoglycemia);
assertTrue(result.isMatch());
Expand All @@ -221,7 +220,7 @@ public void testGreaterThanOrEqual() throws HL7Exception, IOException {
}

@Test
public void testGreaterThan() throws HL7Exception, IOException {
public void testGreaterThan() {
HL7Query hl7Query = HL7Query.compile("DECLARE result AS REQUIRED OBX SELECT MESSAGE WHERE result.4 > 58");
QueryResult result = hl7Query.evaluate(hypoglycemia);
assertTrue(result.isMatch());
Expand All @@ -236,15 +235,15 @@ public void testGreaterThan() throws HL7Exception, IOException {
}

@Test
public void testDistinctValuesReturned() throws HL7Exception, IOException {
public void testDistinctValuesReturned() {
HL7Query hl7Query = HL7Query.compile("DECLARE result1 AS REQUIRED OBX, result2 AS REQUIRED OBX SELECT MESSAGE WHERE result1.7 = 'L' OR result2.7 != 'H'");
QueryResult result = hl7Query.evaluate(hypoglycemia);
assertTrue(result.isMatch());
assertEquals(1, result.getHitCount());
}

@Test
public void testAndWithParents() throws HL7Exception, IOException {
public void testAndWithParents() {
HL7Query hl7Query = HL7Query.compile("DECLARE result AS REQUIRED OBX SELECT MESSAGE WHERE result.7 = 'L' AND result.3.1 = 'GLU'");
QueryResult result = hl7Query.evaluate(hypoglycemia);
assertTrue(result.isMatch());
Expand Down Expand Up @@ -276,7 +275,7 @@ public void testAndWithParents() throws HL7Exception, IOException {
}

@Test
public void testIsNull() throws HL7Exception, IOException {
public void testIsNull() {
HL7Query hl7Query = HL7Query.compile("DECLARE result AS REQUIRED OBX SELECT MESSAGE WHERE result.999 IS NULL");
QueryResult result = hl7Query.evaluate(hypoglycemia);
assertTrue(result.isMatch());
Expand All @@ -295,7 +294,7 @@ public void testIsNull() throws HL7Exception, IOException {
}

@Test
public void testNotNull() throws HL7Exception, IOException {
public void testNotNull() {
HL7Query hl7Query = HL7Query.compile("DECLARE result AS REQUIRED OBX SELECT MESSAGE WHERE result.999 NOT NULL");
QueryResult result = hl7Query.evaluate(hypoglycemia);
assertFalse(result.isMatch());
Expand All @@ -313,7 +312,7 @@ public void testNotNull() throws HL7Exception, IOException {
assertTrue(result.isMatch());
}

private HL7Message createMessage(final String msgText) throws HL7Exception, IOException {
private HL7Message createMessage(final String msgText) throws HL7Exception {
final HapiContext hapiContext = new DefaultHapiContext();
hapiContext.setValidationContext(ValidationContextFactory.noValidation());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ import org.junit.jupiter.api.Test

import static groovy.json.JsonOutput.prettyPrint
import static groovy.json.JsonOutput.toJson
import static org.junit.Assert.assertFalse
import static org.junit.Assert.assertTrue
import static org.junit.jupiter.api.Assertions.assertFalse
import static org.junit.jupiter.api.Assertions.assertTrue
import static org.mockito.Mockito.mock

class TestStandardValidators {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertThrows;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;

public class KeyedCipherPropertyEncryptorTest {
private static final Charset DEFAULT_CHARSET = StandardCharsets.UTF_8;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertThrows;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;

public class PasswordBasedCipherPropertyEncryptorTest {
private static final Charset DEFAULT_CHARSET = StandardCharsets.UTF_8;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@

import java.util.Properties;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThrows;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;

public class PropertyEncryptorFactoryTest {
private static final EncryptionMethod ENCRYPTION_METHOD = EncryptionMethod.MD5_256AES;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@

import javax.crypto.SecretKey;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThrows;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;

public class StandardPropertySecretKeyProviderTest {
private static final String SEED = String.class.getName();
Expand All @@ -42,7 +42,7 @@ public void testPropertyEncryptionMethodSupported() {
final SecretKey secretKey = provider.getSecretKey(propertyEncryptionMethod, SEED);
final int secretKeyLength = secretKey.getEncoded().length;
final String message = String.format("Method [%s] Key Length not matched", propertyEncryptionMethod);
assertEquals(message, propertyEncryptionMethod.getHashLength(), secretKeyLength);
assertEquals(propertyEncryptionMethod.getHashLength(), secretKeyLength, message);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import java.util.List;
import java.util.Map;

import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;

/**
* Abstract base class for tests that walk FieldValue hierarchies.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
import java.util.List;
import java.util.stream.Collectors;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThrows;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;

public class TestFieldValueLogicalPathBuilder extends AbstractWalkerTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import java.util.List;
import java.util.stream.Collectors;

import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;

public class TestFieldValueWalker extends AbstractWalkerTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import java.util.List;
import java.util.Set;

import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.assertThrows;

public class TestSimpleRecordSchema {
Expand Down
Loading

0 comments on commit 5337184

Please sign in to comment.