Added tests instead of a main method
This commit is contained in:
@@ -1,33 +0,0 @@
|
||||
package com.baeldung.predicate.not;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static java.util.function.Predicate.*;
|
||||
|
||||
public class FindPeople {
|
||||
public static void main(String[] args) {
|
||||
List<Person> people = List.of(
|
||||
new Person(1),
|
||||
new Person(18),
|
||||
new Person(2)
|
||||
);
|
||||
|
||||
people.stream()
|
||||
.filter(Person::isAdult)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
people.stream()
|
||||
.filter(person -> !person.isAdult())
|
||||
.collect(Collectors.toList());
|
||||
|
||||
people.stream()
|
||||
.filter(Person::isNotAdult)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
people.stream()
|
||||
.filter(not(Person::isAdult))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,7 @@ import junit.framework.TestSuite;
|
||||
/**
|
||||
* Unit test for simple App.
|
||||
*/
|
||||
public class AppTest
|
||||
public class AppUnitTest
|
||||
extends TestCase
|
||||
{
|
||||
/**
|
||||
@@ -15,7 +15,7 @@ public class AppTest
|
||||
*
|
||||
* @param testName name of the test case
|
||||
*/
|
||||
public AppTest( String testName )
|
||||
public AppUnitTest(String testName )
|
||||
{
|
||||
super( testName );
|
||||
}
|
||||
@@ -25,7 +25,7 @@ public class AppTest
|
||||
*/
|
||||
public static Test suite()
|
||||
{
|
||||
return new TestSuite( AppTest.class );
|
||||
return new TestSuite( AppUnitTest.class );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -32,7 +32,7 @@ import java.util.stream.Collectors;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class HttpClientTest {
|
||||
public class HttpClientUnitTest {
|
||||
|
||||
@Test
|
||||
public void shouldReturnSampleDataContentWhenConnectViaSystemProxy() throws IOException, InterruptedException, URISyntaxException {
|
||||
@@ -19,7 +19,7 @@ import java.time.Duration;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class HttpRequestTest {
|
||||
public class HttpRequestUnitTest {
|
||||
|
||||
@Test
|
||||
public void shouldReturnStatusOKWhenSendGetRequest() throws IOException, InterruptedException, URISyntaxException {
|
||||
@@ -14,7 +14,7 @@ import java.net.http.HttpResponse;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class HttpResponseTest {
|
||||
public class HttpResponseUnitTest {
|
||||
|
||||
@Test
|
||||
public void shouldReturnStatusOKWhenSendGetRequest() throws IOException, InterruptedException, URISyntaxException {
|
||||
@@ -0,0 +1,61 @@
|
||||
package com.baeldung.predicate.not;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static java.util.function.Predicate.not;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
class PersonUnitTest {
|
||||
private List<Person> people;
|
||||
|
||||
@BeforeEach
|
||||
void preparePeople() {
|
||||
people = Arrays.asList(
|
||||
new Person(1),
|
||||
new Person(18),
|
||||
new Person(2)
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
void givenPeople_whenFilterIsAdult_thenOneResult() {
|
||||
List<Person> adults = people.stream()
|
||||
.filter(Person::isAdult)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
assertThat(adults).size().isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
void givenPeople_whenFilterIsAdultNegated_thenTwoResults() {
|
||||
List<Person> nonAdults = people.stream()
|
||||
.filter(person -> !person.isAdult())
|
||||
.collect(Collectors.toList());
|
||||
|
||||
assertThat(nonAdults).size().isEqualTo(2);
|
||||
}
|
||||
|
||||
@Test
|
||||
void givenPeople_whenFilterIsNotAdult_thenTwoResults() {
|
||||
List<Person> nonAdults = people.stream()
|
||||
.filter(Person::isNotAdult)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
assertThat(nonAdults).size().isEqualTo(2);
|
||||
}
|
||||
|
||||
@Test
|
||||
void givenPeople_whenFilterNotIsAdult_thenTwoResults() {
|
||||
List<Person> nonAdults = people.stream()
|
||||
.filter(not(Person::isAdult))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
assertThat(nonAdults).size().isEqualTo(2);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user