Java 类org.junit.jupiter.params.provider.MethodSource 实例源码

项目:selenium-jupiter    文件:FirefoxAnnotationReaderTest.java   
@ParameterizedTest
@MethodSource("testClassProvider")
@SuppressWarnings("unchecked")
void testFirefoxOptions(Class<?> testClass) throws Exception {
    Parameter parameter = testClass
            .getMethod("webrtcTest", FirefoxDriver.class)
            .getParameters()[0];
    Optional<Object> testInstance = Optional.of(testClass.newInstance());

    FirefoxOptions firefoxOptions = (FirefoxOptions) annotationsReader
            .getOptions(parameter, testInstance);
    Map<String, Map<String, Boolean>> options = (Map<String, Map<String, Boolean>>) firefoxOptions
            .asMap().get(FIREFOX_OPTIONS);

    assertTrue(options.get("prefs")
            .get("media.navigator.permission.disabled"));
    assertTrue(options.get("prefs").get("media.navigator.streams.fake"));
}
项目:java-9-wtf    文件:BootstrapLoaderTest.java   
@ParameterizedTest(name = "loading {0}")
@MethodSource(value = "classNames")
public void loadJdkClass(String className, TestReporter reporter) throws ClassNotFoundException {
    TestClassLoader classLoader = new TestClassLoader();

    try {
        Class c = classLoader.loadClass(className);
        reporter.publishEntry(className, "visible");
        // the assertion is pretty useless, but if `c` would not be used,
        // dead code elimination might remove it
        assertThat(c.getName()).isEqualTo(className);
    } catch (ClassNotFoundException ex) {
        reporter.publishEntry(className, "not visible");
        throw ex;
    }
}
项目:filter-sort-jooq-api    文件:ValueTest.java   
@ParameterizedTest
@MethodSource("valuesStream")
void valueWithGetterNumbered(final Value value) {
    final int size = value.size();
    Assertions.assertNotNull(((Value1) value).value1());

    if (size > 1)
        Assertions.assertNotNull(((Value2) value).value2());

    if (size > 2)
        Assertions.assertNotNull(((Value3) value).value3());

    if (size > 3)
        Assertions.assertNotNull(((Value4) value).value4());

    if (size > 4)
        Assertions.assertNotNull(((Value5) value).value5());

    if (size > 5)
        Assertions.assertNotNull(((Value6) value).value6());
}
项目:filter-sort-jooq-api    文件:ValueTest.java   
@ParameterizedTest
@MethodSource("valuesStream")
void valueWithGetterNumberedThrowsOutOfRange(final Value value) {
    final int size = value.size();

    // No class cast exception as Value == ValueImpl (supposedly)
    if (size <= 1)
        Assertions.assertThrows(IndexOutOfBoundsException.class, ((Value2) value)::value2);

    if (size <= 2)
        Assertions.assertThrows(IndexOutOfBoundsException.class, ((Value3) value)::value3);

    if (size <= 3)
        Assertions.assertThrows(IndexOutOfBoundsException.class, ((Value4) value)::value4);

    if (size <= 4)
        Assertions.assertThrows(IndexOutOfBoundsException.class, ((Value5) value)::value5);

    if (size <= 5)
        Assertions.assertThrows(IndexOutOfBoundsException.class, ((Value6) value)::value6);
}
项目:qpp-conversion-tool    文件:CpcPlusAcceptanceTest.java   
@ParameterizedTest
@MethodSource("successData")
void testCpcPlusFileSuccesses(Path entry) throws IOException {
    AllErrors errors = null;

    Converter converter = new Converter(new PathSource(entry));

    try {
        converter.transform();
    } catch (TransformException failure) {
        errors = failure.getDetails();
    }

    assertThat(errors).isNull();
}
项目:qpp-conversion-tool    文件:CpcPlusAcceptanceTest.java   
@ParameterizedTest
@MethodSource("failureData")
void testCpcPlusFileFailures(Path entry) throws IOException {
    String fileName = entry.getFileName().toString();
    assertWithMessage("No associated entry in fixture.json for the file %s", fileName).that(fixtureValues).containsKey(fileName);

    Converter converter = new Converter(new PathSource(entry));

    TransformException expected = Assertions.assertThrows(TransformException.class, converter::transform);
    //runnning conversions on individual files
    List<Detail> details = expected.getDetails().getErrors().get(0).getDetails();
    verifyOutcome(fileName, details);
}
项目:qpp-conversion-tool    文件:JsonPathToXpathCoverageTest.java   
@ParameterizedTest
@MethodSource("paths")
void testCoverage(Path path) throws IOException {
    JsonWrapper metaWrapper = new JsonWrapper(false);
    helper = new JsonPathToXpathHelper(path, metaWrapper, false);
    JsonWrapper wrapper = new JsonWrapper(metaWrapper, true);
    JsonNode root = om.readTree(wrapper.toString());
    JsonPathAggregator agg = new JsonPathAggregator(root);

    agg.getJsonPaths().forEach((key, value) -> helper.executeAttributeTest(key, value));
}
项目:qpp-conversion-tool    文件:UnprocessedCpcFileDataTest.java   
@ParameterizedTest
@MethodSource("metadataProvider")
void testConstructor(Metadata metadata) {

    UnprocessedCpcFileData cpcFileData = new UnprocessedCpcFileData(metadata);

    assertThat(cpcFileData.getFileId()).isEqualTo(metadata.getUuid());
    assertThat(cpcFileData.getFilename()).isEqualTo(metadata.getFileName());
    assertThat(cpcFileData.getApm()).isEqualTo(metadata.getApm());
    assertThat(cpcFileData.getConversionDate()).isEqualTo(metadata.getCreatedDate().toString());
    assertThat(cpcFileData.getValidationSuccess()).isEqualTo(metadata.getOverallStatus());
}
项目:mastering-junit5    文件:MethodSourceObjectsParameterizedTest.java   
@ParameterizedTest
@MethodSource("personProvider")
void testWithPersonProvider(Person argument) {
    System.out.println(
            "Parameterized test with (Person) argument: " + argument);
    assertNotNull(argument);
}
项目:mastering-junit5    文件:MethodSourcePrimitiveTypesParameterizedTest.java   
@ParameterizedTest
@MethodSource("intProvider")
void testWithIntProvider(int argument) {
    System.out
            .println("Parameterized test with (int) argument: " + argument);
    assertNotNull(argument);
}
项目:mastering-junit5    文件:MethodSourcePrimitiveTypesParameterizedTest.java   
@ParameterizedTest
@MethodSource("doubleProvider")
void testWithDoubleProvider(double argument) {
    System.out.println(
            "Parameterized test with (double) argument: " + argument);
    assertNotNull(argument);
}
项目:mastering-junit5    文件:MethodSourcePrimitiveTypesParameterizedTest.java   
@ParameterizedTest
@MethodSource("longProvider")
void testWithLongProvider(long argument) {
    System.out.println(
            "Parameterized test with (long) argument: " + argument);
    assertNotNull(argument);
}
项目:auto-value-step-builder    文件:GeneratorTest.java   
@ParameterizedTest
@MethodSource("inputSourceBlocks")
public void printAllGenerated(List<String> block) throws IOException {

    List<JavaFileObject> sourceJavaFileObject = getResourceStrings("input", block);

    AutoValueProcessor processor = new AutoValueProcessor();

    Compilation compilation = javac().withProcessors(processor).compile(sourceJavaFileObject);

    ImmutableList<JavaFileObject> javaFileObjects = ImmutableList.<JavaFileObject>builder()
            .addAll(compilation.generatedSourceFiles())
            .build();
    String destination = "src/test/resources/expected";
    Files.createDirectories(Paths.get(destination));

    javaFileObjects.forEach(
            generated -> {
                try {
                    String fileName = destination + generated.getName().replace("SOURCE_OUTPUT/", "");
                    Path parent = Paths.get(fileName).getParent();
                    Files.createDirectories(parent);

                    try (PrintWriter printWriter = new PrintWriter(fileName)) {
                        printWriter.println(generated.getCharContent(true).toString());
                    }
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
    );
}
项目:mastering-junit5    文件:MethodSourceMixedTypesParameterizedTest.java   
@ParameterizedTest
@MethodSource("stringAndIntProvider")
void testWithMultiArgMethodSource(String first, int second) {
    System.out.println("Parameterized test with two arguments: (String) "
            + first + " and (int) " + second);

    assertNotNull(first);
    assertNotEquals(0, second);
}
项目:fuse-nio-adapter    文件:OpenOptionsUtilTest.java   
@ParameterizedTest
@MethodSource("openOptionsProvider")
public void testOpenFlagsMaskToSet(Set<OpenOption> expectedOptions, Set<OpenFlags> flags) {
    BitMaskEnumUtil enumUtil = Mockito.mock(BitMaskEnumUtil.class);
    Mockito.verifyNoMoreInteractions(enumUtil);
    OpenOptionsUtil util = new OpenOptionsUtil(enumUtil);
    Set<OpenOption> options = util.fuseOpenFlagsToNioOpenOptions(flags);
    Assertions.assertEquals(expectedOptions, options);
}
项目:fuse-nio-adapter    文件:BitMaskEnumUtilTest.java   
@ParameterizedTest
@MethodSource("argumentsProvider")
public void testBitMaskToSet(Set<TestEnum> expectedSet, long mask) {
    BitMaskEnumUtil util = new BitMaskEnumUtil();
    Set<TestEnum> set = util.bitMaskToSet(TestEnum.class, mask);
    Assertions.assertEquals(expectedSet, set);
}
项目:fuse-nio-adapter    文件:FileAttributesUtilTest.java   
@ParameterizedTest
@MethodSource("accessModeProvider")
public void testAccessModeMaskToSet(Set<AccessMode> expectedModes, int mask) {
    FileAttributesUtil util = new FileAttributesUtil();
    Set<AccessMode> accessModes = util.accessModeMaskToSet(mask);
    Assertions.assertEquals(expectedModes, accessModes);
}
项目:fuse-nio-adapter    文件:FileAttributesUtilTest.java   
@ParameterizedTest
@MethodSource("filePermissionProvider")
public void testOctalModeToPosixPermissions(Set<PosixFilePermission> expectedPerms, long octalMode) {
    FileAttributesUtil util = new FileAttributesUtil();
    Set<PosixFilePermission> perms = util.octalModeToPosixPermissions(octalMode);
    Assertions.assertEquals(expectedPerms, perms);
}
项目:micrometer    文件:TimeWindowRotationTest.java   
@ParameterizedTest
@MethodSource("histogramTypes")
void percentilesValidation(Class<? extends TimeWindowHistogramBase<?, ?>> histogramType) throws Exception {
    expectValidationFailure(histogramType, HistogramConfig.builder()
                                                          .percentiles(-0.01)
                                                          .build());
    expectValidationFailure(histogramType, HistogramConfig.builder()
                                                          .percentiles(1.01)
                                                          .build());
}
项目:micrometer    文件:TimeWindowRotationTest.java   
@ParameterizedTest
@MethodSource("histogramTypes")
void slaBoundariesValidation(Class<? extends TimeWindowHistogramBase<?, ?>> histogramType) throws Exception {
    expectValidationFailure(histogramType, HistogramConfig.builder()
                                                          .sla(0L)
                                                          .build());
}
项目:micrometer    文件:TimeWindowRotationTest.java   
@ParameterizedTest
@MethodSource("histogramTypes")
void bufferLengthValidation(Class<? extends TimeWindowHistogramBase<?, ?>> histogramType) throws Exception {
    expectValidationFailure(histogramType, HistogramConfig.builder()
                                                          .histogramBufferLength(-1)
                                                          .build());
}
项目:micrometer    文件:TimeWindowRotationTest.java   
@ParameterizedTest
@MethodSource("histogramTypes")
void rotationIntervalValidation(Class<? extends TimeWindowHistogramBase<?, ?>> histogramType) throws Exception {
    expectValidationFailure(histogramType, HistogramConfig.builder()
                                                          .histogramExpiry(Duration.ofMillis(9))
                                                          .histogramBufferLength(10)
                                                          .build());
}
项目:stf-console-client    文件:ConnectCommandTest.java   
@DisplayName("Valid index leads to DeviceParams instance creation")
@ParameterizedTest(name = "\"connect -l {0}\" creates DeviceParams with serial {1}")
@MethodSource("validIndexArrayProvider")
void connectToEachCacheItem(int parameter, String targetSerial) throws IOException {
    prepareMocks();
    connectCommand.setDevicesIndexesFromCache(Collections.singletonList(parameter));
    connectCommand.execute().test().assertComplete();
    verify(farmClient).connectToDevices(paramsCaptor.capture());
    assertDeviceInParams(targetSerial);
}
项目:ocraft-s2client    文件:ResponseRestartGameTest.java   
@ParameterizedTest(name = "\"{0}\" is mapped to {1}")
@MethodSource(value = "responseRestartGameErrorMappings")
void mapsSc2ApiResponseGameError(
        Sc2Api.ResponseRestartGame.Error sc2ApiResponseRestartGameError,
        ResponseRestartGame.Error expectedResponseRestartGameError) {
    assertThat(ResponseRestartGame.Error.from(sc2ApiResponseRestartGameError))
            .isEqualTo(expectedResponseRestartGameError);
}
项目:ocraft-s2client    文件:ActionSpatialUnitSelectionPointTest.java   
@ParameterizedTest(name = "\"{0}\" is mapped to {1}")
@MethodSource(value = "unitSelectionPointTypeMappings")
void mapsSc2ApiUnitSelectionPointType(
        Spatial.ActionSpatialUnitSelectionPoint.Type sc2ApiUnitSelectionPointType,
        ActionSpatialUnitSelectionPoint.Type expectedUnitSelectionPointType) {
    assertThat(ActionSpatialUnitSelectionPoint.Type.from(sc2ApiUnitSelectionPointType))
            .isEqualTo(expectedUnitSelectionPointType);
}
项目:shuffleboard    文件:DifferentialDriveWidgetTest.java   
@ParameterizedTest
@MethodSource("createMapArgs")
public void testMap(Number expected, Number x, Number minInput, Number maxInput, Number minOutput, Number maxOutput) {
  assertEquals(
      expected.doubleValue(),
      DifferentialDriveWidget.map(
          x.doubleValue(),
          minInput.doubleValue(), maxInput.doubleValue(),
          minOutput.doubleValue(), maxOutput.doubleValue())
  );
}
项目:selenium-jupiter    文件:ForcedAnnotationReaderTest.java   
@ParameterizedTest
@MethodSource("forcedTestProvider")
void forcedTest(Class<? extends DriverHandler> handler, Class<?> testClass,
        Class<?> driverClass, String testName) throws Exception {
    Parameter parameter = testClass.getMethod(testName, driverClass)
            .getParameters()[0];
    assertThrows(SeleniumJupiterException.class, () -> {
        handler.getDeclaredConstructor(Parameter.class,
                ExtensionContext.class).newInstance(parameter, null)
                .resolve();
    });
}
项目:selenium-jupiter    文件:EdgeAnnotationReaderTest.java   
@ParameterizedTest
@MethodSource("testClassProvider")
void testEdgeOptions(Class<?> testClass) throws Exception {
    Parameter parameter = testClass.getMethod("edgeTest", EdgeDriver.class)
            .getParameters()[0];
    Optional<Object> testInstance = Optional.of(testClass.newInstance());
    EdgeOptions edgeOptions = (EdgeOptions) annotationsReader
            .getOptions(parameter, testInstance);
    assertThat(edgeOptions.getCapability("pageLoadStrategy"),
            equalTo("eager"));
}
项目:Mastering-Software-Testing-with-JUnit-5    文件:MethodSourcePrimitiveTypesParameterizedTest.java   
@ParameterizedTest
@MethodSource("intProvider")
void testWithIntProvider(int argument) {
    System.out
            .println("Parameterized test with (int) argument: " + argument);
    assertNotNull(argument);
}
项目:Mastering-Software-Testing-with-JUnit-5    文件:MethodSourcePrimitiveTypesParameterizedTest.java   
@ParameterizedTest
@MethodSource("doubleProvider")
void testWithDoubleProvider(double argument) {
    System.out.println(
            "Parameterized test with (double) argument: " + argument);
    assertNotNull(argument);
}
项目:Mastering-Software-Testing-with-JUnit-5    文件:MethodSourcePrimitiveTypesParameterizedTest.java   
@ParameterizedTest
@MethodSource("longProvider")
void testWithLongProvider(long argument) {
    System.out.println(
            "Parameterized test with (long) argument: " + argument);
    assertNotNull(argument);
}
项目:Mastering-Software-Testing-with-JUnit-5    文件:MethodSourceStringsParameterizedTest.java   
@ParameterizedTest
@MethodSource("stringProvider")
void testWithStringProvider(String argument) {
    System.out.println(
            "Parameterized test with (String) argument: " + argument);
    assertNotNull(argument);
}
项目:roboslack    文件:StringDecoratorTests.java   
@ParameterizedTest
@MethodSource(value = "validDecorators")
void testDecorate(StringDecorator decorator) {
    String decorated = decorator.decorate(EXAMPLE_INPUT_STRING);
    assertThat(decorated, is(not(equalTo(EXAMPLE_INPUT_STRING))));
    decorator.prefix().ifPresent(prefix ->
            assertTrue(decorated.startsWith(prefix)));
    decorator.suffix().ifPresent(suffix ->
            assertTrue(decorated.endsWith(suffix)));
}
项目:roboslack    文件:AttachmentTests.java   
@ParameterizedTest
@MethodSource(value = "invalidConstructors")
void testConstructionConstraints(Executable executable) {
    Throwable thrown = assertThrows(IllegalArgumentException.class, executable);
    assertThat(thrown.getMessage(), either(containsString("cannot be null or empty"))
            .or(containsString("cannot contain markdown")));
}
项目:roboslack    文件:TitleTests.java   
@ParameterizedTest
@MethodSource(value = "invalidConstructors")
void testConstructionConstraints(Executable executable) {
    Throwable thrown = assertThrows(IllegalArgumentException.class, executable);
    assertThat(thrown.getMessage(),
            either(containsString("cannot contain markdown"))
                    .or(containsString("cannot be null or empty")));
}
项目:filter-sort-jooq-api    文件:FilterMultipleValueParserIntTest.java   
@ParameterizedTest
@MethodSource("goodStringParsableAndResult")
void parse(final String argument, final List<Integer> expected) {
    Assertions.assertEquals(expected, FilterMultipleValueParser.ofInt().parse(argument));
    Assertions.assertEquals(expected.size(), FilterMultipleValueParser.ofInt().parse(argument).size());
    Assertions.assertEquals(expected, FilterMultipleValueParser.ofInt().parse(argument, ","));
}
项目:ocraft-s2client    文件:ResponseJoinGameTest.java   
@ParameterizedTest(name = "\"{0}\" is mapped to {1}")
@MethodSource(value = "responseJoinGameErrorMappings")
void mapsSc2ApiResponseGameError(
        Sc2Api.ResponseJoinGame.Error sc2ApiResponseJoinGameError,
        ResponseJoinGame.Error expectedResponseJoinGameError) {
    assertThat(ResponseJoinGame.Error.from(sc2ApiResponseJoinGameError)).isEqualTo(expectedResponseJoinGameError);
}
项目:filter-sort-jooq-api    文件:FilterMultipleValueParserTimeTest.java   
@ParameterizedTest
@MethodSource("goodStringParsableAndResult")
void parse(final String argument, final List<LocalTime> expected) {
    Assertions.assertEquals(expected, FilterMultipleValueParser.ofTime().parse(argument));
    Assertions.assertEquals(expected.size(), FilterMultipleValueParser.ofTime().parse(argument).size());
    Assertions.assertEquals(expected, FilterMultipleValueParser.ofTime().parse(argument, ","));
}
项目:junit5-demo    文件:ParameterizedTests.java   
@ParameterizedTest
//  @ValueSource(strings = { //
//          "mom", //
//          "dad", //
//          "radar", //
//          "racecar", //
//          "able was I ere I saw elba"//
//  })
@MethodSource("candidates")
void palindromes(String candidate) {
    assertTrue(isPalindrome(candidate));
}
项目:solidity-ide    文件:ReferenceExamplesTest.java   
@ParameterizedTest
@MethodSource("getReferenceFiles")
public void test_parseReferenceFile(Path path) throws Exception {
    String content = new String(Files.readAllBytes(path));
    SolidityModel model = parseHelper.parse(content, URI.createFileURI(path.toAbsolutePath().toString()), set);
    Assert.assertNotNull("Could not load model " + path, model);
    validationHelper.assertNoErrors(model);
}