Added tests instead of a main method
This commit is contained in:
parent
f5937a3600
commit
7871014656
|
@ -1,4 +1,6 @@
|
|||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
<project
|
||||
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.baeldung</groupId>
|
||||
|
@ -12,7 +14,7 @@
|
|||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>parent-modules</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<relativePath>../../</relativePath>
|
||||
<relativePath>../..</relativePath>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
|
@ -21,6 +23,12 @@
|
|||
<artifactId>guava</artifactId>
|
||||
<version>${guava.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.assertj</groupId>
|
||||
<artifactId>assertj-core</artifactId>
|
||||
<version>${assertj.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
@ -41,6 +49,7 @@
|
|||
<maven.compiler.source.version>11</maven.compiler.source.version>
|
||||
<maven.compiler.target.version>11</maven.compiler.target.version>
|
||||
<guava.version>27.1-jre</guava.version>
|
||||
<assertj.version>3.11.1</assertj.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue