Java 类org.junit.jupiter.api.extension.ExtendWith 实例源码

项目:junit-extensions    文件:TemporaryFolderExtensionParameterTest.java   
@RepeatedTest(5)
@ExtendWith(TemporaryFolderExtension.class)
public void willCreateANewTemporaryFileEveryTime(TemporaryFolder temporaryFolder)
    throws IOException {
  File file = temporaryFolder.createFile("foo.txt");

  assertThat(file.exists(), is(true));

  if (temporaryFilePaths.isEmpty()) {
    temporaryFilePaths.add(file.getAbsolutePath());
  } else {
    assertThat(
        "Received the same value twice, expected each random value to be different!",
        temporaryFilePaths,
        not(hasItem(file.getAbsolutePath())));
    temporaryFilePaths.add(file.getAbsolutePath());
  }
}
项目:junit-extensions    文件:TemporaryFolderExtensionParameterTest.java   
@RepeatedTest(5)
@ExtendWith(TemporaryFolderExtension.class)
public void willCreateANewTemporaryDirectoryEveryTime(TemporaryFolder temporaryFolder) {
  File dir = temporaryFolder.createDirectory("bar");

  assertThat(dir.exists(), is(true));

  if (temporaryDirectoryPaths.isEmpty()) {
    temporaryDirectoryPaths.add(dir.getAbsolutePath());
  } else {
    assertThat(
        "Received the same value twice, expected each random value to be different!",
        temporaryDirectoryPaths,
        not(hasItem(dir.getAbsolutePath())));
    temporaryDirectoryPaths.add(dir.getAbsolutePath());
  }
}
项目:junit-extensions    文件:CompositeExtensionTest.java   
@Test
@ExtendWith(TemporaryFolderExtension.class)
@ExpectedException(type = RuntimeException.class, messageIs = "Doh!")
public void canHandleTheKitchenSink(TemporaryFolder temporaryFolder, @Random Long anyLong)
    throws IOException {
  // randomness
  assertThat(anyString, notNullValue());
  assertThat(anyLong, notNullValue());

  // system property
  assertThat(System.getProperty("x"), is("y"));

  // temporary folder
  File file = temporaryFolder.createFile("foo.txt");
  assertThat(file.exists(), is(true));

  // expected exception
  throw new RuntimeException("Doh!");
}
项目:weld-junit    文件:ExplicitParameterInjectionViaMethodAnnotationTest.java   
@Test
@ExtendWith(CustomExtension.class)
@ExplicitParamInjection
public void testParametersNeedExtraAnnotation(@Default Foo foo, Bar bar, @MyQualifier BeanWithQualifier bean) {
    // Bar should be resolved by another extension
    Assertions.assertNotNull(bar);
    Assertions.assertEquals(CustomExtension.class.getSimpleName(), bar.ping());
    // Foo should be resolved as usual
    Assertions.assertNotNull(foo);
    Assertions.assertEquals(Foo.class.getSimpleName(), foo.ping());
    // BeanWithQualifier should be resolved
    Assertions.assertNotNull(bean);
    Assertions.assertEquals(BeanWithQualifier.class.getSimpleName(), bean.ping());
}
项目:weld-junit    文件:ExplicitParameterInjectionViaClassAnnotationTest.java   
@Test
@ExtendWith(CustomExtension.class)
public void testParametersNeedExtraAnnotation(@Default Foo foo, Bar bar, @MyQualifier BeanWithQualifier bean) {
    // Bar should be resolved by another extension
    Assertions.assertNotNull(bar);
    Assertions.assertEquals(CustomExtension.class.getSimpleName(), bar.ping());
    // Foo should be resolved as usual
    Assertions.assertNotNull(foo);
    Assertions.assertEquals(Foo.class.getSimpleName(), foo.ping());
    // BeanWithQualifier should be resolved
    Assertions.assertNotNull(bean);
    Assertions.assertEquals(BeanWithQualifier.class.getSimpleName(), bean.ping());
}
项目:weld-junit    文件:ExplicitParameterInjectionViaPropertyTest.java   
@Test
@ExtendWith(CustomExtension.class)
public void testParametersNeedExtraAnnotation(@Default Foo foo, Bar bar, @MyQualifier BeanWithQualifier bean) {
    // Bar should be resolved by another extension
    Assertions.assertNotNull(bar);
    Assertions.assertEquals(CustomExtension.class.getSimpleName(), bar.ping());
    // Foo should be resolved as usual
    Assertions.assertNotNull(foo);
    Assertions.assertEquals(Foo.class.getSimpleName(), foo.ping());
    // BeanWithQualifier should be resolved
    Assertions.assertNotNull(bean);
    Assertions.assertEquals(BeanWithQualifier.class.getSimpleName(), bean.ping());
}
项目:junit5-extensions    文件:GuiceExtensionTest.java   
@Test
@ExtendWith(FooBarExtension.class)
void doesNotResolveEveryParameter(String string, String[] fooBar, Injector injector) {
  assertThat(string).isEqualTo(TestModule.STRING);
  assertThat(fooBar).asList().containsExactly("foo", "bar").inOrder();

  assertNull(injector.getExistingBinding(Key.get(String[].class)));
}
项目:junit-extensions    文件:TemporaryFolderExtensionParameterTest.java   
@Test
@ExtendWith(TemporaryFolderExtension.class)
public void canInjectATemporaryFolderAsAParameter(TemporaryFolder temporaryFolder)
    throws IOException {
  File file = temporaryFolder.createFile("foo.txt");

  assertThat(file.exists(), is(true));

  File dir = temporaryFolder.createDirectory("bar");

  assertThat(dir.exists(), is(true));
}
项目:junit-extensions    文件:RandomBeansExtensionParameterTest.java   
@RepeatedTest(5)
@ExtendWith(RandomBeansExtension.class)
public void willInjectANewRandomValueEachTime(@Random String anyString) {
  assertThat(anyString, notNullValue());

  if (anyStrings.isEmpty()) {
    anyStrings.add(anyString);
  } else {
    assertThat(
        "Received the same value twice, expected each random value to be different!",
        anyStrings,
        not(hasItem(anyString)));
    anyStrings.add(anyString);
  }
}
项目:junit-dataprovider    文件:CustomStringConverterAcceptanceTest.java   
@TestTemplate
@ExtendWith(DataProviderExtension.class)
@DataProvider(value = {
        "2016-02-19                  | 2016 | 02 | 19 | 00 | 00 | 00 | 000 | UTC",
        "2016-02-19T20:15:22.629 GMT | 2016 | 02 | 19 | 20 | 15 | 22 | 629 | UTC",
    }, splitBy = "\\|", stringConverter = DateTimeAwareStringConverter.class)
// @formatter:off
void testDateTimeDirectAnnotation(Date date, int year, int month, int dayOfMonth, int hourOfDay, int minute,
        int second, int millis, String timeZone) {
    // Expect:
    assertThat(date).isEqualTo(date(year, month, dayOfMonth, hourOfDay, minute, second, millis, timeZone));
}
项目:junit-dataprovider    文件:CustomStringConverterAcceptanceTest.java   
@TestTemplate
@ExtendWith(CustomConverterDataProviderExtension.class)
@CustomConverterDataProvider(value = {
        "2016-02-19                  | 2016 | 02 | 19 | 00 | 00 | 00 | 000 | UTC",
        "2016-02-19T20:15:22.629 GMT | 2016 | 02 | 19 | 20 | 15 | 22 | 629 | UTC",
    }, splitBy = "\\|", trimValues = true)
// @formatter:off
void testDateTimeDirectMetaAnnotation(Date date, int year, int month, int dayOfMonth, int hourOfDay, int minute,
        int second, int millis, String timeZone) {
    // Expect:
    assertThat(date).isEqualTo(date(year, month, dayOfMonth, hourOfDay, minute, second, millis, timeZone));
}
项目:junit-dataprovider    文件:CustomStringConverterAcceptanceTest.java   
@TestTemplate
@ExtendWith(UseDataProviderExtension.class)
@UseDataProvider("dateTimeMetaAnnotationAndDataProviderMethodProvider")
void testDateTimeAnnotationAndDataProviderMethod(Date date, int year, int month, int dayOfMonth, int hourOfDay,
        int minute, int second, int millis, String timeZone) {
    // Expect:
    assertThat(date).isEqualTo(date(year, month, dayOfMonth, hourOfDay, minute, second, millis, timeZone));
}
项目:junit-dataprovider    文件:CustomResolverAcceptanceTest.java   
@TestTemplate
@ExtendWith(UseDataProviderExtension.class)
@UseDataProvider(resolver = DataProviderStartWithTestMethodNameResolver.class)
void testNumber(Number number) {
    // When:
    int count = counterOne.incrementAndGet();

    // Then:
    assertThat(count).isEqualTo(number.intValue());
}
项目:mastering-junit5    文件:TemplateTest.java   
@TestTemplate
@ExtendWith(MyTestTemplateInvocationContextProvider.class)
void testTemplate(String parameter) {
    System.out.println(parameter);
}
项目:mastering-junit5    文件:DependencyInjectionTest.java   
@ExtendWith(MyParameterResolver.class)
@Test
public void test(Object parameter) {
    System.out.println("My parameter " + parameter);
}
项目:mastering-junit5    文件:ExceptionTest.java   
@ExtendWith(IgnoreIOExceptionExtension.class)
@Test
public void firstTest() throws IOException {
    throw new IOException("IO Exception");
}
项目:testee.fi    文件:JUnit5QualifyingAnnotationExtension.java   
@Override
public Collection<Class<? extends Annotation>> getQualifyingAnnotations() {
    return asList(Test.class, TestFactory.class, ExtendWith.class);
}
项目:Mastering-Software-Testing-with-JUnit-5    文件:TemplateTest.java   
@TestTemplate
@ExtendWith(MyTestTemplateInvocationContextProvider.class)
void testTemplate(String parameter) {
    System.out.println(parameter);
}
项目:Mastering-Software-Testing-with-JUnit-5    文件:DependencyInjectionTest.java   
@ExtendWith(MyParameterResolver.class)
@Test
public void test(Object parameter) {
    System.out.println("My parameter " + parameter);
}
项目:Mastering-Software-Testing-with-JUnit-5    文件:ExceptionTest.java   
@ExtendWith(IgnoreIOExceptionExtension.class)
@Test
public void test1() throws IOException {
    throw new IOException("IO Exception");
}
项目:junit-extensions    文件:RandomBeansExtensionParameterTest.java   
@Test
@ExtendWith(RandomBeansExtension.class)
public void canInjectARandomString(@Random String anyString) {
  assertThat(anyString, notNullValue());
}
项目:JUnit-5-Quick-Start-Guide-with-AssertJ-Spring-TestFX-Mockito    文件:JUnit5_04_AdvancedExamples.java   
/**
 * Here I go a step further and annotate my days dynamically, by specifying the days I don't want the test to run
 * on with another custom annotation called @{@link DisabledWeekdays}.
 *
 * My extension {@link DisabledOnWeekday} later searches for @{@link DisabledWeekdays} and determines whether the
 * test should run or not.
 */
@Test
@DisabledWeekdays({Calendar.THURSDAY, Calendar.SATURDAY})
@ExtendWith(DisabledOnWeekday.class)
void disabledOnWeekdaysTest() {}