當前位置: 首頁>>代碼示例>>Java>>正文


Java ExtendWith類代碼示例

本文整理匯總了Java中org.junit.jupiter.api.extension.ExtendWith的典型用法代碼示例。如果您正苦於以下問題:Java ExtendWith類的具體用法?Java ExtendWith怎麽用?Java ExtendWith使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ExtendWith類屬於org.junit.jupiter.api.extension包,在下文中一共展示了ExtendWith類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: willCreateANewTemporaryFileEveryTime

import org.junit.jupiter.api.extension.ExtendWith; //導入依賴的package包/類
@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());
  }
}
 
開發者ID:glytching,項目名稱:junit-extensions,代碼行數:19,代碼來源:TemporaryFolderExtensionParameterTest.java

示例2: willCreateANewTemporaryDirectoryEveryTime

import org.junit.jupiter.api.extension.ExtendWith; //導入依賴的package包/類
@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());
  }
}
 
開發者ID:glytching,項目名稱:junit-extensions,代碼行數:18,代碼來源:TemporaryFolderExtensionParameterTest.java

示例3: canHandleTheKitchenSink

import org.junit.jupiter.api.extension.ExtendWith; //導入依賴的package包/類
@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!");
}
 
開發者ID:glytching,項目名稱:junit-extensions,代碼行數:20,代碼來源:CompositeExtensionTest.java

示例4: testParametersNeedExtraAnnotation

import org.junit.jupiter.api.extension.ExtendWith; //導入依賴的package包/類
@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());
}
 
開發者ID:weld,項目名稱:weld-junit,代碼行數:15,代碼來源:ExplicitParameterInjectionViaMethodAnnotationTest.java

示例5: testParametersNeedExtraAnnotation

import org.junit.jupiter.api.extension.ExtendWith; //導入依賴的package包/類
@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());
}
 
開發者ID:weld,項目名稱:weld-junit,代碼行數:14,代碼來源:ExplicitParameterInjectionViaClassAnnotationTest.java

示例6: doesNotResolveEveryParameter

import org.junit.jupiter.api.extension.ExtendWith; //導入依賴的package包/類
@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)));
}
 
開發者ID:JeffreyFalgout,項目名稱:junit5-extensions,代碼行數:9,代碼來源:GuiceExtensionTest.java

示例7: canInjectATemporaryFolderAsAParameter

import org.junit.jupiter.api.extension.ExtendWith; //導入依賴的package包/類
@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));
}
 
開發者ID:glytching,項目名稱:junit-extensions,代碼行數:13,代碼來源:TemporaryFolderExtensionParameterTest.java

示例8: willInjectANewRandomValueEachTime

import org.junit.jupiter.api.extension.ExtendWith; //導入依賴的package包/類
@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);
  }
}
 
開發者ID:glytching,項目名稱:junit-extensions,代碼行數:16,代碼來源:RandomBeansExtensionParameterTest.java

示例9: testDateTimeDirectAnnotation

import org.junit.jupiter.api.extension.ExtendWith; //導入依賴的package包/類
@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));
}
 
開發者ID:TNG,項目名稱:junit-dataprovider,代碼行數:13,代碼來源:CustomStringConverterAcceptanceTest.java

示例10: testDateTimeDirectMetaAnnotation

import org.junit.jupiter.api.extension.ExtendWith; //導入依賴的package包/類
@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));
}
 
開發者ID:TNG,項目名稱:junit-dataprovider,代碼行數:13,代碼來源:CustomStringConverterAcceptanceTest.java

示例11: testDateTimeAnnotationAndDataProviderMethod

import org.junit.jupiter.api.extension.ExtendWith; //導入依賴的package包/類
@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));
}
 
開發者ID:TNG,項目名稱:junit-dataprovider,代碼行數:9,代碼來源:CustomStringConverterAcceptanceTest.java

示例12: testNumber

import org.junit.jupiter.api.extension.ExtendWith; //導入依賴的package包/類
@TestTemplate
@ExtendWith(UseDataProviderExtension.class)
@UseDataProvider(resolver = DataProviderStartWithTestMethodNameResolver.class)
void testNumber(Number number) {
    // When:
    int count = counterOne.incrementAndGet();

    // Then:
    assertThat(count).isEqualTo(number.intValue());
}
 
開發者ID:TNG,項目名稱:junit-dataprovider,代碼行數:11,代碼來源:CustomResolverAcceptanceTest.java

示例13: testTemplate

import org.junit.jupiter.api.extension.ExtendWith; //導入依賴的package包/類
@TestTemplate
@ExtendWith(MyTestTemplateInvocationContextProvider.class)
void testTemplate(String parameter) {
    System.out.println(parameter);
}
 
開發者ID:bonigarcia,項目名稱:mastering-junit5,代碼行數:6,代碼來源:TemplateTest.java

示例14: test

import org.junit.jupiter.api.extension.ExtendWith; //導入依賴的package包/類
@ExtendWith(MyParameterResolver.class)
@Test
public void test(Object parameter) {
    System.out.println("My parameter " + parameter);
}
 
開發者ID:bonigarcia,項目名稱:mastering-junit5,代碼行數:6,代碼來源:DependencyInjectionTest.java

示例15: firstTest

import org.junit.jupiter.api.extension.ExtendWith; //導入依賴的package包/類
@ExtendWith(IgnoreIOExceptionExtension.class)
@Test
public void firstTest() throws IOException {
    throw new IOException("IO Exception");
}
 
開發者ID:bonigarcia,項目名稱:mastering-junit5,代碼行數:6,代碼來源:ExceptionTest.java


注:本文中的org.junit.jupiter.api.extension.ExtendWith類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。