JUnit5 test classes and methods should have default package visibility
This commit is contained in:
parent
7d343f7674
commit
06c16d1eb0
@ -32,11 +32,11 @@ import org.junit.jupiter.api.Test;
|
|||||||
* Unit test that demonstrate the different assertions available within JUnit 4
|
* Unit test that demonstrate the different assertions available within JUnit 4
|
||||||
*/
|
*/
|
||||||
@DisplayName("Test case for assertions")
|
@DisplayName("Test case for assertions")
|
||||||
public class Junit5AssertionsUnitTest {
|
class Junit5AssertionsUnitTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@DisplayName("Arrays should be equals")
|
@DisplayName("Arrays should be equals")
|
||||||
public void whenAssertingArraysEquality_thenEqual() {
|
void whenAssertingArraysEquality_thenEqual() {
|
||||||
char[] expected = {'J', 'u', 'p', 'i', 't', 'e', 'r'};
|
char[] expected = {'J', 'u', 'p', 'i', 't', 'e', 'r'};
|
||||||
char[] actual = "Jupiter".toCharArray();
|
char[] actual = "Jupiter".toCharArray();
|
||||||
|
|
||||||
@ -45,7 +45,7 @@ public class Junit5AssertionsUnitTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
@DisplayName("The area of two polygons should be equal")
|
@DisplayName("The area of two polygons should be equal")
|
||||||
public void whenAssertingEquality_thenEqual() {
|
void whenAssertingEquality_thenEqual() {
|
||||||
float square = 2 * 2;
|
float square = 2 * 2;
|
||||||
float rectangle = 2 * 2;
|
float rectangle = 2 * 2;
|
||||||
|
|
||||||
@ -53,7 +53,7 @@ public class Junit5AssertionsUnitTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenAssertingEqualityWithDelta_thenEqual() {
|
void whenAssertingEqualityWithDelta_thenEqual() {
|
||||||
float square = 2 * 2;
|
float square = 2 * 2;
|
||||||
float rectangle = 3 * 2;
|
float rectangle = 3 * 2;
|
||||||
float delta = 2;
|
float delta = 2;
|
||||||
@ -62,27 +62,27 @@ public class Junit5AssertionsUnitTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenAssertingConditions_thenVerified() {
|
void whenAssertingConditions_thenVerified() {
|
||||||
assertTrue(5 > 4, "5 is greater the 4");
|
assertTrue(5 > 4, "5 is greater the 4");
|
||||||
assertTrue(null == null, "null is equal to null");
|
assertTrue(null == null, "null is equal to null");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenAssertingNull_thenTrue() {
|
void whenAssertingNull_thenTrue() {
|
||||||
Object cat = null;
|
Object cat = null;
|
||||||
|
|
||||||
assertNull(cat, () -> "The cat should be null");
|
assertNull(cat, () -> "The cat should be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenAssertingNotNull_thenTrue() {
|
void whenAssertingNotNull_thenTrue() {
|
||||||
Object dog = new Object();
|
Object dog = new Object();
|
||||||
|
|
||||||
assertNotNull(dog, () -> "The dog should not be null");
|
assertNotNull(dog, () -> "The dog should not be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenAssertingSameObject_thenSuccessfull() {
|
void whenAssertingSameObject_thenSuccessfull() {
|
||||||
String language = "Java";
|
String language = "Java";
|
||||||
Optional<String> optional = Optional.of(language);
|
Optional<String> optional = Optional.of(language);
|
||||||
|
|
||||||
@ -90,7 +90,7 @@ public class Junit5AssertionsUnitTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenBooleanSupplier_whenAssertingCondition_thenVerified() {
|
void givenBooleanSupplier_whenAssertingCondition_thenVerified() {
|
||||||
BooleanSupplier condition = () -> 5 > 6;
|
BooleanSupplier condition = () -> 5 > 6;
|
||||||
|
|
||||||
assertFalse(condition, "5 is not greater then 6");
|
assertFalse(condition, "5 is not greater then 6");
|
||||||
@ -98,13 +98,13 @@ public class Junit5AssertionsUnitTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Disabled
|
@Disabled
|
||||||
public void whenFailingATest_thenFailed() {
|
void whenFailingATest_thenFailed() {
|
||||||
// Test not completed
|
// Test not completed
|
||||||
fail("FAIL - test not completed");
|
fail("FAIL - test not completed");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenMultipleAssertion_whenAssertingAll_thenOK() {
|
void givenMultipleAssertion_whenAssertingAll_thenOK() {
|
||||||
Object obj = null;
|
Object obj = null;
|
||||||
assertAll(
|
assertAll(
|
||||||
"heading",
|
"heading",
|
||||||
@ -115,7 +115,7 @@ public class Junit5AssertionsUnitTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenTwoLists_whenAssertingIterables_thenEquals() {
|
void givenTwoLists_whenAssertingIterables_thenEquals() {
|
||||||
Iterable<String> al = new ArrayList<>(asList("Java", "Junit", "Test"));
|
Iterable<String> al = new ArrayList<>(asList("Java", "Junit", "Test"));
|
||||||
Iterable<String> ll = new LinkedList<>(asList("Java", "Junit", "Test"));
|
Iterable<String> ll = new LinkedList<>(asList("Java", "Junit", "Test"));
|
||||||
|
|
||||||
@ -123,7 +123,7 @@ public class Junit5AssertionsUnitTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenAssertingTimeout_thenNotExceeded() {
|
void whenAssertingTimeout_thenNotExceeded() {
|
||||||
assertTimeout(
|
assertTimeout(
|
||||||
ofSeconds(2),
|
ofSeconds(2),
|
||||||
() -> {
|
() -> {
|
||||||
@ -134,7 +134,7 @@ public class Junit5AssertionsUnitTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenAssertingTimeoutPreemptively_thenNotExceeded() {
|
void whenAssertingTimeoutPreemptively_thenNotExceeded() {
|
||||||
assertTimeoutPreemptively(
|
assertTimeoutPreemptively(
|
||||||
ofSeconds(2),
|
ofSeconds(2),
|
||||||
() -> {
|
() -> {
|
||||||
@ -145,14 +145,14 @@ public class Junit5AssertionsUnitTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenAssertingEquality_thenNotEqual() {
|
void whenAssertingEquality_thenNotEqual() {
|
||||||
Integer value = 5; // result of an algorithm
|
Integer value = 5; // result of an algorithm
|
||||||
|
|
||||||
assertNotEquals(0, value, "The result cannot be 0");
|
assertNotEquals(0, value, "The result cannot be 0");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenAssertingEqualityListOfStrings_thenEqual() {
|
void whenAssertingEqualityListOfStrings_thenEqual() {
|
||||||
List<String> expected = asList("Java", "\\d+", "JUnit");
|
List<String> expected = asList("Java", "\\d+", "JUnit");
|
||||||
List<String> actual = asList("Java", "11", "JUnit");
|
List<String> actual = asList("Java", "11", "JUnit");
|
||||||
|
|
||||||
@ -171,7 +171,7 @@ public class Junit5AssertionsUnitTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testConvertToDoubleThrowException() {
|
void testConvertToDoubleThrowException() {
|
||||||
String age = "eighteen";
|
String age = "eighteen";
|
||||||
assertThrows(NumberFormatException.class, () -> {
|
assertThrows(NumberFormatException.class, () -> {
|
||||||
convertToInt(age);
|
convertToInt(age);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user