Code reformat

This commit is contained in:
Alex Golub 2022-04-21 11:07:21 +03:00
parent 06c16d1eb0
commit 618c69690d
1 changed files with 24 additions and 38 deletions

View File

@ -1,22 +1,8 @@
package com.baeldung.junit5vsjunit4assertions; package com.baeldung.junit5vsjunit4assertions;
import static java.time.Duration.ofSeconds; import org.junit.jupiter.api.Disabled;
import static java.util.Arrays.asList; import org.junit.jupiter.api.DisplayName;
import static org.junit.jupiter.api.Assertions.assertAll; import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertIterableEquals;
import static org.junit.jupiter.api.Assertions.assertLinesMatch;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTimeout;
import static org.junit.jupiter.api.Assertions.assertTimeoutPreemptively;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.LinkedList; import java.util.LinkedList;
@ -24,9 +10,9 @@ import java.util.List;
import java.util.Optional; import java.util.Optional;
import java.util.function.BooleanSupplier; import java.util.function.BooleanSupplier;
import org.junit.jupiter.api.Disabled; import static java.time.Duration.ofSeconds;
import org.junit.jupiter.api.DisplayName; import static java.util.Arrays.asList;
import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.*;
/** /**
* Unit test that demonstrate the different assertions available within JUnit 4 * Unit test that demonstrate the different assertions available within JUnit 4
@ -107,10 +93,10 @@ class Junit5AssertionsUnitTest {
void givenMultipleAssertion_whenAssertingAll_thenOK() { void givenMultipleAssertion_whenAssertingAll_thenOK() {
Object obj = null; Object obj = null;
assertAll( assertAll(
"heading", "heading",
() -> assertEquals(4, 2 * 2, "4 is 2 times 2"), () -> assertEquals(4, 2 * 2, "4 is 2 times 2"),
() -> assertEquals("java", "JAVA".toLowerCase()), () -> assertEquals("java", "JAVA".toLowerCase()),
() -> assertEquals(obj, null, "null is equal to null") () -> assertEquals(obj, null, "null is equal to null")
); );
} }
@ -125,22 +111,22 @@ class Junit5AssertionsUnitTest {
@Test @Test
void whenAssertingTimeout_thenNotExceeded() { void whenAssertingTimeout_thenNotExceeded() {
assertTimeout( assertTimeout(
ofSeconds(2), ofSeconds(2),
() -> { () -> {
// code that requires less then 2 minutes to execute // code that requires less then 2 minutes to execute
Thread.sleep(1000); Thread.sleep(1000);
} }
); );
} }
@Test @Test
void whenAssertingTimeoutPreemptively_thenNotExceeded() { void whenAssertingTimeoutPreemptively_thenNotExceeded() {
assertTimeoutPreemptively( assertTimeoutPreemptively(
ofSeconds(2), ofSeconds(2),
() -> { () -> {
// code that requires less then 2 minutes to execute // code that requires less then 2 minutes to execute
Thread.sleep(1000); Thread.sleep(1000);
} }
); );
} }
@ -162,10 +148,10 @@ class Junit5AssertionsUnitTest {
@Test @Test
void whenAssertingException_thenThrown() { void whenAssertingException_thenThrown() {
Throwable exception = assertThrows( Throwable exception = assertThrows(
IllegalArgumentException.class, IllegalArgumentException.class,
() -> { () -> {
throw new IllegalArgumentException("Exception message"); throw new IllegalArgumentException("Exception message");
} }
); );
assertEquals("Exception message", exception.getMessage()); assertEquals("Exception message", exception.getMessage());
} }