"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "documentation/src/test/kotlin/example/AssertionsKotlinDemo.kt" between
junit5-r5.3.2.tar.gz and junit5-r5.4.0.tar.gz

About: JUnit 5 is a unit testing framework for the Java programming language.

AssertionsKotlinDemo.kt  (junit5-r5.3.2):AssertionsKotlinDemo.kt  (junit5-r5.4.0)
/* /*
* Copyright 2015-2018 the original author or authors. * Copyright 2015-2019 the original author or authors.
* *
* All rights reserved. This program and the accompanying materials are * All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License v2.0 which * made available under the terms of the Eclipse Public License v2.0 which
* accompanies this distribution and is available at * accompanies this distribution and is available at
* *
* http://www.eclipse.org/legal/epl-v20.html * http://www.eclipse.org/legal/epl-v20.html
*/ */
package example package example
// tag::user_guide[] // tag::user_guide[]
import example.domain.Person
import example.util.Calculator
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertAll import org.junit.jupiter.api.assertAll
import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Assertions.assertTrue import org.junit.jupiter.api.Assertions.assertTrue
import org.junit.jupiter.api.assertThrows import org.junit.jupiter.api.assertThrows
class AssertionsKotlinDemo { class KotlinAssertionsDemo {
// end::user_guide[] val person = Person("Jane", "Doe")
val person = Person("John", "Doe") val people = setOf(person, Person("John", "Doe"))
val people = setOf(person, Person("Jane", "Doe"))
// tag::user_guide[]
@Test @Test
fun `grouped assertions`() { fun `expected exception testing`() {
assertAll("person", val calculator = Calculator()
{ assertEquals("John", person.firstName) }, val exception = assertThrows<ArithmeticException> ("Should throw an exce
{ assertEquals("Doe", person.lastName) } ption") {
) calculator.divide(1, 0)
}
assertEquals("/ by zero", exception.message)
} }
@Test @Test
fun `exception testing`() { fun `grouped assertions`() {
val exception = assertThrows<IllegalArgumentException> ("Should throw an assertAll("Person properties",
exception") { { assertEquals("Jane", person.firstName) },
throw IllegalArgumentException("a message") { assertEquals("Doe", person.lastName) }
} )
assertEquals("a message", exception.message)
} }
@Test @Test
fun `assertions from a stream`() { fun `grouped assertions from a stream`() {
assertAll( assertAll("People with first name starting with J",
"people with name starting with J",
people people
.stream() .stream()
.map { .map {
// This mapping returns Stream<() -> Unit> // This mapping returns Stream<() -> Unit>
{ assertTrue(it.firstName.startsWith("J")) } { assertTrue(it.firstName.startsWith("J")) }
} }
) )
} }
@Test @Test
fun `assertions from a collection`() { fun `grouped assertions from a collection`() {
assertAll( assertAll("People with last name of Doe",
"people with last name of Doe",
people.map { { assertEquals("Doe", it.lastName) } } people.map { { assertEquals("Doe", it.lastName) } }
) )
} }
} }
// end::user_guide[] // end::user_guide[]
 End of changes. 9 change blocks. 
23 lines changed or deleted 23 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)