微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

org.junit.jupiter.params.provider.ArgumentsSource的实例源码

项目:autotest    文件AutoTestExtension.java   
@Override
public Stream<TestTemplateInvocationContext> provideTestTemplateInvocationContexts(ExtensionContext context) {
    Method templateMethod = Preconditions.notNull(context.getTestMethod().orElse(null),"test method must not be null");
    AutoTestNameFormatter formatter = createNameFormatter(templateMethod);
    AtomicLong invocationCount = new AtomicLong(0L);
    return (Stream) findRepeatableAnnotations(templateMethod,ArgumentsSource.class)
            .stream()
            .map(ArgumentsSource::value)
            .map(ReflectionUtils::newInstance)
            .map(provider -> AnnotationConsumerInitializer.initialize(templateMethod,provider))
            .flatMap(provider -> arguments(provider,context))
            .map(Arguments::get)
            .map((arguments) -> {
                return new AutoTestInvocationContext(formatter,arguments);
            })
            .peek((invocationContext) -> {
                invocationCount.incrementAndGet();
            }).onClose(() -> {
                Preconditions.condition(invocationCount.get() > 0L,() -> {
                    return "当使用注解 @" + AutoTest.class.getSimpleName() + " 的时候,测试方法需要至少一个参数";
                });
            });

}
项目:patience    文件PatientWaitFutureTest.java   
@ParameterizedTest
@displayName("it returns successfully with valid arguments")
@ArgumentsSource(ValidArgumentsProvider.class)
void testValidArgumentsSucceed(Sleep sleep,Duration initialDelay,Duration defaultTimeout,PatientExecutionHandler executionHandler,DelaysupplierFactory delaysupplierFactory,PatientExecutable<Boolean> executable,Predicate<Boolean> filter,supplier<String> messagesupplier) {
    try {
        Assertions.assertNotNull(getInstance(sleep,initialDelay,defaultTimeout,executionHandler,delaysupplierFactory,executable,filter,messagesupplier),"Should have returned a non-null instance for valid arguments.");
    } catch (Throwable thrown) {
        Assertions.fail("Expected to construct a PatientWaitFuture with valid arguments but throwable was caught: " + thrown);
    }
}
项目:patience    文件PatientWaitFutureTest.java   
@ParameterizedTest
@displayName("it returns successfully with valid arguments and a null message")
@ArgumentsSource(ValidArgumentsProvider.class)
void testSucceedsWithNullMessage(Sleep sleep,Predicate<Boolean> filter) {
    try {
        Assertions.assertNotNull(getInstance(sleep,(String) null),"Should have returned a non-null instance for valid arguments.");
    } catch (Throwable thrown) {
        Assertions.fail("Expected to construct a PatientWaitFuture with valid arguments but throwable was caught: " + thrown);
    }
}
项目:patience    文件PatientWaitFutureTest.java   
@ParameterizedTest
@displayName("it throws an exception for invalid arguments")
@ArgumentsSource(InvalidArgumentsProvider.class)
void testInvalidArgumentsThrowsException(Sleep sleep,supplier<String> messagesupplier) {
    Assertions.assertThrows(IllegalArgumentException.class,() -> getInstance(sleep,"Should have thrown an exception for an invalid argument");
}
项目:patience    文件PatientRetryFutureTest.java   
@ParameterizedTest
@displayName("it returns successfully with valid arguments")
@ArgumentsSource(PatientRetryFutureTest.ValidArgumentsProvider.class)
void testValidArgumentsSucceed(Sleep sleep,int defaultNumberOfRetries,defaultNumberOfRetries,"Should have returned a non-null instance for valid arguments.");
    } catch (Throwable thrown) {
        Assertions.fail("Expected to construct a PatientRetryFuture with valid arguments but throwable was caught: " + thrown);
    }
}
项目:patience    文件PatientRetryFutureTest.java   
@ParameterizedTest
@displayName("it returns successfully with valid arguments and a null message")
@ArgumentsSource(PatientRetryFutureTest.ValidArgumentsProvider.class)
void testSucceedsWithNullMessage(Sleep sleep,"Should have returned a non-null instance for valid arguments.");
    } catch (Throwable thrown) {
        Assertions.fail("Expected to construct a PatientRetryFuture with valid arguments but throwable was caught: " + thrown);
    }
}
项目:patience    文件PatientRetryFutureTest.java   
@ParameterizedTest
@displayName("it throws an exception for invalid arguments")
@ArgumentsSource(PatientRetryFutureTest.InvalidArgumentsProvider.class)
void testInvalidArgumentsThrowsException(Sleep sleep,"Should have thrown an exception for an invalid argument");
}
项目:mastering-junit5    文件ArgumentSourcesParameterizedTest.java   
@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);
}
项目:mastering-junit5    文件ArgumentSourceParameterizedTest.java   
@ParameterizedTest
@ArgumentsSource(CustomArgumentsProvider1.class)
void testWithArgumentsSource(String first,int second) {
    System.out.println("Parameterized test with (String) " + first
            + " and (int) " + second);

    assertNotNull(first);
    assertTrue(second > 0);
}
项目:Mastering-Software-Testing-with-JUnit-5    文件ArgumentSourcesParameterizedTest.java   
@ParameterizedTest
@ArgumentsSources({ @ArgumentsSource(CustomArgumentsProvider1.class),int second) {
    System.out.println("Parameterized test with (String) " + first
            + " and (int) " + second);

    assertNotNull(first);
    assertTrue(second > 0);
}
项目:Mastering-Software-Testing-with-JUnit-5    文件ArgumentSourceParameterizedTest.java   
@ParameterizedTest
@ArgumentsSource(CustomArgumentsProvider1.class)
void testWithArgumentsSource(String first,int second) {
    System.out.println("Parameterized test with (String) " + first
            + " and (int) " + second);

    assertNotNull(first);
    assertTrue(second > 0);
}
项目:roboslack    文件MessageRequestTests.java   
@ParameterizedTest
@ArgumentsSource(SerializedMessageRequestsProvider.class)
void testDeserialization(JsonNode json) {
    MoreAssertions.assertSerializable(json,MessageRequest.class,MessageRequestTests::assertValid);
}
项目:roboslack    文件AttachmentTests.java   
@ParameterizedTest
@ArgumentsSource(SerializedAttachmentsProvider.class)
void testDeserialization(JsonNode json) {
    MoreAssertions.assertSerializable(json,Attachment.class,AttachmentTests::assertValid);
}
项目:roboslack    文件ColorTests.java   
@ParameterizedTest
@ArgumentsSource(SerializedColorsProvider.class)
void testSerialization(JsonNode json) {
    MoreAssertions.assertSerializable(json,Color.class,ColorTests::assertValid);
}
项目:roboslack    文件FooterTests.java   
@ParameterizedTest
@ArgumentsSource(SerializedFootersProvider.class)
void testDeserialization(JsonNode json) {
    MoreAssertions.assertSerializable(json,Footer.class,FooterTests::assertValid);
}
项目:roboslack    文件AuthorTests.java   
@ParameterizedTest
@ArgumentsSource(SerializedAuthorsProvider.class)
void testSerialization(JsonNode json) {
    MoreAssertions.assertSerializable(json,Author.class,AuthorTests::assertValid);
}
项目:roboslack    文件FieldTests.java   
@ParameterizedTest
@ArgumentsSource(SerializedFieldsProvider.class)
void testSerialization(JsonNode json) {
    MoreAssertions.assertSerializable(json,Field.class,FieldTests::assertValid);
}
项目:roboslack    文件TitleTests.java   
@ParameterizedTest
@ArgumentsSource(SerializedTitlesProvider.class)
void testDeserialization(JsonNode json) {
    MoreAssertions.assertSerializable(json,Title.class,TitleTests::assertValid);
}
项目:roboslack    文件SlackWebHookServiceTests.java   
@ParameterizedTest
@ArgumentsSource(MessageRequestProvider.class)
void testSendMessage(MessageRequest messageRequest,TestInfo testInfo) {
    assertthat(SlackWebHookService.with(assumingEnvironmentWebHookToken())
                    .sendMessage(EnrichTestMessageRequest.get().apply(messageRequest,testInfo)),is(equalTo(ResponseCode.OK)));
}
项目:patience    文件PatientWaitTest.java   
@ParameterizedTest
@displayName("it returns a non-null instance successfully for valid arguments")
@ArgumentsSource(ValidArgumentsProvider.class)
void testCanInstantiateWithValidArguments(Sleep sleep,PatientExecutionHandler handler,DelaysupplierFactory delaysupplierFactory) {
    try {
        Assertions.assertNotNull(getInstance(sleep,handler,delaysupplierFactory),"Should have received a non-null instance with valid arguments.");
    } catch (Throwable thrown) {
        Assertions.fail("Should have been able to construct a PatientWait with valid arguments but caught throwable: " + thrown);
    }
}
项目:patience    文件PatientWaitTest.java   
@ParameterizedTest
@displayName("it throws an exception for invalid arguments")
@ArgumentsSource(InvalidArgumentsProvider.class)
void testThrowsExceptionWithInvalidArguments(Sleep sleep,DelaysupplierFactory delaysupplierFactory) {
    Assertions.assertThrows(IllegalArgumentException.class,"Should have thrown an exception when the constructor is called with an invalid argument.");
}
项目:patience    文件PatientWaitTest.java   
@ParameterizedTest
@displayName("it returns the given arguments")
@ArgumentsSource(ValidArgumentsProvider.class)
void testCanInstantiateWithValidArguments(Sleep sleep,DelaysupplierFactory delaysupplierFactory) {
    PatientWait wait = getInstance(sleep,delaysupplierFactory);
    Assertions.assertAll(() -> Assertions.assertEquals(sleep,wait.getSleep(),"Should return the given sleep"),() -> Assertions.assertEquals(initialDelay,wait.getinitialDelay(),"Should return the given initial delay"),() -> Assertions.assertEquals(defaultTimeout,wait.getDefaultTimeout(),"Should return the given default timeout"),() -> Assertions.assertEquals(handler,wait.getExecutionHandler(),"Should return the given execution handler"),() -> Assertions.assertEquals(delaysupplierFactory,wait.getDelaysupplierFactory(),"Should return the given delay supplier factory"));
}
项目:patience    文件PatientRetryTest.java   
@ParameterizedTest
@displayName("it returns a non-null instance successfully for valid arguments")
@ArgumentsSource(ValidArgumentsProvider.class)
void testCanInstantiateWithValidArguments(Sleep sleep,"Should have received a non-null instance with valid arguments.");
    } catch (Throwable thrown) {
        Assertions.fail("Should have been able to construct a PatientRetry with valid arguments but caught throwable: " + thrown);
    }
}
项目:patience    文件PatientRetryTest.java   
@ParameterizedTest
@displayName("it throws an exception for invalid arguments")
@ArgumentsSource(PatientRetryTest.InvalidArgumentsProvider.class)
void testThrowsExceptionWithInvalidArguments(Sleep sleep,"Should have thrown an exception when the constructor is called with an invalid argument.");
}
项目:patience    文件PatientRetryTest.java   
@ParameterizedTest
@displayName("it returns the given arguments")
@ArgumentsSource(PatientRetryTest.ValidArgumentsProvider.class)
void testCanInstantiateWithValidArguments(Sleep sleep,DelaysupplierFactory delaysupplierFactory) {
    PatientRetry retry = getInstance(sleep,retry.getSleep(),retry.getinitialDelay(),() -> Assertions.assertEquals(defaultNumberOfRetries,retry.getDefaultNumberOfRetries(),retry.getExecutionHandler(),retry.getDelaysupplierFactory(),"Should return the given delay supplier factory"));
}
项目:patience    文件AbstractRepeatedAttemptsExceptionTest.java   
@ParameterizedTest(name = "with message: <{0}>,and list: {1}")
@ArgumentsSource(ValidArgumentsProvider.class)
@displayName("it returns successfully with valid arguments")
void testCanBeInstantiatedWithValidArguments(String message,List<String> FailedAttemptsDescriptions) {
    try {
        Assertions.assertNotNull(getInstance(message,FailedAttemptsDescriptions),"Sending valid arguments to the constructor should have resulted in a non-null exception being returned.");
    } catch (Throwable thrown) {
        Assertions.fail("Should have been able to instantiate the exception but caught the throwable: " + thrown);
    }
}
项目:patience    文件AbstractRepeatedAttemptsExceptionTest.java   
@ParameterizedTest(name = "with message: <{0}>,and list: {1}")
@ArgumentsSource(InValidArgumentsProvider.class)
@displayName("it throws an exception for invalid arguments")
void testThrowsForInvalidArguments(String message,List<String> FailedAttemptsDescriptions) {
    Assertions.assertThrows(IllegalArgumentException.class,() -> getInstance(message,"Should thrown an IllegalArgumentException for invalid arguments.");
}
项目:patience    文件AbstractExceptionTest.java   
@ParameterizedTest(name = "with message: {0},and cause: {1}")
@displayName("it returns successfully for a message and cause argument")
@ArgumentsSource(ValidMessageAndCauseArguments.class)
void testCanBeConstructedWithMessageAndCauseArgs(String message,Throwable cause) {
    testInstantiation(() -> getInstance(message,cause));
}
项目:patience    文件AbstractExceptionTest.java   
@ParameterizedTest(name = "with message: {0},and cause: {1}")
@displayName("it returns the given message")
@ArgumentsSource(ValidMessageAndCauseArguments.class)
void testReturnsgivenMessage(String message,Throwable cause) {
    Assertions.assertEquals(message,getInstance(message,cause).getMessage(),"An exception should return it's given message.");
}
项目:patience    文件AbstractExceptionTest.java   
@ParameterizedTest(name = "with message: {0},and cause: {1}")
@displayName("it returns the given cause")
@ArgumentsSource(ValidMessageAndCauseArguments.class)
void testReturnsgivenCause(String message,Throwable cause) {
    Assertions.assertEquals(cause,cause).getCause(),"An exception should return it's given cause.");
}
项目:patience    文件IgnoringExecutionHandlerTest.java   
@ParameterizedTest
@displayName("it returns successfully for ignored throwable collection")
@ArgumentsSource(ValidIgnoredCollections.class)
void testCanInstantiateWithNullCollection(Collection<Class<? extends Throwable>> ignored) {
    Assertions.assertNotNull(getInstance(ignored),"Should be able to instantiate with the given collection: " + ignored);
}
项目:patience    文件IgnoringExecutionHandlerTest.java   
@ParameterizedTest
@displayName("it returns successfully for ignored throwable and not ignored throwable collections")
@ArgumentsSource(ValidIgnoredAndNotIgnoredCollections.class)
void testCanInstantiateWithNullCollection(Collection<Class<? extends Throwable>> ignored,Collection<Class<? extends Throwable>> notIgnored) {
    Assertions.assertNotNull(getInstance(ignored,notIgnored),"Should be able to instantiate with the given ignored collection: " + ignored + ",and not ignored collection: " + notIgnored);
}
项目:patience    文件DelaysuppliersTest.java   
@ParameterizedTest
@displayName("it throws an exception for an invalid argument")
@ArgumentsSource(InvalidFixedArgumentsProvider.class)
void testThrowsWithInvalidArguments(Duration duration) {
    Assertions.assertThrows(IllegalArgumentException.class,() -> Delaysuppliers.fixed(duration),"Should throw an exception for an invalid argument.");
}
项目:patience    文件DelaysuppliersTest.java   
@ParameterizedTest
@displayName("it returns a non-null delay supplier for a valid argument")
@ArgumentsSource(ValidFixedArgumentsProvider.class)
void testReturnsSuccessfullyWithValidArguments(Duration duration) {
    Assertions.assertNotNull(Delaysuppliers.fixed(duration),"Should return a non-null delay supplier for a valid argument.");
}
项目:patience    文件DelaysuppliersTest.java   
@ParameterizedTest
@displayName("it returns a delay supplier that returns the expected duration supplier")
@ArgumentsSource(ValidFixedArgumentsProvider.class)
void testReturnsExpectedDelaysupplier(Duration duration,List<Duration> expectedSuppliedDurations) {
    Assumptions.assumeTrue(null != expectedSuppliedDurations && !expectedSuppliedDurations.isEmpty(),"Should have received a non-null and non-empty list of expected durations.");
    supplier<Duration> supplier = Delaysuppliers.fixed(duration).create();
    Assertions.assertAll(expectedSuppliedDurations.stream().map(next -> () -> Assertions.assertEquals(next,supplier.get())));
}
项目:patience    文件DelaysuppliersTest.java   
@ParameterizedTest
@displayName("it throws an exception for an invalid argument")
@ArgumentsSource(InvalidExponentialArgumentsProvider.class)
void testThrowsWithInvalidArguments(int base,Duration duration) {
    Assertions.assertThrows(IllegalArgumentException.class,() -> Delaysuppliers.exponential(base,duration),"Should throw an exception for an invalid argument.");
}
项目:patience    文件DelaysuppliersTest.java   
@ParameterizedTest
@displayName("it returns a non-null delay supplier for a valid argument")
@ArgumentsSource(ValidExponentialArgumentsProvider.class)
void testReturnsSuccessfullyWithValidArguments(int base,Duration duration) {
    Assertions.assertNotNull(Delaysuppliers.exponential(base,"Should return a non-null delay supplier for a valid argument.");
}
项目:patience    文件DelaysuppliersTest.java   
@ParameterizedTest
@displayName("it returns a delay supplier that returns the expected duration supplier")
@ArgumentsSource(ValidExponentialArgumentsProvider.class)
void testReturnsExpectedDelaysupplier(int base,Duration duration,"Should have received a non-null and non-empty list of expected durations.");
    supplier<Duration> supplier = Delaysuppliers.exponential(base,duration).create();
    Assertions.assertAll(expectedSuppliedDurations.stream().map(next -> () -> Assertions.assertEquals(next,supplier.get())));
}
项目:patience    文件SleepTest.java   
@ParameterizedTest
@displayName("throws an exception for an invalid duration")
@ArgumentsSource(InvalidDurationArgumentsProvider.class)
void testSleepForThrowsExceptionForInvalidDuration(Duration duration) {
    Assertions.assertThrows(IllegalArgumentException.class,() -> getDefaultSleep().sleepFor(duration),"Should throw an exception for an invalid duration.");
}
项目:patience    文件SleepTest.java   
@ParameterizedTest
@displayName("calls sleepFor(long,int) with the expected arguments for the given duration")
@ArgumentsSource(DurationAndConversionArgumentsProvider.class)
void testSleepForProperlyConvertsTheGivenduration(Duration duration,long expectedMillis,int expectednanos) throws InterruptedException {
    Sleep sleep = spy(Sleep.class);
    sleep.sleepFor(duration);
    verify(sleep,times(1)).sleepFor(expectedMillis,expectednanos);
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。