Fixed maven build and modifications ot some tests
This commit is contained in:
parent
3f204ebd59
commit
27f540c9bf
@ -1,138 +1,102 @@
|
||||
<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>
|
||||
<artifactId>core-java9</artifactId>
|
||||
<version>0.1-SNAPSHOT</version>
|
||||
<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>
|
||||
<artifactId>core-java9</artifactId>
|
||||
<version>0.2-SNAPSHOT</version>
|
||||
|
||||
<name>core-java9</name>
|
||||
<name>core-java9</name>
|
||||
|
||||
<dependencies>
|
||||
<pluginRepositories>
|
||||
<pluginRepository>
|
||||
<id>apache.snapshots</id>
|
||||
<url>http://repository.apache.org/snapshots/</url>
|
||||
</pluginRepository>
|
||||
</pluginRepositories>
|
||||
|
||||
<!-- utils
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>commons-io</groupId>
|
||||
<artifactId>commons-io</artifactId>
|
||||
<version>2.4</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava</artifactId>
|
||||
<version>${guava.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-collections4</artifactId>
|
||||
<version>4.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>commons-codec</groupId>
|
||||
<artifactId>commons-codec</artifactId>
|
||||
<version>1.10</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
<version>3.3.2</version>
|
||||
</dependency>
|
||||
-->
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
<version>${org.slf4j.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
<version>${org.slf4j.version}</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>org.hamcrest</groupId>
|
||||
<artifactId>hamcrest-library</artifactId>
|
||||
<version>${org.hamcrest.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hamcrest</groupId>
|
||||
<artifactId>hamcrest-library</artifactId>
|
||||
<version>${org.hamcrest.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>${junit.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>${junit.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-core</artifactId>
|
||||
<version>${mockito.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-core</artifactId>
|
||||
<version>${mockito.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<finalName>core-java-9</finalName>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
<filtering>true</filtering>
|
||||
</resource>
|
||||
</resources>
|
||||
<build>
|
||||
<finalName>core-java-9</finalName>
|
||||
|
||||
<plugins>
|
||||
<plugins>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>${maven-compiler-plugin.version}</version>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
|
||||
<verbose>true</verbose>
|
||||
<executable>C:\develop\jdks\jdk-9_ea122\bin\javac</executable>
|
||||
<compilerVersion>1.9</compilerVersion>
|
||||
</configuration>
|
||||
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>${maven-compiler-plugin.version}</version>
|
||||
<configuration>
|
||||
<source>1.9</source>
|
||||
<target>1.9</target>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>${maven-surefire-plugin.version}</version>
|
||||
</plugin>
|
||||
<verbose>true</verbose>
|
||||
<!-- <executable>C:\develop\jdks\jdk-9_ea122\bin\javac</executable>
|
||||
<compilerVersion>1.9</compilerVersion> -->
|
||||
</configuration>
|
||||
|
||||
</plugins>
|
||||
</plugin>
|
||||
|
||||
</build>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>${maven-surefire-plugin.version}</version>
|
||||
</plugin>
|
||||
|
||||
<properties>
|
||||
<!-- logging -->
|
||||
<org.slf4j.version>1.7.13</org.slf4j.version>
|
||||
<logback.version>1.0.13</logback.version>
|
||||
</plugins>
|
||||
|
||||
<!-- various -->
|
||||
<hibernate-validator.version>5.1.3.Final</hibernate-validator.version>
|
||||
</build>
|
||||
|
||||
<!-- util -->
|
||||
<guava.version>19.0</guava.version>
|
||||
<commons-lang3.version>3.4</commons-lang3.version>
|
||||
<properties>
|
||||
<!-- logging -->
|
||||
<org.slf4j.version>1.7.13</org.slf4j.version>
|
||||
<logback.version>1.0.13</logback.version>
|
||||
|
||||
<!-- testing -->
|
||||
<org.hamcrest.version>1.3</org.hamcrest.version>
|
||||
<junit.version>4.12</junit.version>
|
||||
<mockito.version>1.10.19</mockito.version>
|
||||
|
||||
<!-- maven plugins -->
|
||||
<maven-compiler-plugin.version>3.5.1</maven-compiler-plugin.version>
|
||||
|
||||
<!-- <maven-compiler-plugin.version>3.6-jigsaw-SNAPSHOT</maven-compiler-plugin.version> -->
|
||||
<maven-war-plugin.version>2.6</maven-war-plugin.version>
|
||||
<maven-surefire-plugin.version>2.19.1</maven-surefire-plugin.version>
|
||||
<maven-resources-plugin.version>2.7</maven-resources-plugin.version>
|
||||
<!-- maven plugins -->
|
||||
<!--
|
||||
<maven-war-plugin.version>2.6</maven-war-plugin.version>
|
||||
maven-compiler-plugin.version>3.5.1</maven-compiler-plugin.version> -->
|
||||
<maven-compiler-plugin.version>3.6-jigsaw-SNAPSHOT</maven-compiler-plugin.version>
|
||||
|
||||
</properties>
|
||||
|
||||
<maven-surefire-plugin.version>2.19.1</maven-surefire-plugin.version>
|
||||
|
||||
<!-- testing -->
|
||||
<org.hamcrest.version>1.3</org.hamcrest.version>
|
||||
<junit.version>4.12</junit.version>
|
||||
<mockito.version>1.10.19</mockito.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
|
@ -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");
|
||||
}
|
||||
}
|
@ -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 {
|
||||
|
||||
|
@ -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<HttpResponse> 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);
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
// }
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user