Debian Codegraph @

platform-tooling-support-tests/projects/gradle-kotlin-extensions/src/test/kotlin/com/example/project/ExtensionFunctionsTests.kt

raw
1 /*
2 * Copyright 2015-2024 the original author or authors.
3 *
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v2.0 which
6 * accompanies this distribution and is available at
7 *
8 * https://www.eclipse.org/legal/epl-v20.html
9 */
10 package com.example.project
11
12 import org.junit.jupiter.api.Assertions.assertEquals
13 import org.junit.jupiter.api.Test
14 import org.junit.jupiter.api.assertAll
15 import org.junit.jupiter.api.assertDoesNotThrow
16 import org.junit.jupiter.api.assertThrows
17 import org.junit.jupiter.api.fail
18 import org.junit.jupiter.params.ParameterizedTest
19 import org.junit.jupiter.params.aggregator.ArgumentsAccessor
20 import org.junit.jupiter.params.aggregator.get
21 import org.junit.jupiter.params.provider.CsvSource
22 import org.opentest4j.AssertionFailedError
23
24 class ExtensionFunctionsTests {
25
26 @Test
27 fun `assertDoesNotThrow() and assertAll`() {
28 assertDoesNotThrow {
29 assertAll(setOf {})
30 }
31 assertDoesNotThrow("message") {
32 assertAll("header", setOf {})
33 }
34 assertDoesNotThrow({ "message" }) {
35 assertAll({})
36 assertAll("header", {})
37 }
38 }
39
40 @Test
41 fun `fail() and assertThrows`() {
42 assertThrows<AssertionFailedError> {
43 fail("message")
44 }
45 assertThrows<AssertionFailedError>("message") {
46 fail { "message" }
47 }
48 assertThrows<AssertionFailedError>({ "message" }) {
49 fail(IllegalArgumentException())
50 }
51 }
52
53 @ParameterizedTest
54 @CsvSource("1")
55 fun accessor(accessor: ArgumentsAccessor) {
56 val value = accessor.get<Int>(0)
57 assertEquals(1, value)
58 }
59 }