diff --git a/core-java-9/pom.xml b/core-java-9/pom.xml index 06421915a3..b29838d283 100644 --- a/core-java-9/pom.xml +++ b/core-java-9/pom.xml @@ -1,138 +1,102 @@ - - 4.0.0 - com.baeldung - core-java9 - 0.1-SNAPSHOT + + 4.0.0 + com.baeldung + core-java9 + 0.2-SNAPSHOT - core-java9 + core-java9 - + + + apache.snapshots + http://repository.apache.org/snapshots/ + + - - - org.slf4j - slf4j-api - ${org.slf4j.version} - + + org.slf4j + slf4j-api + ${org.slf4j.version} + - - org.hamcrest - hamcrest-library - ${org.hamcrest.version} - test - + + org.hamcrest + hamcrest-library + ${org.hamcrest.version} + test + - - junit - junit - ${junit.version} - test - + + junit + junit + ${junit.version} + test + - - org.mockito - mockito-core - ${mockito.version} - test - + + org.mockito + mockito-core + ${mockito.version} + test + - + - - core-java-9 - - - src/main/resources - true - - + + core-java-9 - + - - org.apache.maven.plugins - maven-compiler-plugin - ${maven-compiler-plugin.version} - - 1.8 - 1.8 - - true - C:\develop\jdks\jdk-9_ea122\bin\javac - 1.9 - - - + + org.apache.maven.plugins + maven-compiler-plugin + ${maven-compiler-plugin.version} + + 1.9 + 1.9 - - org.apache.maven.plugins - maven-surefire-plugin - ${maven-surefire-plugin.version} - + true + + - + - + + org.apache.maven.plugins + maven-surefire-plugin + ${maven-surefire-plugin.version} + - - - 1.7.13 - 1.0.13 + - - 5.1.3.Final + - - 19.0 - 3.4 + + + 1.7.13 + 1.0.13 - - 1.3 - 4.12 - 1.10.19 - - 3.5.1 - - - 2.6 - 2.19.1 - 2.7 + + + 3.6-jigsaw-SNAPSHOT - + + 2.19.1 + + + 1.3 + 4.12 + 1.10.19 + diff --git a/core-java-9/src/main/java/com/baeldung/java9/language/PrivateInterface.java b/core-java-9/src/main/java/com/baeldung/java9/language/PrivateInterface.java new file mode 100644 index 0000000000..fd6a496b18 --- /dev/null +++ b/core-java-9/src/main/java/com/baeldung/java9/language/PrivateInterface.java @@ -0,0 +1,23 @@ +package com.baeldung.java9.language; + +public interface PrivateInterface { + + private static String staticPrivate() { + return "static private"; + } + + private String instancePrivate() { + return "instance private"; + } + + public default void check(){ + String result = staticPrivate(); + if (!result.equals("static private")) + throw new AssertionError("Incorrect result for static private interface method"); + PrivateInterface pvt = new PrivateInterface() { + }; + result = pvt.instancePrivate(); + if (!result.equals("instance private")) + throw new AssertionError("Incorrect result for instance private interface method"); + } +} diff --git a/core-java-9/src/main/java/com/baeldung/java9/process/ProcessUtils.java b/core-java-9/src/main/java/com/baeldung/java9/process/ProcessUtils.java index b9c1cf1880..d6682bd0c8 100644 --- a/core-java-9/src/main/java/com/baeldung/java9/process/ProcessUtils.java +++ b/core-java-9/src/main/java/com/baeldung/java9/process/ProcessUtils.java @@ -8,10 +8,6 @@ import java.time.Duration; import java.time.Instant; import java.util.stream.Stream; -import org.junit.Before; -import org.junit.Test; - -import junit.framework.Assert; public class ProcessUtils { diff --git a/core-java-9/src/test/java/com/baeldung/java9/httpclient/SimpleHttpRequestsTest.java b/core-java-9/src/test/java/com/baeldung/java9/httpclient/SimpleHttpRequestsTest.java index 78a38f3357..ab28b0a805 100644 --- a/core-java-9/src/test/java/com/baeldung/java9/httpclient/SimpleHttpRequestsTest.java +++ b/core-java-9/src/test/java/com/baeldung/java9/httpclient/SimpleHttpRequestsTest.java @@ -1,4 +1,6 @@ -package com.baeldung.java9.httpclient; +package com.baeldung.java9.httpclient; + + import static java.net.HttpURLConnection.HTTP_OK; import static org.junit.Assert.assertTrue; @@ -24,61 +26,40 @@ import javax.net.ssl.SSLParameters; import org.junit.Before; import org.junit.Test; -public class SimpleHttpRequests { +public class SimpleHttpRequestsTest { - // private URI httpURI = + private URI httpURI; @Before - public void init() { - + public void init() throws URISyntaxException { + httpURI = new URI("http://www.baeldung.com/"); } @Test public void quickGet() throws IOException, InterruptedException, URISyntaxException { - HttpRequest request = HttpRequest.create(new URI("http://localhost:8080")).GET(); + HttpRequest request = HttpRequest.create( httpURI ).GET(); HttpResponse response = request.response(); - System.out.println(printHeaders(response.headers())); + int responseStatusCode = response.statusCode(); String responseBody = response.body(HttpResponse.asString()); - assertTrue("Get response body size", responseBody.length() > 10); + assertTrue("Get response status code is bigger then 400", responseStatusCode < 400); } @Test - public void asyncGet() throws URISyntaxException, IOException, InterruptedException, ExecutionException{ - HttpRequest request = HttpRequest.create(new URI("http://localhost:8080")).GET(); + public void asynchronousGet() throws URISyntaxException, IOException, InterruptedException, ExecutionException{ + HttpRequest request = HttpRequest.create(httpURI).GET(); long before = System.currentTimeMillis(); CompletableFuture futureResponse = request.responseAsync(); futureResponse.thenAccept( response -> { - HttpHeaders hs = response.headers(); - System.out.println(Thread.currentThread()+"\nHeaders:----------------------\n"+ printHeaders(hs)); String responseBody = response.body(HttpResponse.asString()); - - - //System.out.println(responseBody); - }); - - - - - long after = System.currentTimeMillis(); - System.out.println(Thread.currentThread()+" waits "+ (after - before)); - assertTrue("Thread waits", (after - before) < 1500); - - futureResponse.join(); - - // Calculate some other thing in this Thread - //HttpResponse response = futureResponse.get(); - long afterAfter = System.currentTimeMillis(); - System.out.println(Thread.currentThread()+ "(afterAfter - before)"+ (afterAfter - before)); - - //String responseBody = response.body(HttpResponse.asString()); - //HttpHeaders hs = response.headers(); - //System.out.println(responseBody); - // assertTrue("Get response body size", responseBody.length() > 10); + }); + HttpResponse resp = futureResponse.get(); + HttpHeaders hs = resp.headers(); + assertTrue("There should be more then 1 header.", hs.map().size() >1); } @Test - public void PostMehtod() throws URISyntaxException, IOException, InterruptedException { - HttpRequest.Builder requestBuilder = HttpRequest.create(new URI("http://localhost:8080")); + public void postMehtod() throws URISyntaxException, IOException, InterruptedException { + HttpRequest.Builder requestBuilder = HttpRequest.create(httpURI); requestBuilder.body(HttpRequest.fromString("param1=foo,param2=bar")).followRedirects(HttpClient.Redirect.SECURE); HttpRequest request = requestBuilder.POST(); HttpResponse response = request.response(); @@ -96,12 +77,11 @@ public class SimpleHttpRequests { HttpClient.Builder hcBuilder = HttpClient.create(); hcBuilder.cookieManager(cManager).sslContext(SSLContext.getDefault()).sslParameters(sslParam); HttpClient httpClient = hcBuilder.build(); - HttpRequest.Builder reqBuilder = httpClient.request(new URI("https://localhost:8443")); + HttpRequest.Builder reqBuilder = httpClient.request(new URI("https://www.facebook.com")); HttpRequest request = reqBuilder.followRedirects(HttpClient.Redirect.ALWAYS).GET(); HttpResponse response = request.response(); int statusCode = response.statusCode(); - System.out.println(response.body(HttpResponse.asString())); assertTrue("HTTP return code", statusCode == HTTP_OK); } diff --git a/core-java-9/src/test/java/com/baeldung/java9/language/PrivateInterfaceTest.java b/core-java-9/src/test/java/com/baeldung/java9/language/PrivateInterfaceTest.java index a41541f000..29ef3930f8 100644 --- a/core-java-9/src/test/java/com/baeldung/java9/language/PrivateInterfaceTest.java +++ b/core-java-9/src/test/java/com/baeldung/java9/language/PrivateInterfaceTest.java @@ -1,22 +1,15 @@ -package com.baeldung.java9; +package com.baeldung.java9.language; import com.baeldung.java9.language.PrivateInterface; -import com.baeldung.java9.language.TryWithResourcesTest; +import org.junit.Test; -public class Main { +public class PrivateInterfaceTest { - public static void main(String args[]){ - PrivateInterface pi =new PrivateInterface() { + @Test + public void test() { + PrivateInterface piClass = new PrivateInterface() { }; - pi.check(); + piClass.check(); } - -// public static void main(String[] args) throws Exception { -// MultiResultionImageTest mri = new MultiResultionImageTest(); -// mri.baseMultiResImageTest(); -// -// TryWithResourcesTest tt = new TryWithResourcesTest(); -// // tt.test1(); -// } }