JUnit5 test classes and methods should have default package visibility
This commit is contained in:
parent
d722c0d1d1
commit
efaf789e71
|
@ -1,16 +1,16 @@
|
||||||
package com.baeldung;
|
package com.baeldung;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import org.junit.jupiter.api.Test;
|
||||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
import org.junit.jupiter.api.function.Executable;
|
||||||
|
|
||||||
import java.util.ConcurrentModificationException;
|
import java.util.ConcurrentModificationException;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import org.junit.jupiter.api.function.Executable;
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
|
||||||
public class ExceptionUnitTest {
|
class ExceptionUnitTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void shouldThrowException() {
|
void shouldThrowException() {
|
||||||
|
@ -29,7 +29,7 @@ public class ExceptionUnitTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenModifyMapDuringIteration_thenThrowExecption() {
|
void whenModifyMapDuringIteration_thenThrowExecption() {
|
||||||
Map<Integer, String> hashmap = new HashMap<>();
|
Map<Integer, String> hashmap = new HashMap<>();
|
||||||
hashmap.put(1, "One");
|
hashmap.put(1, "One");
|
||||||
hashmap.put(2, "Two");
|
hashmap.put(2, "Two");
|
||||||
|
|
|
@ -1,28 +1,28 @@
|
||||||
package com.baeldung;
|
package com.baeldung;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import org.junit.jupiter.api.DynamicTest;
|
||||||
|
import org.junit.jupiter.api.TestFactory;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
import org.junit.jupiter.api.DynamicTest;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import org.junit.jupiter.api.TestFactory;
|
|
||||||
|
|
||||||
public class LiveTest {
|
class LiveTest {
|
||||||
|
|
||||||
private List<String> in = new ArrayList<>(Arrays.asList("Hello", "Yes", "No"));
|
private List<String> in = new ArrayList<>(Arrays.asList("Hello", "Yes", "No"));
|
||||||
private List<String> out = new ArrayList<>(Arrays.asList("Cześć", "Tak", "Nie"));
|
private List<String> out = new ArrayList<>(Arrays.asList("Cześć", "Tak", "Nie"));
|
||||||
|
|
||||||
@TestFactory
|
@TestFactory
|
||||||
public Stream<DynamicTest> translateDynamicTestsFromStream() {
|
Stream<DynamicTest> translateDynamicTestsFromStream() {
|
||||||
|
|
||||||
return in.stream()
|
return in.stream()
|
||||||
.map(word -> DynamicTest.dynamicTest("Test translate " + word, () -> {
|
.map(word -> DynamicTest.dynamicTest("Test translate " + word, () -> {
|
||||||
int id = in.indexOf(word);
|
int id = in.indexOf(word);
|
||||||
assertEquals(out.get(id), translate(word));
|
assertEquals(out.get(id), translate(word));
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
private String translate(String word) {
|
private String translate(String word) {
|
||||||
|
|
|
@ -1,28 +1,26 @@
|
||||||
package com.baeldung.migration.junit5;
|
package com.baeldung.migration.junit5;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
||||||
import static org.junit.jupiter.api.Assumptions.assumeFalse;
|
|
||||||
import static org.junit.jupiter.api.Assumptions.assumeTrue;
|
|
||||||
import static org.junit.jupiter.api.Assumptions.assumingThat;
|
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
public class AssumptionUnitTest {
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assumptions.*;
|
||||||
|
|
||||||
|
class AssumptionUnitTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void trueAssumption() {
|
void trueAssumption() {
|
||||||
assumeTrue(5 > 1, () -> "5 is greater the 1");
|
assumeTrue(5 > 1, () -> "5 is greater the 1");
|
||||||
assertEquals(5 + 2, 7);
|
assertEquals(5 + 2, 7);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void falseAssumption() {
|
void falseAssumption() {
|
||||||
assumeFalse(5 < 1, () -> "5 is less then 1");
|
assumeFalse(5 < 1, () -> "5 is less then 1");
|
||||||
assertEquals(5 + 2, 7);
|
assertEquals(5 + 2, 7);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void assumptionThat() {
|
void assumptionThat() {
|
||||||
String someString = "Just a string";
|
String someString = "Just a string";
|
||||||
assumingThat(someString.equals("Just a string"), () -> assertEquals(2 + 2, 4));
|
assumingThat(someString.equals("Just a string"), () -> assertEquals(2 + 2, 4));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue