@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")); }
@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; } }
@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()); }
@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); }
@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(); }
@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); }
@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)); }
@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()); }
@ParameterizedTest @MethodSource("personProvider") void testWithPersonProvider(Person argument) { System.out.println( "Parameterized test with (Person) argument: " + argument); assertNotNull(argument); }
@ParameterizedTest @MethodSource("intProvider") void testWithIntProvider(int argument) { System.out .println("Parameterized test with (int) argument: " + argument); assertNotNull(argument); }
@ParameterizedTest @MethodSource("doubleProvider") void testWithDoubleProvider(double argument) { System.out.println( "Parameterized test with (double) argument: " + argument); assertNotNull(argument); }
@ParameterizedTest @MethodSource("longProvider") void testWithLongProvider(long argument) { System.out.println( "Parameterized test with (long) argument: " + argument); assertNotNull(argument); }
@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); } } ); }
@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); }
@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); }
@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); }
@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); }
@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); }
@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()); }
@ParameterizedTest @MethodSource("histogramTypes") void slaBoundariesValidation(Class<? extends TimeWindowHistogramBase<?, ?>> histogramType) throws Exception { expectValidationFailure(histogramType, HistogramConfig.builder() .sla(0L) .build()); }
@ParameterizedTest @MethodSource("histogramTypes") void bufferLengthValidation(Class<? extends TimeWindowHistogramBase<?, ?>> histogramType) throws Exception { expectValidationFailure(histogramType, HistogramConfig.builder() .histogramBufferLength(-1) .build()); }
@ParameterizedTest @MethodSource("histogramTypes") void rotationIntervalValidation(Class<? extends TimeWindowHistogramBase<?, ?>> histogramType) throws Exception { expectValidationFailure(histogramType, HistogramConfig.builder() .histogramExpiry(Duration.ofMillis(9)) .histogramBufferLength(10) .build()); }
@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); }
@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); }
@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); }
@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()) ); }
@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(); }); }
@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")); }
@ParameterizedTest @MethodSource("stringProvider") void testWithStringProvider(String argument) { System.out.println( "Parameterized test with (String) argument: " + argument); assertNotNull(argument); }
@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))); }
@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"))); }
@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"))); }
@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, ",")); }
@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); }
@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, ",")); }
@ParameterizedTest // @ValueSource(strings = { // // "mom", // // "dad", // // "radar", // // "racecar", // // "able was I ere I saw elba"// // }) @MethodSource("candidates") void palindromes(String candidate) { assertTrue(isPalindrome(candidate)); }
@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); }