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


Java Assertions類代碼示例

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


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

示例1: invalidCases

import org.junit.jupiter.api.Assertions; //導入依賴的package包/類
@Test
void invalidCases() {
    assertThrows(IllegalArgumentException.class, () -> TimeUtils.abbreviate(null));

    @NotNull Class<?> clazz = TimeUtils.class;
    try {
        Constructor constructor = clazz.getDeclaredConstructor();
        assertTrue(Modifier.isPrivate(constructor.getModifiers()));
        constructor.setAccessible(true);
        try {
            constructor.newInstance();
            Assertions.fail("Private constructor should throw exception");
        } catch (InvocationTargetException t) {
            assertTrue(t.getTargetException() instanceof Error);
        }
        constructor.setAccessible(false);
    } catch (Exception e) {
        Assert.fail("No defaultConstructor");
    }
}
 
開發者ID:ViniciusArnhold,項目名稱:ProjectAltaria,代碼行數:21,代碼來源:TimeUtilsTest.java

示例2: valueWithGetterNumberedThrowsOutOfRange

import org.junit.jupiter.api.Assertions; //導入依賴的package包/類
@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);
}
 
開發者ID:Blackdread,項目名稱:filter-sort-jooq-api,代碼行數:22,代碼來源:ValueTest.java

示例3: checkSupplier

import org.junit.jupiter.api.Assertions; //導入依賴的package包/類
private static <T> void checkSupplier(int readFailureCountTrigger, MockConnection connection, Address address, Supplier<T> supplier, Object ... values) throws Exception {
  // verify that a read failure doesn't kill the consumer
  // it logs (not verified) but returns null (as designed) and keeps working for the subsequent reads
  connection.setReadException(readFailureCountTrigger, "This is a mock read exception");
  int readCount = 0;
  for (Object value : values) {
    connection.setDataValue(address, value);
    T readData = supplier.get();
    // System.out.println("checkSupplier"+(readFailureCountTrigger > 0 ? "NEG" : "")+": value:"+value+" readData:"+readData);
    if (readFailureCountTrigger <= 0)
      Assertions.assertEquals(value, readData);
    else {
      if (++readCount != readFailureCountTrigger)
        Assertions.assertEquals(value, readData);
      else
        Assertions.assertNull(readData);
    }
  }
}
 
開發者ID:apache,項目名稱:incubator-plc4x,代碼行數:20,代碼來源:PlcConnectionAdapterTest.java

示例4: checkConsumer

import org.junit.jupiter.api.Assertions; //導入依賴的package包/類
@SuppressWarnings("unchecked")
private static <T> void checkConsumer(int writeFailureCountTrigger, MockConnection connection, Address address, Consumer<T> consumer, Object ... values) throws Exception {
  // verify that a write failure doesn't kill the consumer
  // it logs (not verified) but keeps working for the subsequent writes
  connection.setWriteException(writeFailureCountTrigger, "This is a mock write exception");
  int writeCount = 0;
  Object previousValue = null;
  for (Object value : values) {
    consumer.accept((T)value);
    T writtenData = (T) connection.getDataValue(address);
    if(writtenData.getClass().isArray()) {
      writtenData = (T) Array.get(writtenData, 0);
    }
    // System.out.println("checkConsumer"+(writeFailureCountTrigger > 0 ? "NEG" : "")+": value:"+value+" writtenData:"+writtenData);
    if (writeFailureCountTrigger <= 0)
      Assertions.assertEquals(value, writtenData);
    else { 
      if (++writeCount != writeFailureCountTrigger)
        Assertions.assertEquals(value, writtenData);
      else
        Assertions.assertEquals(previousValue, writtenData);
    }
    previousValue = value;
  }
}
 
開發者ID:apache,項目名稱:incubator-plc4x,代碼行數:26,代碼來源:PlcConnectionAdapterTest.java

示例5: testEncoderWithoutMeasureValue2

import org.junit.jupiter.api.Assertions; //導入依賴的package包/類
@Test
void testEncoderWithoutMeasureValue2() {
	iaMeasurePerformedNode.putValue("measurePerformed", null);
	QppOutputEncoder encoder = new QppOutputEncoder(new Context());

	encoder.setNodes(nodes);

	StringWriter sw = new StringWriter();

	try {
		encoder.encode(new BufferedWriter(sw));
	} catch (EncodeException e) {
		Assertions.fail("Failure to encode: " + e.getMessage());
	}

	assertThat(sw.toString())
			.isEqualTo(EXPECTED_NO_MEASURE_VALUE_1);
}
 
開發者ID:CMSgov,項目名稱:qpp-conversion-tool,代碼行數:19,代碼來源:IaSectionEncoderTest.java

示例6: of6

import org.junit.jupiter.api.Assertions; //導入依賴的package包/類
@Test
void of6() {
    final KeyParser6<Integer, String, LocalTime, Locale, Byte, LocalDateTime> keyParser = KeyParsers.of(
        "key1", val -> 0,
        "key2", val -> "other",
        "key3", val -> LocalTime.MIDNIGHT,
        "key4", val -> Locale.ENGLISH,
        "key5", val -> (byte) 0xFF,
        "key6", val -> LocalDateTime.MAX);
    Assertions.assertEquals("key6", keyParser.key6());
    Assertions.assertEquals("key6", keyParser.getKeys()[5]);
    Assertions.assertEquals(6, keyParser.size());
    Assertions.assertEquals(6, keyParser.getKeys().length);

    Assertions.assertEquals(LocalDateTime.MAX, keyParser.parser6().apply("any"));
    Assertions.assertEquals(6, keyParser.getParsers().length);
}
 
開發者ID:Blackdread,項目名稱:filter-sort-jooq-api,代碼行數:18,代碼來源:KeyParsersTest.java

示例7: testDescriptorGenerator

import org.junit.jupiter.api.Assertions; //導入依賴的package包/類
@Test
public void testDescriptorGenerator(){
    String desc = newDescriptor()
            .returns(void.class)
            .toString();
    String desc2 = newDescriptor()
            .returns(Void.class)
            .toString();
    String desc3 = newDescriptor()
            .accepts(int.class, int.class)
            .returns(String.class)
            .toString();
    Assertions.assertEquals("()V", desc);
    Assertions.assertEquals("()Ljava/lang/Void;", desc2); // huh?
    Assertions.assertEquals("(II)Ljava/lang/String;", desc3);
}
 
開發者ID:mikroskeem,項目名稱:Shuriken,代碼行數:17,代碼來源:DescriptorTester.java

示例8: testClassLoader

import org.junit.jupiter.api.Assertions; //導入依賴的package包/類
@Test
@SuppressWarnings("unchecked")
public void testClassLoader() throws Exception {
    BrotliLibraryLoader.loadBrotli();
    String className = "eu.mikroskeem.test.shuriken.classloader.classes.TestClass1";
    Path testJar = Utils.generateTestJar(GenerateTestClass.generate());
    URL[] urls = new URL[]{ToURL.to(testJar)};
    ShurikenClassLoader cl = new ShurikenClassLoader(urls, this.getClass().getClassLoader());

    /* Find class via reflection */
    Optional<ClassWrapper<?>> optClazz = Reflect.getClass(className, cl);
    Assertions.assertTrue(optClazz.isPresent(), "Class should be present!");

    /* Try constructing that class */
    ClassWrapper<?> clazz = optClazz.get().construct();
    Assertions.assertTrue(clazz.getClassInstance().getClass() == clazz.getWrappedClass());

    /* Peek into cached classes */
    ClassWrapper<ShurikenClassLoader> clw = Reflect.wrapInstance(cl);
    FieldWrapper<Map> classesField = clw.getField("classes", Map.class).get();
    Map<String, Class<?>> classes = (Map<String, Class<?>>) classesField.read();

    Assertions.assertTrue(new ArrayList<>(classes.keySet()).get(0).equals(className));
    Assertions.assertTrue(new ArrayList<>(classes.values()).get(0) == clazz.getWrappedClass());
}
 
開發者ID:mikroskeem,項目名稱:Shuriken,代碼行數:26,代碼來源:TestClassLoader.java

示例9: testBindingInjecting

import org.junit.jupiter.api.Assertions; //導入依賴的package包/類
@Test
public void testBindingInjecting() throws Exception {
    Injector injector = ShurikenInjector.createInjector(binder -> {
       binder.bind(InterfacesTestClass.a.class).to(InterfacesTestClass.A.class);
       binder.bind(InterfacesTestClass.b.class).to(InterfacesTestClass.C.class);
    });

    TestClassTwo t1 = injector.getInstance(TestClassTwo.class);
    TestClassTwo t2 = injector.getInstance(TestClassTwo.class);

    Assertions.assertEquals("a implementer A", t1.getA().toString());
    Assertions.assertEquals("b implementer C", t1.getB().toString());
    Assertions.assertEquals("a implementer A", t2.getA().toString());
    Assertions.assertEquals("b implementer C", t2.getB().toString());
    Assertions.assertNotEquals(t1.getA(), t2.getA());
    Assertions.assertNotEquals(t1.getB(), t2.getB());
}
 
開發者ID:mikroskeem,項目名稱:Shuriken,代碼行數:18,代碼來源:InjectorTester.java

示例10: testDefaultBuilder

import org.junit.jupiter.api.Assertions; //導入依賴的package包/類
@Test
public void testDefaultBuilder() throws Exception {
    List<Dependency> dependencies = Arrays.asList(UriUtilsTest.SAMPLE_DEPENDENCY, UriUtilsTest.SAMPLE_DEPENDENCY2);
    try (
        PicoMaven picoMaven = new PicoMaven.Builder()
            .withDownloadPath(downloadDir.toPath())
            .withRepositories(Arrays.asList(MAVEN_CENTRAL_REPOSITORY, UriUtilsTest.DEFAULT_REPOSITORY2))
            .withDependencies(dependencies)
                .withDebugLoggerImpl(new DebugLoggerImpl() {
                    @Override
                    public void debug(String format, Object... contents) {
                        System.err.format(format + "\n", contents);
                    }
                })
            .build()
    ) {
        List<Path> downloadedDeps = picoMaven.downloadAll();
        Assertions.assertEquals(dependencies.size(), downloadedDeps.size());
    }
}
 
開發者ID:mikroskeem,項目名稱:PicoMaven,代碼行數:21,代碼來源:ClientTest.java

示例11: testMixedAccessMethodReflector

import org.junit.jupiter.api.Assertions; //導入依賴的package包/類
@Test
public void testMixedAccessMethodReflector() {
    ClassWrapper<TestClass4> tc = wrapClass(TestClass4.class).construct();
    MethodReflector<TestClass3n4Reflector> reflector = newInstance(tc, TestClass3n4Reflector.class);

    TypeWrapper[] eParams = new TypeWrapper[] {
            TypeWrapper.of(int.class, 3),
            TypeWrapper.of("a"),
            TypeWrapper.of(char.class, 'a')
    };

    TestClass3n4Reflector reflectorImpl = reflector.getReflector();
    Assertions.assertEquals(tc.invokeMethod("a", String.class), reflectorImpl.a());
    Assertions.assertEquals(tc.invokeMethod("b", int.class).intValue(), reflectorImpl.b());
    reflectorImpl.c();
    Assertions.assertEquals(tc.invokeMethod("d", char.class).charValue(), reflectorImpl.d());
    Assertions.assertEquals(tc.invokeMethod("e", String.class, eParams), reflectorImpl.e(3, "a", 'a'));
}
 
開發者ID:mikroskeem,項目名稱:Shuriken,代碼行數:19,代碼來源:MethodReflectorTester.java

示例12: testInterfaceDefaultReflection

import org.junit.jupiter.api.Assertions; //導入依賴的package包/類
@Test
public void testInterfaceDefaultReflection() {
    ClassWrapper<TestClass8> tc = wrapClass(TestClass8.class).construct();
    MethodReflector<TestClass8Reflector> reflector = newInstance(tc, TestClass8Reflector.class);

    TestClass8Reflector reflectorImpl = reflector.getReflector();
    Assertions.assertEquals("abcd", reflectorImpl.a());
    Assertions.assertEquals("1234", reflectorImpl.b());
}
 
開發者ID:mikroskeem,項目名稱:Shuriken,代碼行數:10,代碼來源:MethodReflectorTester.java

示例13: parse

import org.junit.jupiter.api.Assertions; //導入依賴的package包/類
@ParameterizedTest
@MethodSource("goodStringParsableAndResult")
void parse(final String argument, final List<LocalDate> expected) {
    Assertions.assertEquals(expected, FilterMultipleValueParser.ofDate().parse(argument));
    Assertions.assertEquals(expected.size(), FilterMultipleValueParser.ofDate().parse(argument).size());
    Assertions.assertEquals(expected, FilterMultipleValueParser.ofDate().parse(argument, ","));
}
 
開發者ID:Blackdread,項目名稱:filter-sort-jooq-api,代碼行數:8,代碼來源:FilterMultipleValueParserDateTest.java

示例14: throwWithDuplicateKeySameFilter

import org.junit.jupiter.api.Assertions; //導入依賴的package包/類
@Test
void throwWithDuplicateKeySameFilter() {
    Assertions.assertThrows(IllegalArgumentException.class, () -> Filter.of("key", "key", val1 -> "value", val2 -> "value", (value1, value2) -> DSL.trueCondition()));
    Assertions.assertThrows(IllegalArgumentException.class, () -> Filter.of("key", "key", "key3", val1 -> "value", val2 -> "value", val3 -> "value", value3 -> DSL.trueCondition()));
    Assertions.assertThrows(IllegalArgumentException.class, () -> Filter.of("key", "key2", "key", "key4", val1 -> "value", val2 -> "value", val3 -> "value", val4 -> "value", value4 -> DSL.trueCondition()));

    Assertions.assertThrows(IllegalArgumentException.class, () -> KeyParsers.ofN(
        Arrays.asList("key", "key1", "key2", "key", "key4", "key5", "key6", "key6", "key8"),
        Arrays.asList(val1 -> "value", val1 -> "value", val1 -> "value", val1 -> "value", val1 -> "value", val1 -> "value", val1 -> "value", val1 -> "value", val1 -> "value")
    ));
}
 
開發者ID:Blackdread,項目名稱:filter-sort-jooq-api,代碼行數:12,代碼來源:FilterTest.java

示例15: getConditionOrNull

import org.junit.jupiter.api.Assertions; //導入依賴的package包/類
@Test
@SuppressWarnings("deprecation")
void getConditionOrNull() {
    Assertions.assertNull(filteringJooqImpl1.getConditionOrNull(emptyMap, "any", s -> DSL.trueCondition()));
    Assertions.assertNull(filteringJooqImpl1.getConditionOrNull(notEmptyMap, "any", s -> DSL.trueCondition()));
    Assertions.assertNotNull(filteringJooqImpl1.getConditionOrNull(notEmptyMap, "key1", s -> DSL.trueCondition()));
    Assertions.assertNull(filteringJooqImpl1.getConditionOrNull(mapWithNullValues, "key1", s -> DSL.trueCondition()));
    Assertions.assertNull(filteringJooqImpl1.getConditionOrNull(mapWithEmptyValues, "key1", s -> DSL.trueCondition()));
    Assertions.assertNull(filteringJooqImpl1.getConditionOrNull(mapWithSpaceValues, "key1", s -> DSL.trueCondition()));
}
 
開發者ID:Blackdread,項目名稱:filter-sort-jooq-api,代碼行數:11,代碼來源:FilteringJooqTest.java


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