org.junit.jupiter.params.converter.ConvertWith Java Examples

The following examples show how to use org.junit.jupiter.params.converter.ConvertWith. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EntityRecordItemListenerTopicTest.java    From hedera-mirror-node with Apache License 2.0 6 votes vote down vote up
@ParameterizedTest
@CsvSource({
        "0.0.65537, 10, 20, admin-key, submit-key, '', 1000000, 1, 30",
        "0.0.2147483647, 9223372036854775807, 2147483647, admin-key, '', memo, 1000001, 1, 30",
        "0.0.1, -9223372036854775808, -2147483648, '', '', memo, 1000002, , ,",
        "0.0.55, 10, 20, admin-key, submit-key, memo, 1000003, 1, 30"
})
void createTopicTest(@ConvertWith(TopicIdConverter.class) TopicID topicId, long expirationTimeSeconds,
                     int expirationTimeNanos, @ConvertWith(KeyConverter.class) Key adminKey,
                     @ConvertWith(KeyConverter.class) Key submitKey, String memo, long consensusTimestamp,
                     Long autoRenewAccountNum, Long autoRenewPeriod) throws Exception {
    var responseCode = ResponseCodeEnum.SUCCESS;
    var transaction = createCreateTopicTransaction(adminKey, submitKey, memo, autoRenewAccountNum, autoRenewPeriod);
    var transactionRecord = createTransactionRecord(topicId, consensusTimestamp, responseCode);

    parseRecordItemAndCommit(new RecordItem(transaction, transactionRecord));

    long entityCount = autoRenewAccountNum != null ? 4 : 3; // Node, payer, topic & optionally autorenew
    var entity = getTopicEntity(topicId);
    assertTransactionInRepository(responseCode, consensusTimestamp, entity.getId());
    assertEquals(entityCount, entityRepository.count());
    var expectedEntity = createTopicEntity(topicId, null, null, adminKey, submitKey, memo, autoRenewAccountNum,
            autoRenewPeriod);
    assertThat(entity).isEqualTo(expectedEntity);
}
 
Example #2
Source File: JavaVersionTest.java    From keystore-explorer with GNU General Public License v3.0 6 votes vote down vote up
@ParameterizedTest
@CsvSource({
	"JRE_VERSION_160, JRE_VERSION_170, true",
	"JRE_VERSION_170, JRE_VERSION_180, true",
	"JRE_VERSION_180, JRE_VERSION_9,   true",
	"JRE_VERSION_9,   JRE_VERSION_180, false",
	"JRE_VERSION_170, JRE_VERSION_160, false",
	"JRE_VERSION_170, JRE_VERSION_170, false",
	"JRE_VERSION_180, JRE_VERSION_160, false",
	"JRE_VERSION_180, JRE_VERSION_170, false",
	"JRE_VERSION_180, JRE_VERSION_180, false",
})
public void isBelow(@ConvertWith(JavaVersionConstantArgumentConverter.class) JavaVersion version1,
		@ConvertWith(JavaVersionConstantArgumentConverter.class) JavaVersion version2, boolean result) {
	assertEquals(version1.isBelow(version2), result);
}
 
Example #3
Source File: UtilityTest.java    From hedera-mirror-node with Apache License 2.0 6 votes vote down vote up
@ParameterizedTest(name = "verifyHashChain {5}")
@CsvSource({
        // @formatter:off
        "'', '', 1970-01-01T00:00:00Z,        2000-01-01T10_00_00.000000Z.rcd, true,  passes if both hashes are empty",
        "xx, '', 1970-01-01T00:00:00Z,        2000-01-01T10_00_00.000000Z.rcd, true,  passes if hash mismatch and expected hash is empty", // starting stream in middle
        "'', xx, 1970-01-01T00:00:00Z,        2000-01-01T10_00_00.000000Z.rcd, false, fails if hash mismatch and actual hash is empty", // bad db state
        "xx, yy, 1970-01-01T00:00:00Z,        2000-01-01T10_00_00.000000Z.rcd, false, fails if hash mismatch and hashes are non-empty",
        "xx, yy, 2000-01-01T10:00:00.000001Z, 2000-01-01T10_00_00.000000Z.rcd, true,  passes if hash mismatch but verifyHashAfter is after filename",
        "xx, yy, 2000-01-01T10:00:00.000001Z, 2000-01-01T10_00_00.000000Z.rcd, true,  passes if hash mismatch but verifyHashAfter is same as filename",
        "xx, yy, 2000-01-01T09:59:59.999999Z, 2000-01-01T10_00_00.000000Z.rcd, false, fails if hash mismatch and verifyHashAfter is before filename",
        "xx, xx, 1970-01-01T00:00:00Z,        2000-01-01T10_00_00.000000Z.rcd, true,  passes if hashes are equal"
        // @formatter:on
})
public void testVerifyHashChain(String actualPrevFileHash, String expectedPrevFileHash,
                                @ConvertWith(InstantConverter.class) Instant verifyHashAfter, String fileName,
                                Boolean expectedResult, String testName) {
    assertThat(Utility.verifyHashChain(actualPrevFileHash, expectedPrevFileHash, verifyHashAfter, fileName))
            .isEqualTo(expectedResult);
}
 
Example #4
Source File: JavaVersionTest.java    From keystore-explorer with GNU General Public License v3.0 6 votes vote down vote up
@ParameterizedTest
@CsvSource({
	"JRE_VERSION_160, 1.6.0_45,  0",
	"JRE_VERSION_170, 1.6.0_45,  1",
	"JRE_VERSION_170, 1.7.0_101, 0",
	"JRE_VERSION_180, 1.7.0_101, 1",
	"JRE_VERSION_180, 1.8.0_20,  0",
	"JRE_VERSION_170, 1.8.0_20, -1",
	"JRE_VERSION_160, 1.8.0_20, -1",
	"JRE_VERSION_9,   1.8.0_20,  1",
	"JRE_VERSION_9,   9.0.0,     0",
	"JRE_VERSION_9,   9.0.1,    -1",
	"JRE_VERSION_9,   10.0.1,   -1",
	"JRE_VERSION_10,  9.0.1,     1",
	"JRE_VERSION_10,  10.0.0,    0",
	"JRE_VERSION_10,  10.0.1,   -1",
	"JRE_VERSION_10,  11.0.1,   -1",
	"JRE_VERSION_11,  10.0.1,    1",
	"JRE_VERSION_11,  11.0.0,    0",
	"JRE_VERSION_11,  11.0.1,   -1",
})
public void compareTo(@ConvertWith(JavaVersionConstantArgumentConverter.class) JavaVersion verConst, String verStr,
		int result) {
	assertEquals(Integer.signum(verConst.compareTo(new JavaVersion(verStr))), result);
}
 
Example #5
Source File: EntityRecordItemListenerTopicTest.java    From hedera-mirror-node with Apache License 2.0 5 votes vote down vote up
@ParameterizedTest
@CsvSource({
        "0.0.1300, 10, 20, admin-key, submit-key, memo, 11, 21, updated-admin-key, updated-submit-key, " +
                "updated-memo, 4000000, 1, 30",
        "0.0.1301, 10, 20, admin-key, submit-key, memo, 11, 21, '', '', '', 4000001, 1, 30",
        "0.0.1302, 0, 0, '', '', '', 11, 21, updated-admin-key, updated-submit-key, updated-memo, 4000002, ,"
})
void updateTopicTest(@ConvertWith(TopicIdConverter.class) TopicID topicId, long expirationTimeSeconds,
                     int expirationTimeNanos, @ConvertWith(KeyConverter.class) Key adminKey,
                     @ConvertWith(KeyConverter.class) Key submitKey, String memo,
                     long updatedExpirationTimeSeconds, int updatedExpirationTimeNanos,
                     @ConvertWith(KeyConverter.class) Key updatedAdminKey,
                     @ConvertWith(KeyConverter.class) Key updatedSubmitKey,
                     String updatedMemo, long consensusTimestamp, Long autoRenewAccountId, Long autoRenewPeriod) {
    // Store topic to be updated.
    var topic = createTopicEntity(topicId, expirationTimeSeconds, expirationTimeNanos, adminKey, submitKey, memo,
            autoRenewAccountId, autoRenewPeriod);
    entityRepository.save(topic);

    var responseCode = ResponseCodeEnum.SUCCESS;
    var transaction = createUpdateTopicTransaction(topicId, updatedExpirationTimeSeconds,
            updatedExpirationTimeNanos, updatedAdminKey, updatedSubmitKey, updatedMemo, autoRenewAccountId,
            autoRenewPeriod);
    var transactionRecord = createTransactionRecord(topicId, consensusTimestamp, responseCode);
    var expectedEntity = createTopicEntity(topicId, updatedExpirationTimeSeconds, updatedExpirationTimeNanos,
            updatedAdminKey, updatedSubmitKey, updatedMemo, autoRenewAccountId, autoRenewPeriod);

    parseRecordItemAndCommit(new RecordItem(transaction, transactionRecord));

    long entityCount = autoRenewAccountId != null ? 4 : 3; // Node, payer, topic & optionally autorenew
    var entity = getTopicEntity(topicId);
    assertTransactionInRepository(responseCode, consensusTimestamp, entity.getId());
    assertEquals(entityCount, entityRepository.count());
    assertThat(entity).isEqualTo(expectedEntity);
}
 
Example #6
Source File: JavaVersionTest.java    From keystore-explorer with GNU General Public License v3.0 5 votes vote down vote up
@ParameterizedTest
@CsvSource({
	"JRE_VERSION_9,   JRE_VERSION_160, true",
	"JRE_VERSION_9,   JRE_VERSION_170, true",
	"JRE_VERSION_9,   JRE_VERSION_180, true",
	"JRE_VERSION_9,   JRE_VERSION_9,   true",
	"JRE_VERSION_10,  JRE_VERSION_160, true",
	"JRE_VERSION_10,  JRE_VERSION_170, true",
	"JRE_VERSION_10,  JRE_VERSION_180, true",
	"JRE_VERSION_10,  JRE_VERSION_9,   true",
	"JRE_VERSION_180, JRE_VERSION_160, true",
	"JRE_VERSION_180, JRE_VERSION_170, true",
	"JRE_VERSION_180, JRE_VERSION_180, true",
	"JRE_VERSION_170, JRE_VERSION_160, true",
	"JRE_VERSION_170, JRE_VERSION_170, true",
	"JRE_VERSION_180, JRE_VERSION_9,   false",
	"JRE_VERSION_170, JRE_VERSION_180, false",
	"JRE_VERSION_170, JRE_VERSION_9,   false",
	"JRE_VERSION_9,   JRE_VERSION_9,   true",
	"JRE_VERSION_10,  JRE_VERSION_9,   true",
	"JRE_VERSION_9,   JRE_VERSION_10,  false",
	"JRE_VERSION_10,  JRE_VERSION_9,   true",
	"JRE_VERSION_10,  JRE_VERSION_10,  true",
	"JRE_VERSION_10,  JRE_VERSION_11,  false",
})
public void isAtLeast(@ConvertWith(JavaVersionConstantArgumentConverter.class) JavaVersion version1,
		@ConvertWith(JavaVersionConstantArgumentConverter.class) JavaVersion version2, boolean result) {
	assertEquals(version1.isAtLeast(version2), result);
}
 
Example #7
Source File: JavaVersionTest.java    From keystore-explorer with GNU General Public License v3.0 5 votes vote down vote up
@ParameterizedTest
@CsvSource({
	"JRE_VERSION_160, 1.6.0",
	"JRE_VERSION_170, 1.7.0",
	"JRE_VERSION_180, 1.8.0",
	"JRE_VERSION_9, 9",
	"JRE_VERSION_9, 9.0.0",
	"JRE_VERSION_10, 10.0.0",
	"JRE_VERSION_11, 11.0.0",
})
public void equals(@ConvertWith(JavaVersionConstantArgumentConverter.class) JavaVersion verConst, String verStr) {
	assertEquals(verConst, new JavaVersion(verStr));
}
 
Example #8
Source File: ExplicitConversionParameterizedTest.java    From Mastering-Software-Testing-with-JUnit-5 with MIT License 5 votes vote down vote up
@ParameterizedTest
@EnumSource(TimeUnit.class)
void testWithExplicitArgumentConversion(
        @ConvertWith(CustomArgumentsConverter.class) String argument) {
    System.out.println("Argument " + argument + " is a type of "
            + argument.getClass());

    assertNotNull(argument);
}
 
Example #9
Source File: UsageExampleTests.java    From junit5-extensions with MIT License 5 votes vote down vote up
@ExpectFailure({
    @Cause(type = ParameterResolutionException.class),
    @Cause(type = ArgumentConversionException.class, message = "is not assignable to")
})
@ParameterizedTest
@ValueSource(strings = "java.lang.Object")
void badUpperBound(
    @ConvertWith(ClassArgumentConverter.class) Class<? extends Collection<?>> clazz) {}
 
Example #10
Source File: UsageExampleTests.java    From junit5-extensions with MIT License 5 votes vote down vote up
@ExpectFailure({
    @Cause(type = ParameterResolutionException.class),
    @Cause(type = ArgumentConversionException.class, message = "is not assignable to")
})
@ParameterizedTest
@ValueSource(strings = "java.util.List")
void badLowerBound(
    @ConvertWith(ClassArgumentConverter.class) Class<? super Collection<?>> clazz) {}
 
Example #11
Source File: UsageExampleTests.java    From junit5-extensions with MIT License 5 votes vote down vote up
@ExpectFailure({
    @Cause(type = ParameterResolutionException.class),
    @Cause(
        type = ArgumentConversionException.class,
        message = "java.lang.Class<java.util.List> is not assignable to"
            + " java.lang.Class<java.util.Collection<?>>"
    )
})
@ParameterizedTest
@ValueSource(strings = "java.util.List")
void wrongClass(@ConvertWith(ClassArgumentConverter.class) Class<Collection<?>> clazz) {}
 
Example #12
Source File: UsageExampleTests.java    From junit5-extensions with MIT License 5 votes vote down vote up
@ExpectFailure({
    @Cause(type = ParameterResolutionException.class),
    @Cause(type = ArgumentConversionException.class, message = "Invalid parameter type")
})
@ParameterizedTest
@ValueSource(strings = "java.lang.Object")
void badParameterType(@ConvertWith(ClassArgumentConverter.class) String clazz) {}
 
Example #13
Source File: UsageExampleTests.java    From junit5-extensions with MIT License 5 votes vote down vote up
@ExpectFailure({
    @Cause(type = ParameterResolutionException.class),
    @Cause(type = ArgumentConversionException.class),
    @Cause(type = ClassNotFoundException.class)
})
@ParameterizedTest
@ValueSource(strings = "123ClassDoesNotExist")
void classNotFound(@ConvertWith(ClassArgumentConverter.class) Class<?> clazz) {}
 
Example #14
Source File: UsageExampleTests.java    From junit5-extensions with MIT License 5 votes vote down vote up
@ParameterizedTest
@ValueSource(strings = {
    "java.util.List",
    "java.util.ArrayList",
})
void anySubclass(@ConvertWith(ClassArgumentConverter.class) Class<? extends List<?>> anything) {
  assertThat(anything).isNotNull();
}
 
Example #15
Source File: UsageExampleTests.java    From junit5-extensions with MIT License 5 votes vote down vote up
@ParameterizedTest
@ValueSource(strings = {
    "java.util.List",
    "java.util.Collection",
    "java.lang.Object",
})
void anySuperclass(
    @ConvertWith(ClassArgumentConverter.class) Class<? super List<?>> superclassOfList) {
  assertThat(superclassOfList).isNotNull();
}
 
Example #16
Source File: ExplicitConversionParameterizedTest.java    From mastering-junit5 with Apache License 2.0 5 votes vote down vote up
@ParameterizedTest
@EnumSource(TimeUnit.class)
void testWithExplicitArgumentConversion(
        @ConvertWith(CustomArgumentsConverter.class) String argument) {
    System.out.println("Argument " + argument + " is a type of "
            + argument.getClass());

    assertNotNull(argument);
}
 
Example #17
Source File: JsonArgumentsToValuesTest.java    From junit-json-params with Apache License 2.0 5 votes vote down vote up
@ParameterizedTest
@Disabled("Doesn't yet work as only the first parameter gets a value")
@JsonSource("{'stringKey':'value', 'boolKey': true, 'intKey': 1 }")
@DisplayName("provides multiple objects")
void multipleObjects(
        @ConvertWith(JsonConverter.class) String stringKey,
        @ConvertWith(JsonConverter.class) int intKey,
        @ConvertWith(JsonConverter.class) boolean boolKey) {
    assertEquals("value", stringKey);
    assertTrue(boolKey);
    assertEquals(1, intKey);
}
 
Example #18
Source File: EntityRecordItemListenerTopicTest.java    From hedera-mirror-node with Apache License 2.0 5 votes vote down vote up
@ParameterizedTest
@CsvSource({
        "0.0.9000, test-message0, 9000000, runninghash, 1, 1",
        "0.0.9001, '', 9000001, '', 9223372036854775807, 2"
})
void submitMessageTest(@ConvertWith(TopicIdConverter.class) TopicID topicId, String message,
                       long consensusTimestamp, String runningHash,
                       long sequenceNumber, int runningHashVersion) throws Exception {
    var responseCode = ResponseCodeEnum.SUCCESS;

    var topic = createTopicEntity(topicId, 10L, 20, null, null, null, null, null);
    entityRepository.save(topic);

    var topicMessage = createTopicMessage(topicId, message, sequenceNumber, runningHash, consensusTimestamp,
            runningHashVersion);
    var transaction = createSubmitMessageTransaction(topicId, message);
    var transactionRecord = createTransactionRecord(topicId, sequenceNumber, runningHash
            .getBytes(), runningHashVersion, consensusTimestamp, responseCode);

    parseRecordItemAndCommit(new RecordItem(transaction, transactionRecord));

    var entity = getTopicEntity(topicId);
    assertTransactionInRepository(responseCode, consensusTimestamp, entity.getId());
    assertEquals(3L, entityRepository.count()); // Node, payer, topic
    assertThat(entity).isEqualTo(topic);
    assertThat(topicMessageRepository.findById(consensusTimestamp)).get()
            .isEqualTo(topicMessage);
}
 
Example #19
Source File: JsonArgumentsToValuesTest.java    From junit-json-params with Apache License 2.0 4 votes vote down vote up
@ParameterizedTest
@JsonSource("{'key': 1 }")
@DisplayName("Converts to ints")
void booleans(@ConvertWith(JsonConverter.class) int key) {
    assertEquals(1, key);
}
 
Example #20
Source File: CustomArgumentConverterTest.java    From demo-junit-5 with Creative Commons Zero v1.0 Universal 4 votes vote down vote up
@ParameterizedTest
@ValueSource(strings = { "(0/0)", "(0/1)", "(1/0)", "(1/1)", "(2/1)" })
void testPointNotNull_1(@ConvertWith(PointConverter.class) Point point) {
	assertNotNull(point);
}
 
Example #21
Source File: JsonArgumentsToValuesTest.java    From junit-json-params with Apache License 2.0 4 votes vote down vote up
@ParameterizedTest
@JsonSource("{'key': true}")
@DisplayName("Converts to booleans")
void ints(@ConvertWith(JsonConverter.class) boolean key) {
    assertTrue(key);
}
 
Example #22
Source File: JsonArgumentsToValuesTest.java    From junit-json-params with Apache License 2.0 4 votes vote down vote up
@ParameterizedTest
@JsonSource("{'key':'value'}")
@DisplayName("Converts to Strings")
void strings(@ConvertWith(JsonConverter.class) String key) {
    assertEquals("value", key);
}
 
Example #23
Source File: EntityRecordItemListenerTopicTest.java    From hedera-mirror-node with Apache License 2.0 4 votes vote down vote up
@ParameterizedTest
@CsvSource({
        "0.0.1500, 10, 20, admin-key, submit-key, memo, 5000000, 0, 0, , , , 1, 30, , 0",
        "0.0.1500, 10, 20, admin-key, submit-key, memo, 5000000, , , , , , 1, 30, , ",
        "0.0.1501, 0, 0, '', '', '', 5000001, 0, 0, , , , , , ,",
        "0.0.1502, , , admin-key, submit-key, memo, 5000002, 10, 20, updated-admin-key, updated-submit-key, " +
                "updated-memo, 1, 30, 11, 31",
        "0.0.1503, , , , , , 5000003, 11, 21, admin-key, submit-key, memo, , , 1, 30"
})
void updateTopicTestPartialUpdates(@ConvertWith(TopicIdConverter.class) TopicID topicId, Long expirationTimeSeconds,
                                   Integer expirationTimeNanos, @ConvertWith(KeyConverter.class) Key adminKey,
                                   @ConvertWith(KeyConverter.class) Key submitKey, String memo,
                                   long consensusTimestamp, Long updatedExpirationTimeSeconds,
                                   Integer updatedExpirationTimeNanos,
                                   @ConvertWith(KeyConverter.class) Key updatedAdminKey,
                                   @ConvertWith(KeyConverter.class) Key updatedSubmitKey, String updatedMemo,
                                   Long autoRenewAccountNum, Long autoRenewPeriod, Long updatedAutoRenewAccountNum,
                                   Long updatedAutoRenewPeriod) {
    // Store topic to be updated.
    var topic = createTopicEntity(topicId, expirationTimeSeconds, expirationTimeNanos, adminKey, submitKey, memo,
            autoRenewAccountNum, autoRenewPeriod);
    entityRepository.save(topic);

    if (updatedAutoRenewPeriod != null) {
        topic.setAutoRenewPeriod(updatedAutoRenewPeriod);
    }
    if (updatedExpirationTimeSeconds != null && updatedExpirationTimeNanos != null) {
        topic.setExpiryTimeNs(Utility.convertToNanosMax(updatedExpirationTimeSeconds, updatedExpirationTimeNanos));
    }
    if (updatedAdminKey != null) {
        topic.setKey(updatedAdminKey.toByteArray());
    }
    if (updatedSubmitKey != null) {
        topic.setSubmitKey(updatedSubmitKey.toByteArray());
    }
    if (updatedMemo != null) {
        topic.setMemo(updatedMemo);
    }

    var responseCode = ResponseCodeEnum.SUCCESS;
    var transaction = createUpdateTopicTransaction(topicId, updatedExpirationTimeSeconds,
            updatedExpirationTimeNanos, updatedAdminKey, updatedSubmitKey, updatedMemo, updatedAutoRenewAccountNum,
            updatedAutoRenewPeriod);
    var transactionRecord = createTransactionRecord(topicId, consensusTimestamp, responseCode);

    parseRecordItemAndCommit(new RecordItem(transaction, transactionRecord));

    long entityCount = 3;
    if (autoRenewAccountNum != null) {
        ++entityCount;
    }
    if (updatedAutoRenewAccountNum != null) {
        ++entityCount;
        topic.setAutoRenewAccountId(EntityId.of(0L, 0L, updatedAutoRenewAccountNum, EntityTypeEnum.ACCOUNT));
    }
    var entity = getTopicEntity(topicId);
    assertTransactionInRepository(responseCode, consensusTimestamp, entity.getId());
    assertEquals(entityCount, entityRepository.count());
    assertThat(entity).isEqualTo(topic);
}
 
Example #24
Source File: LocalDateUnitTest.java    From tutorials with MIT License 4 votes vote down vote up
@ParameterizedTest
@CsvSource({"2018/12/25,2018", "2019/02/11,2019"})
void getYear_ShouldWorkAsExpected(@ConvertWith(SlashyDateConverter.class) LocalDate date, int expected) {
    assertEquals(expected, date.getYear());
}