@ParameterizedTest @EnumSource(StatsdFlavor.class) void timerLineProtocol(StatsdFlavor flavor) { String line = null; switch (flavor) { case Etsy: line = "myTimer.myTag.val:1|ms"; break; case Datadog: line = "my.timer:1|ms|#my.tag:val"; break; case Telegraf: line = "my_timer,my_tag=val:1|ms"; } assertLines(r -> r.timer("my.timer", "my.tag", "val").record(1, TimeUnit.MILLISECONDS), flavor, line); }
@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 @EnumSource(Color.Preset.class) void testPresetStrings(Color.Preset preset) { Color color = Color.of(preset.toString()); assertValid(color); assertTrue(color.isPreset()); assertThat(color.asPreset(), is(equalTo(preset))); }
@ParameterizedTest @ValueSource(strings = { "Hello", "World" }) void testWithStrings(String argument) { System.out.println( "Parameterized test with (String) parameter: " + argument); assertNotNull(argument); }
@ParameterizedTest @ValueSource(longs = { 2L, 3L }) void testWithLongs(long argument) { System.out.println( "Parameterized test with (long) argument: " + argument); assertNotNull(argument); }
@ParameterizedTest @EnumSource(value = TimeUnit.class, mode = EXCLUDE, names = { "DAYS", "HOURS" }) void testWithExcludeEnum(TimeUnit argument) { System.out.println( "Parameterized test with excluded (TimeUnit) argument: " + argument); assertNotNull(argument); }
@ParameterizedTest(name = "\"{0}\" is serialization of {1}") @MethodSource(value = "unitSelectionPointTypeMappings") void serializesToSc2ApiUnitSelectionPointType( Spatial.ActionSpatialUnitSelectionPoint.Type expectedSc2ApiSelectionPointType, ActionSpatialUnitSelectionPoint.Type selectionPointType) { assertThat(selectionPointType.toSc2Api()).isEqualTo(expectedSc2ApiSelectionPointType); }
@ParameterizedTest(name = "\"{0}\" is serialization of {1}") @MethodSource(value = "controlGroupActionMappings") void serializesToSc2ApiControlGroupAction( Ui.ActionControlGroup.ControlGroupAction expectedSc2ApiControlGroupAction, ActionUiControlGroup.Action controlGroupAction) { assertThat(controlGroupAction.toSc2Api()).isEqualTo(expectedSc2ApiControlGroupAction); }
@ParameterizedTest @ArgumentsSources({ @ArgumentsSource(CustomArgumentsProvider1.class), @ArgumentsSource(CustomArgumentsProvider2.class) }) void testWithArgumentsSource(String first, int second) { System.out.println("Parameterized test with (String) " + first + " and (int) " + second); assertNotNull(first); assertTrue(second > 0); }
@ParameterizedTest @MethodSource("longProvider") void testWithLongProvider(long argument) { System.out.println( "Parameterized test with (long) argument: " + argument); assertNotNull(argument); }
@ParameterizedTest @MethodSource("stringProvider") void testWithStringProvider(String argument) { System.out.println( "Parameterized test with (String) argument: " + argument); assertNotNull(argument); }
@ParameterizedTest @ValueSource(doubles = { 4d, 5d }) void testWithDoubles(double argument) { System.out.println( "Parameterized test with (double) argument: " + argument); assertNotNull(argument); }
@ParameterizedTest @ValueSource(strings = "SECONDS") void testWithImplicitConversionToEnum(TimeUnit argument) { System.out.println("Argument " + argument + " is a type of " + argument.getDeclaringClass()); assertNotNull(argument.name()); }
@ParameterizedTest @EnumSource(value = TimeUnit.class, mode = MATCH_ALL, names = "^(M|N).+SECONDS$") void testWithRegexEnum(TimeUnit argument) { System.out.println( "Parameterized test with regex filtered (TimeUnit) argument: " + argument); assertNotNull(argument); }
@DisplayName("Display name of test container") @ParameterizedTest(name = "[{index}] first argument=\"{0}\", second argument={1}") @CsvSource({ "mastering, 1", "parameterized, 2", "tests, 3" }) void testWithCustomDisplayNames(String first, int second) { System.out.println( "Testing with parameters: " + first + " and " + second); }
@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 @EnumSource(TimeUnit.class) void testWithEnum(TimeUnit argument) { System.out.println( "Parameterized test with (TimeUnit) argument: " + argument); assertNotNull(argument); }
@ParameterizedTest(name = "\"{0}\" is mapped to {1}") @MethodSource(value = "responseReplayInfoErrorMappings") void mapsSc2ApiResponseGameError( Sc2Api.ResponseReplayInfo.Error sc2ApiResponseReplayInfoError, ResponseReplayInfo.Error expectedResponseReplayInfoError) { assertThat(ResponseReplayInfo.Error.from(sc2ApiResponseReplayInfoError)) .isEqualTo(expectedResponseReplayInfoError); }
@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("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 @EnumSource(QueryType.class) void allQueriesShouldHandleNullValueForUnary(final QueryType queryType) { final DatabaseValidation validation = new DatabaseValidation(context, queries.get(queryType)); final ValidationResult result = validation.validate(getValidUnaryWithNulls()); assertThat(result.isValid()).isTrue(); }
@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("intProvider") void testWithIntProvider(int argument) { System.out .println("Parameterized test with (int) argument: " + argument); assertNotNull(argument); }
@ParameterizedTest @ArgumentsSource(SerializedAttachmentsProvider.class) void testDeserialization(JsonNode json) { MoreAssertions.assertSerializable(json, Attachment.class, AttachmentTests::assertValid); }
@ParameterizedTest @MethodSource("goodStringParsableAndResult") void parse(final String argument, final List<String> expected) { Assertions.assertEquals(expected, FilterMultipleValueParser.ofIdentity().parse(argument)); Assertions.assertEquals(expected.size(), FilterMultipleValueParser.ofIdentity().parse(argument).size()); Assertions.assertEquals(expected, FilterMultipleValueParser.ofIdentity().parse(argument, ",")); }
@ParameterizedTest @ArgumentsSource(SerializedFootersProvider.class) void testDeserialization(JsonNode json) { MoreAssertions.assertSerializable(json, Footer.class, FooterTests::assertValid); }
@ParameterizedTest @MethodSource("valuesStream") void getValue(final Value value) { for (int i = 0; i < value.size(); i++) { Assertions.assertNotNull(value.getValue(i)); } }
@ParameterizedTest @MethodSource("histogramTypes") void expectedValueRangeValidation(Class<? extends TimeWindowHistogramBase<?, ?>> histogramType) throws Exception { expectValidationFailure(histogramType, HistogramConfig.builder() .minimumExpectedValue(0L) .build()); expectValidationFailure(histogramType, HistogramConfig.builder() .minimumExpectedValue(10L) .maximumExpectedValue(9L) .build()); }
@ParameterizedTest @ArgumentsSource(MessageRequestProvider.class) void testSendMessage(MessageRequest messageRequest, TestInfo testInfo) { assertThat(SlackWebHookService.with(assumingEnvironmentWebHookToken()) .sendMessage(EnrichTestMessageRequest.get().apply(messageRequest, testInfo)), is(equalTo(ResponseCode.OK))); }
@ParameterizedTest @MethodSource("histogramTypes") void bufferLengthValidation(Class<? extends TimeWindowHistogramBase<?, ?>> histogramType) throws Exception { expectValidationFailure(histogramType, HistogramConfig.builder() .histogramBufferLength(-1) .build()); }
@ParameterizedTest @ValueSource(strings = "2017-07-25") void testWithImplicitConversionToLocalDate(LocalDate argument) { System.out.println("Argument " + argument + " is a type of " + argument.getClass()); assertNotNull(argument); }
@ParameterizedTest @ValueSource(ints = { 0, 1 }) void testWithInts(int argument) { System.out .println("Parameterized test with (int) argument: " + argument); assertNotNull(argument); }
@ParameterizedTest @ArgumentsSource(SerializedFieldsProvider.class) void testSerialization(JsonNode json) { MoreAssertions.assertSerializable(json, Field.class, FieldTests::assertValid); }
@ParameterizedTest @EnumSource(StatsdFlavor.class) void longTaskTimerLineProtocol(StatsdFlavor flavor) { final Function<MeterRegistry, LongTaskTimer> ltt = r -> r.more().longTaskTimer("my.long.task", "my.tag", "val"); StepVerifier .withVirtualTime(() -> { String[] lines = null; switch (flavor) { case Etsy: lines = new String[]{ "myLongTask.myTag.val.statistic.activetasks:1|c", "myLongTaskDuration.myTag.val.statistic.value:1|c", }; break; case Datadog: lines = new String[]{ "my.long.task:1|c|#statistic:activetasks,myTag:val", "my.long.task:1|c|#statistic:duration,myTag:val", }; break; case Telegraf: lines = new String[]{ "myLongTask,statistic=activetasks,myTag=val:1|c", "myLongTask,statistic=duration,myTag=val:1|c", }; } assertLines(r -> ltt.apply(r).start(), flavor, lines); return null; }) .then(() -> mockClock.add(10, TimeUnit.MILLISECONDS)) .thenAwait(Duration.ofMillis(10)); }
@ParameterizedTest(name = "\"{0}\" is mapped to {1}") @MethodSource(value = "responseCreateGameErrorMappings") void mapsSc2ApiResponseCreateGameError( Sc2Api.ResponseCreateGame.Error sc2ApiResponseCreateGameError, ResponseCreateGame.Error expectedResponseCreateGameError) { assertThat(ResponseCreateGame.Error.from(sc2ApiResponseCreateGameError)) .isEqualTo(expectedResponseCreateGameError); }
@ParameterizedTest @ArgumentsSource(SerializedColorsProvider.class) void testSerialization(JsonNode json) { MoreAssertions.assertSerializable(json, Color.class, ColorTests::assertValid); }
@DisplayName("Command without params should be called with an empty DeviceParams object") @ParameterizedTest(name = "Command is {0}") @EnumSource(DeviceParamsProducingCommand.class) void commandsEmptyParamsNullableFields(DeviceParamsProducingCommand source) throws Exception { DevicesParams value = runDeviceParamsTest(source, ""); assertNull(value.getAbi()); assertNull(value.getNameFilterDescription()); assertNull(value.getProviderFilterDescription()); assertNull(value.getSerialFilterDescription()); assertEquals(0, value.getApiVersion()); assertEquals(0, value.getMaxApiVersion()); assertEquals(0, value.getMinApiVersion()); assertEquals(0, value.getCount()); assertFalse(value.isAllDevices()); }