类org.junit.jupiter.api.TestFactory源码实例Demo

下面列出了怎么用org.junit.jupiter.api.TestFactory的API类实例代码及写法,或者点击链接到github查看源代码。

@TestFactory
Stream<DynamicTest> testCleanBeforeNavigate()
{
    WebDriver driver = mock(WebDriver.class, withSettings().extraInterfaces(HasCapabilities.class));
    Consumer<Runnable> test = methodUnderTest ->
    {
        Options options = mock(Options.class);
        when(driver.manage()).thenReturn(options);
        Logs logs = mock(Logs.class);
        when(options.logs()).thenReturn(logs);
        when(logs.get(LogType.BROWSER)).thenReturn(mock(LogEntries.class));
        methodUnderTest.run();
    };
    return Stream.of(
            dynamicTest("beforeNavigateBack", () -> test.accept(() -> listener.beforeNavigateBack(driver))),
            dynamicTest("beforeNavigateForward", () -> test.accept(() -> listener.beforeNavigateForward(driver))),
            dynamicTest("beforeNavigateRefresh", () -> test.accept(() -> listener.beforeNavigateRefresh(driver))),
            dynamicTest("beforeNavigateTo", () -> test.accept(() -> listener.beforeNavigateTo("url", driver))));
}
 
源代码2 项目: vividus   文件: ScreenshotOnFailureMonitorTests.java
@TestFactory
Stream<DynamicTest> shouldProcessStepWithAnnotation() throws NoSuchMethodException
{
    return Stream.of(getClass().getDeclaredMethod(WHEN_STEP_METHOD),
            TestSteps.class.getDeclaredMethod("innerWhenStep"))
            .flatMap(method ->
            {
                reset(bddRunContext);
                mockScenarioAndStoryMeta(EMPTY_META);
                return Stream.of(
                        dynamicTest("beforePerformingProcessesStepWithAnnotation",
                            () -> monitor.beforePerforming(I_DO_ACTION, false, method)),
                        dynamicTest("afterPerformingProcessesStepWithAnnotation",
                            () -> monitor.afterPerforming(I_DO_ACTION, false, method))
                        );
            });
}
 
源代码3 项目: sdn-rx   文件: Neo4jConversionsIT.java
@TestFactory
@DisplayName("Objects")
Stream<DynamicNode> objects() {
	Map<String, Map<String, Object>> supportedTypes = new HashMap<>();
	supportedTypes.put("CypherTypes", CYPHER_TYPES);
	supportedTypes.put("AdditionalTypes", ADDITIONAL_TYPES);
	supportedTypes.put("SpatialTypes", SPATIAL_TYPES);

	return supportedTypes.entrySet().stream()
		.map(types -> {

			DynamicContainer reads = DynamicContainer.dynamicContainer("read", types.getValue().entrySet().stream()
				.map(a -> dynamicTest(a.getKey(),
					() -> Neo4jConversionsIT.assertRead(types.getKey(), a.getKey(), a.getValue()))));

			DynamicContainer writes = DynamicContainer.dynamicContainer("write", types.getValue().entrySet().stream()
				.map(a -> dynamicTest(a.getKey(),
					() -> Neo4jConversionsIT.assertWrite(types.getKey(), a.getKey(), a.getValue()))));

			return DynamicContainer.dynamicContainer(types.getKey(), Arrays.asList(reads, writes));
		});
}
 
源代码4 项目: mongo-kafka   文件: RecordBatchesTest.java
@TestFactory
@DisplayName("test batching with different config params for max.batch.size")
Stream<DynamicTest> testBatchingWithDifferentConfigsForBatchSize() {

  return Stream.iterate(0, r -> r + 1)
      .limit(NUM_FAKE_RECORDS + 1)
      .map(
          batchSize ->
              dynamicTest(
                  "test batching for "
                      + NUM_FAKE_RECORDS
                      + " records with batchsize="
                      + batchSize,
                  () -> {
                    RecordBatches batches = new RecordBatches(batchSize, NUM_FAKE_RECORDS);
                    assertEquals(LIST_INITIAL_EMPTY, batches.getBufferedBatches());
                    List<SinkRecord> recordList =
                        createSinkRecordList("foo", 0, 0, NUM_FAKE_RECORDS);
                    recordList.forEach(batches::buffer);
                    List<List<SinkRecord>> batchedList =
                        partition(recordList, batchSize > 0 ? batchSize : recordList.size());
                    assertEquals(batchedList, batches.getBufferedBatches());
                  }));
}
 
@TestFactory
List<DynamicTest> noop_implementation_never_throws() {
    MetricsCollectorWrapper metricsCollectorWrapper = new NoopMetricsCollectorWrapper();
    return Arrays.asList(
        dynamicTest("newConnection", () -> metricsCollectorWrapper.newConnection(null)),
        dynamicTest("closeConnection", () -> metricsCollectorWrapper.closeConnection(null)),
        dynamicTest("newChannel", () -> metricsCollectorWrapper.newChannel(null)),
        dynamicTest("closeChannel", () -> metricsCollectorWrapper.closeChannel(null)),
        dynamicTest("basicPublish", () -> metricsCollectorWrapper.basicPublish(null)),
        dynamicTest("consumedMessage", () -> metricsCollectorWrapper.consumedMessage(null, 0L, true)),
        dynamicTest("consumedMessage (consumerTag)", () -> metricsCollectorWrapper.consumedMessage(null, 0L, null)),
        dynamicTest("basicAck", () -> metricsCollectorWrapper.basicAck(null, 0L, true)),
        dynamicTest("basicNack", () -> metricsCollectorWrapper.basicNack(null, 0L)),
        dynamicTest("basicReject", () -> metricsCollectorWrapper.basicReject(null, 0L)),
        dynamicTest("basicConsume", () -> metricsCollectorWrapper.basicConsume(null, null, true)),
        dynamicTest("basicCancel", () -> metricsCollectorWrapper.basicCancel(null, null))
    );
}
 
源代码6 项目: herd-mdl   文件: HttpsAndAuthTest.java
@TestFactory
public Stream<DynamicTest> testHerdShellCommandWithWrongCredential() {
    String assertionPass = "status code is 200";
    String assertionFailure = "status code is 401";

    return getTestCases(HERD_AUTH_TESTCASES)
            .stream().map(command -> DynamicTest.dynamicTest(COMPONENT + command.getName(), () -> {
                String result = ShellHelper.executeShellTestCase(command, envVars);
                if (!IS_SSLAUTH_ENABLED) {
                    LogVerification("Verify herd shell command response pass without/with invalid credential provided when enableAuth is false");
                    assertThat(result, containsString(assertionPass));
                }
                else {
                    LogVerification("Verify herd shell command response failure without/with invalid credential provided when enableAuth is true");
                    assertThat(result, containsString(assertionFailure));
                }
            }));
}
 
源代码7 项目: herd-mdl   文件: HttpsAndAuthTest.java
@TestFactory
public Stream<DynamicTest> testHerdHttpIsNotAllowedWhenHttpsEnabled() {
    return getTestCases(HTTP_TESTCASES)
            .stream().map(command -> DynamicTest.dynamicTest(COMPONENT + command.getName(), () -> {
                if (!IS_SSLAUTH_ENABLED) {
                    LogVerification("Verify herd/shepherd call pass with http url when enableSslAuth is false");
                    String result = ShellHelper.executeShellTestCase(command, envVars);
                    assertThat(command.getAssertVal(), notNullValue());
                    assertThat(result, containsString(command.getAssertVal()));
                }
                else {
                    LogVerification("Verify herd/shepherd call failed with http url when enableSslAuth is true");
                    assertThrows(RuntimeException.class, () -> {
                        ShellHelper.executeShellTestCase(command, envVars);
                    });
                }
            }));
}
 
源代码8 项目: herd-mdl   文件: HttpsAndAuthTest.java
@TestFactory
public Stream<DynamicTest> testHerdHttpsIsNotAllowedWhenHttpsIsDisabled() {
    return getTestCases(HTTPS_TESTCASES)
            .stream().map(command -> DynamicTest.dynamicTest(COMPONENT + command.getName(), () -> {
                if (IS_SSLAUTH_ENABLED) {
                    LogVerification("Verify herd call pass with https url when enableSslAuth is true");
                    String result = ShellHelper.executeShellTestCase(command, envVars);
                    assertThat(command.getAssertVal(), notNullValue());
                    assertThat(result, containsString(command.getAssertVal()));
                }
                else {
                    LogVerification("Verify herd call failed with https url when enableSslAuth is false");
                    assertThrows(RuntimeException.class, () -> {
                        ShellHelper.executeShellTestCase(command, envVars);
                    });
                }
            }));
}
 
源代码9 项目: yare   文件: OperandSerializationTestCase.java
@TestFactory
Stream<DynamicTest> operandSerializationTestFactory() {
    return Stream.of(
            DynamicTest.dynamicTest(
                    "Should serialize value operand",
                    () -> shouldSerializeOperand(createValueOperandModel(), getSerializedValueOperand())
            ),
            DynamicTest.dynamicTest(
                    "Should serialize values operand",
                    () -> shouldSerializeOperand(createValuesOperandModel(), getSerializedValuesOperand())
            ),
            DynamicTest.dynamicTest(
                    "Should serialize function operand",
                    () -> shouldSerializeOperand(createFunctionOperandModel(), getSerializedFunctionOperand())
            ),
            DynamicTest.dynamicTest(
                    "Should serialize operator operand",
                    () -> shouldSerializeOperand(createOperatorOperandModel(), getSerializedOperatorOperand())
            )
    );
}
 
源代码10 项目: yare   文件: OperandSerializationTestCase.java
@TestFactory
Stream<DynamicTest> operandDeserializationTestFactory() {
    return Stream.of(
            DynamicTest.dynamicTest(
                    "Should deserialize value operand",
                    () -> shouldDeserializeOperand(createValueOperandModel(), getSerializedValueOperand())
            ),
            DynamicTest.dynamicTest(
                    "Should deserialize values operand",
                    () -> shouldDeserializeOperand(createValuesOperandModel(), getSerializedValuesOperand())
            ),
            DynamicTest.dynamicTest(
                    "Should deserialize function operand",
                    () -> shouldDeserializeOperand(createFunctionOperandModel(), getSerializedFunctionOperand())
            ),
            DynamicTest.dynamicTest(
                    "Should deserialize operator operand",
                    () -> shouldDeserializeOperand(createOperatorOperandModel(), getSerializedOperatorOperand())
            )
    );
}
 
源代码11 项目: yare   文件: ExpressionSerializationTestCase.java
@TestFactory
Stream<DynamicTest> expressionSerializationTestFactory() {
    return Stream.of(
            DynamicTest.dynamicTest(
                    "Should serialize value expression",
                    () -> shouldSerializeExpression(createValueExpressionModel(), getSerializedValueExpression())
            ),
            DynamicTest.dynamicTest(
                    "Should serialize values expression",
                    () -> shouldSerializeExpression(createValuesExpressionModel(), getSerializedValuesExpression())
            ),
            DynamicTest.dynamicTest(
                    "Should serialize function expression",
                    () -> shouldSerializeExpression(createFunctionExpressionModel(), getSerializedFunctionExpression())
            )
    );
}
 
源代码12 项目: yare   文件: ParameterSerializationTestCase.java
@TestFactory
Stream<DynamicTest> parameterSerializationTestFactory() {
    return Stream.of(
            DynamicTest.dynamicTest(
                    "Should serialize value parameter",
                    () -> shouldSerializeParameter(createValueParameterModel(), getSerializedValueParameter())
            ),
            DynamicTest.dynamicTest(
                    "Should serialize values parameter",
                    () -> shouldSerializeParameter(createValuesParameterModel(), getSerializedValuesParameter())
            ),
            DynamicTest.dynamicTest(
                    "Should serialize function parameter",
                    () -> shouldSerializeParameter(createFunctionParameterModel(), getSerializedFunctionParameter())
            )
    );
}
 
源代码13 项目: yare   文件: ParameterSerializationTestCase.java
@TestFactory
Stream<DynamicTest> parameterDeserializeTestFactory() {
    return Stream.of(
            DynamicTest.dynamicTest(
                    "Should deserialize value parameter",
                    () -> shouldDeserializeParameter(createValueParameterModel(), getSerializedValueParameter())
            ),
            DynamicTest.dynamicTest(
                    "Should deserialize values parameter",
                    () -> shouldDeserializeParameter(createValuesParameterModel(), getSerializedValuesParameter())
            ),
            DynamicTest.dynamicTest(
                    "Should deserialize function parameter",
                    () -> shouldDeserializeParameter(createFunctionParameterModel(), getSerializedFunctionParameter())
            )
    );
}
 
源代码14 项目: yare   文件: ValueSerializationTestCase.java
@TestFactory
Stream<DynamicTest> valueSerializationTestFactory() {
    return Stream.of(
            DynamicTest.dynamicTest(
                    "Should serialize build-in type value",
                    () -> shouldSerializeValue(createBuildInTypeValueModel(), getSerializedBuildInTypeValue())
            ),
            DynamicTest.dynamicTest(
                    "Should serialize string type value",
                    () -> shouldSerializeValue(createStringTypeValueModel(), getSerializedStringTypeValue())
            ),
            DynamicTest.dynamicTest(
                    "Should serialize custom type value",
                    () -> shouldSerializeValue(createCustomTypeValueModel(), getSerializedCustomTypeValue())
            )
    );
}
 
源代码15 项目: yare   文件: ValueSerializationTestCase.java
@TestFactory
Stream<DynamicTest> valueDeserializationTestFactory() {
    return Stream.of(
            DynamicTest.dynamicTest(
                    "Should deserialize build-in type value",
                    () -> shouldDeserializeValue(createBuildInTypeValueModel(), getSerializedBuildInTypeValue())
            ),
            DynamicTest.dynamicTest(
                    "Should deserialize string type value",
                    () -> shouldDeserializeValue(createStringTypeValueModel(), getSerializedStringTypeValue())
            ),
            DynamicTest.dynamicTest(
                    "Should deserialize custom type value",
                    () -> shouldDeserializeValue(createCustomTypeValueModel(), getSerializedCustomTypeValue())
            )
    );
}
 
源代码16 项目: jhdf   文件: CompressedChunkedDatasetTest.java
@TestFactory
Collection<DynamicNode> compressedChunkedDatasetReadTests() {
	// List of all the datasetPaths
	return Arrays.asList(
			dynamicContainer(HDF5_TEST_EARLIEST_FILE_NAME, Arrays.asList(
					dynamicTest("float32", createTest(earliestHdfFile,"/float/float32")),
					dynamicTest("float64", createTest(earliestHdfFile,"/float/float64")),
					dynamicTest("int8", createTest(earliestHdfFile,"/int/int8")),
					dynamicTest("int16", createTest(earliestHdfFile,"/int/int16")),
					dynamicTest("int32", createTest(earliestHdfFile,"/int/int32")))),

			dynamicContainer(HDF5_TEST_LATEST_FILE_NAME, Arrays.asList(
					dynamicTest("float32", createTest(latestHdfFile, "/float/float32")),
					dynamicTest("float64", createTest(latestHdfFile,"/float/float64")),
					dynamicTest("int8", createTest(latestHdfFile,"/int/int8")),
					dynamicTest("int16", createTest(latestHdfFile,"/int/int16")),
					dynamicTest("int32", createTest(latestHdfFile,"/int/int32")))));
}
 
源代码17 项目: jhdf   文件: ChunkedDatasetTest.java
@TestFactory
Collection<DynamicNode> chunkedDatasetReadTests() {
	// List of all the datasetPaths
	return Arrays.asList(
			dynamicContainer(HDF5_TEST_EARLIEST_FILE_NAME, Arrays.asList(
					dynamicTest("float16", createTest(earliestHdfFile, "/float/float16")),
					dynamicTest("float32", createTest(earliestHdfFile, "/float/float32")),
					dynamicTest("float64", createTest(earliestHdfFile, "/float/float64")),
					dynamicTest("int8", createTest(earliestHdfFile, "/int/int8")),
					dynamicTest("int16", createTest(earliestHdfFile, "/int/int16")),
					dynamicTest("int32", createTest(earliestHdfFile, "/int/int32")))),

			dynamicContainer(HDF5_TEST_EARLIEST_FILE_NAME, Arrays.asList(
					dynamicTest("float16", createTest(latestHdfFile, "/float/float16")),
					dynamicTest("float32", createTest(latestHdfFile, "/float/float32")),
					dynamicTest("float64", createTest(latestHdfFile, "/float/float64")),
					dynamicTest("int8", createTest(latestHdfFile, "/int/int8")),
					dynamicTest("int16", createTest(latestHdfFile, "/int/int16")),
					dynamicTest("int32", createTest(latestHdfFile, "/int/int32"))))
	);
}
 
源代码18 项目: jhdf   文件: FloatSpecialValuesTest.java
@TestFactory
Collection<DynamicNode> specialFloatValuesTests() {
    // List of all the datasetPaths
    return Arrays.asList(
            dynamicContainer("earliest", Arrays.asList(
                    dynamicTest("float16",
                            testFloat(earliestHdfFile, "float16")),
                    dynamicTest("float32",
                            testFloat(earliestHdfFile, "float32")),
                    dynamicTest("float64",
                            testDouble(earliestHdfFile, "float64")))),

            dynamicContainer("latest", Arrays.asList(
                    dynamicTest("float16",
                            testFloat(latestHdfFile, "float16")),
                    dynamicTest("float32",
                            testFloat(latestHdfFile, "float32")),
                    dynamicTest("float64",
                            testDouble(latestHdfFile, "float64")))));
}
 
源代码19 项目: jhdf   文件: StringDatasetTest.java
@TestFactory
Collection<DynamicNode> stringDataset1DTests() {
	// List of all the datasetPaths
	return Arrays.asList(
			dynamicContainer("earliest", Arrays.asList(
					dynamicTest("fixed ASCII",
							createTest(earliestHdfFile, "/fixed_length_ascii")),
					dynamicTest("fixed ASCII 1 char",
							createTest(earliestHdfFile, "/fixed_length_ascii_1_char")),
					dynamicTest("variable ASCII",
							createTest(earliestHdfFile, "/variable_length_ascii")),
					dynamicTest("variable UTF8",
							createTest(earliestHdfFile, "/variable_length_utf8")))),

			dynamicContainer("latest", Arrays.asList(
					dynamicTest("fixed ASCII",
							createTest(latestHdfFile, "/fixed_length_ascii")),
					dynamicTest("fixed ASCII 1 char",
							createTest(latestHdfFile, "/fixed_length_ascii_1_char")),
					dynamicTest("variable ASCII",
							createTest(latestHdfFile, "/variable_length_ascii")),
					dynamicTest("variable UTF8",
							createTest(latestHdfFile, "/variable_length_utf8")))));
}
 
源代码20 项目: jhdf   文件: TestAllFiles.java
@TestFactory
Stream<DynamicNode> allHdf5TestFiles() throws IOException, URISyntaxException {

	// Auto discover the test files assuming they exist in under the directory
	// containing test_file.hdf5
	URL resource = this.getClass().getResource("/hdf5/");
	Path path = Paths.get(resource.toURI()).getParent();
	List<Path> files = Files.walk(path).filter(HDF5::matches).collect(Collectors.toList());

	// Check at least some files have been discovered
	assertThat("Less than 3 HDF5 test files discovered searched paths below: " + path.toAbsolutePath(),
			files.size(), is(greaterThan(2)));

	// Make a test for each file
	return files.stream().map(this::createTest);
}
 
源代码21 项目: vividus   文件: ScreenshotOnFailureMonitorTests.java
@TestFactory
Stream<DynamicTest> shouldIgnoreStepWithoutAnnotation() throws NoSuchMethodException
{
    return Stream.of(getClass().getDeclaredMethod("anotherWhenStep"), null)
            .flatMap(method -> Stream.of(
                    dynamicTest("beforePerformingIgnoresStepWithoutAnnotation",
                        () -> monitor.beforePerforming(I_DO_ACTION, false, method)),
                    dynamicTest("afterPerformingIgnoresStepWithoutAnnotation",
                        () -> monitor.afterPerforming(I_DO_ACTION, false, method))
                    ));
}
 
源代码22 项目: javatech   文件: DynamicTests.java
@TestFactory
Stream<DynamicNode> dynamicTestsWithContainers() {
    return Stream
        .of("A", "B", "C").map(
            input -> dynamicContainer("Container " + input, Stream
                .of(dynamicTest("not null", () -> assertNotNull(input)),
                    dynamicContainer("properties",
                        Stream.of(
                            dynamicTest("length > 0",
                                () -> assertTrue(input
                                    .length() > 0)),
                            dynamicTest("not empty",
                                () -> assertFalse(input
                                    .isEmpty())))))));
}
 
源代码23 项目: mongo-kafka   文件: SinkFieldConverterTest.java
@TestFactory
@DisplayName("tests for boolean field conversions")
List<DynamicTest> testBooleanFieldConverter() {

  SinkFieldConverter converter = new BooleanFieldConverter();

  List<DynamicTest> tests = new ArrayList<>();
  asList(true, false)
      .forEach(
          el ->
              tests.add(
                  dynamicTest(
                      "conversion with " + converter.getClass().getSimpleName() + " for " + el,
                      () -> assertEquals(el, ((BsonBoolean) converter.toBson(el)).getValue()))));

  tests.add(
      dynamicTest(
          "optional type conversion checks",
          () -> {
            Schema valueOptionalDefault = SchemaBuilder.bool().optional().defaultValue(true);
            assertAll(
                "",
                () ->
                    assertThrows(
                        DataException.class, () -> converter.toBson(null, Schema.BOOLEAN_SCHEMA)),
                () ->
                    assertEquals(
                        new BsonNull(), converter.toBson(null, Schema.OPTIONAL_BOOLEAN_SCHEMA)),
                () ->
                    assertEquals(
                        valueOptionalDefault.defaultValue(),
                        converter.toBson(null, valueOptionalDefault).asBoolean().getValue()));
          }));

  return tests;
}
 
源代码24 项目: mongo-kafka   文件: SinkFieldConverterTest.java
@TestFactory
@DisplayName("tests for int8 field conversions")
List<DynamicTest> testInt8FieldConverter() {

  SinkFieldConverter converter = new Int8FieldConverter();

  List<DynamicTest> tests = new ArrayList<>();
  asList(Byte.MIN_VALUE, (byte) 0, Byte.MAX_VALUE)
      .forEach(
          el ->
              tests.add(
                  dynamicTest(
                      "conversion with " + converter.getClass().getSimpleName() + " for " + el,
                      () ->
                          assertEquals(
                              (int) el, ((BsonInt32) converter.toBson(el)).getValue()))));

  tests.add(
      dynamicTest(
          "optional type conversions",
          () -> {
            Schema valueOptionalDefault = SchemaBuilder.int8().optional().defaultValue((byte) 0);
            assertAll(
                "checks",
                () ->
                    assertThrows(
                        DataException.class, () -> converter.toBson(null, Schema.INT8_SCHEMA)),
                () ->
                    assertEquals(
                        new BsonNull(), converter.toBson(null, Schema.OPTIONAL_INT8_SCHEMA)),
                () ->
                    assertEquals(
                        ((Byte) valueOptionalDefault.defaultValue()).intValue(),
                        ((BsonInt32) converter.toBson(null, valueOptionalDefault)).getValue()));
          }));

  return tests;
}
 
源代码25 项目: mongo-kafka   文件: SinkFieldConverterTest.java
@TestFactory
@DisplayName("tests for int16 field conversions")
List<DynamicTest> testInt16FieldConverter() {

  SinkFieldConverter converter = new Int16FieldConverter();

  List<DynamicTest> tests = new ArrayList<>();
  asList(Short.MIN_VALUE, (short) 0, Short.MAX_VALUE)
      .forEach(
          el ->
              tests.add(
                  dynamicTest(
                      "conversion with " + converter.getClass().getSimpleName() + " for " + el,
                      () ->
                          assertEquals(
                              (short) el, ((BsonInt32) converter.toBson(el)).getValue()))));

  tests.add(
      dynamicTest(
          "optional type conversions",
          () -> {
            Schema valueOptionalDefault =
                SchemaBuilder.int16().optional().defaultValue((short) 0);
            assertAll(
                "checks",
                () ->
                    assertThrows(
                        DataException.class, () -> converter.toBson(null, Schema.INT16_SCHEMA)),
                () ->
                    assertEquals(
                        new BsonNull(), converter.toBson(null, Schema.OPTIONAL_INT16_SCHEMA)),
                () ->
                    assertEquals(
                        ((short) valueOptionalDefault.defaultValue()),
                        ((BsonInt32) converter.toBson(null, valueOptionalDefault)).getValue()));
          }));

  return tests;
}
 
源代码26 项目: mongo-kafka   文件: SinkFieldConverterTest.java
@TestFactory
@DisplayName("tests for int32 field conversions")
List<DynamicTest> testInt32FieldConverter() {

  SinkFieldConverter converter = new Int32FieldConverter();

  List<DynamicTest> tests = new ArrayList<>();
  asList(Integer.MIN_VALUE, 0, Integer.MAX_VALUE)
      .forEach(
          el ->
              tests.add(
                  dynamicTest(
                      "conversion with " + converter.getClass().getSimpleName() + " for " + el,
                      () ->
                          assertEquals(
                              (int) el, ((BsonInt32) converter.toBson(el)).getValue()))));

  tests.add(
      dynamicTest(
          "optional type conversions",
          () -> {
            Schema valueOptionalDefault = SchemaBuilder.int32().optional().defaultValue(0);
            assertAll(
                "checks",
                () ->
                    assertThrows(
                        DataException.class, () -> converter.toBson(null, Schema.INT32_SCHEMA)),
                () ->
                    assertEquals(
                        new BsonNull(), converter.toBson(null, Schema.OPTIONAL_INT32_SCHEMA)),
                () ->
                    assertEquals(
                        valueOptionalDefault.defaultValue(),
                        ((BsonInt32) converter.toBson(null, valueOptionalDefault)).getValue()));
          }));

  return tests;
}
 
源代码27 项目: mongo-kafka   文件: SinkFieldConverterTest.java
@TestFactory
@DisplayName("tests for int64 field conversions")
List<DynamicTest> testInt64FieldConverter() {
  SinkFieldConverter converter = new Int64FieldConverter();
  List<DynamicTest> tests = new ArrayList<>();

  asList(Long.MIN_VALUE, 0L, Long.MAX_VALUE)
      .forEach(
          el ->
              tests.add(
                  dynamicTest(
                      "conversion with " + converter.getClass().getSimpleName() + " for " + el,
                      () ->
                          assertEquals(
                              (long) el, ((BsonInt64) converter.toBson(el)).getValue()))));

  tests.add(
      dynamicTest(
          "optional type conversions",
          () -> {
            Schema valueOptionalDefault = SchemaBuilder.int64().optional().defaultValue(0L);
            assertAll(
                "checks",
                () ->
                    assertThrows(
                        DataException.class, () -> converter.toBson(null, Schema.INT64_SCHEMA)),
                () ->
                    assertEquals(
                        new BsonNull(), converter.toBson(null, Schema.OPTIONAL_INT64_SCHEMA)),
                () ->
                    assertEquals(
                        (long) valueOptionalDefault.defaultValue(),
                        ((BsonInt64) converter.toBson(null, valueOptionalDefault)).getValue()));
          }));

  return tests;
}
 
源代码28 项目: mongo-kafka   文件: SinkFieldConverterTest.java
@TestFactory
@DisplayName("tests for float32 field conversions")
List<DynamicTest> testFloat32FieldConverter() {
  SinkFieldConverter converter = new Float32FieldConverter();
  List<DynamicTest> tests = new ArrayList<>();

  asList(Float.MIN_VALUE, 0f, Float.MAX_VALUE)
      .forEach(
          el ->
              tests.add(
                  dynamicTest(
                      "conversion with " + converter.getClass().getSimpleName() + " for " + el,
                      () ->
                          assertEquals(
                              (float) el, ((BsonDouble) converter.toBson(el)).getValue()))));

  tests.add(
      dynamicTest(
          "optional type conversions",
          () -> {
            Schema valueOptionalDefault = SchemaBuilder.float32().optional().defaultValue(0.0f);
            assertAll(
                "checks",
                () ->
                    assertThrows(
                        DataException.class, () -> converter.toBson(null, Schema.FLOAT32_SCHEMA)),
                () ->
                    assertEquals(
                        new BsonNull(), converter.toBson(null, Schema.OPTIONAL_FLOAT32_SCHEMA)),
                () ->
                    assertEquals(
                        ((Float) valueOptionalDefault.defaultValue()).doubleValue(),
                        ((BsonDouble) converter.toBson(null, valueOptionalDefault)).getValue()));
          }));

  return tests;
}
 
源代码29 项目: mongo-kafka   文件: SinkFieldConverterTest.java
@TestFactory
@DisplayName("tests for float64 field conversions")
List<DynamicTest> testFloat64FieldConverter() {
  SinkFieldConverter converter = new Float64FieldConverter();
  List<DynamicTest> tests = new ArrayList<>();

  asList(Double.MIN_VALUE, 0d, Double.MAX_VALUE)
      .forEach(
          el ->
              tests.add(
                  dynamicTest(
                      "conversion with " + converter.getClass().getSimpleName() + " for " + el,
                      () ->
                          assertEquals(
                              (double) el, ((BsonDouble) converter.toBson(el)).getValue()))));

  tests.add(
      dynamicTest(
          "optional type conversions",
          () -> {
            Schema valueOptionalDefault = SchemaBuilder.float64().optional().defaultValue(0.0d);
            assertAll(
                "checks",
                () ->
                    assertThrows(
                        DataException.class, () -> converter.toBson(null, Schema.FLOAT64_SCHEMA)),
                () ->
                    assertEquals(
                        new BsonNull(), converter.toBson(null, Schema.OPTIONAL_FLOAT64_SCHEMA)),
                () ->
                    assertEquals(
                        valueOptionalDefault.defaultValue(),
                        ((BsonDouble) converter.toBson(null, valueOptionalDefault)).getValue()));
          }));
  return tests;
}
 
源代码30 项目: mongo-kafka   文件: SinkFieldConverterTest.java
@TestFactory
@DisplayName("tests for string field conversions")
List<DynamicTest> testStringFieldConverter() {
  SinkFieldConverter converter = new StringFieldConverter();
  List<DynamicTest> tests = new ArrayList<>();

  asList("fooFOO", "", "blahBLAH")
      .forEach(
          el ->
              tests.add(
                  dynamicTest(
                      "conversion with " + converter.getClass().getSimpleName() + " for " + el,
                      () -> assertEquals(el, ((BsonString) converter.toBson(el)).getValue()))));

  tests.add(
      dynamicTest(
          "optional type conversions",
          () -> {
            Schema valueOptionalDefault = SchemaBuilder.string().optional().defaultValue("");
            assertAll(
                "checks",
                () ->
                    assertThrows(
                        DataException.class, () -> converter.toBson(null, Schema.STRING_SCHEMA)),
                () ->
                    assertEquals(
                        new BsonNull(), converter.toBson(null, Schema.OPTIONAL_STRING_SCHEMA)),
                () ->
                    assertEquals(
                        valueOptionalDefault.defaultValue(),
                        ((BsonString) converter.toBson(null, valueOptionalDefault)).getValue()));
          }));

  return tests;
}
 
 类所在包
 同包方法