Skip to content

Commit 27f540c

Browse files
committed
Fixed maven build and modifications ot some tests
1 parent 3f204eb commit 27f540c

5 files changed

Lines changed: 149 additions & 193 deletions

File tree

core-java-9/pom.xml

Lines changed: 100 additions & 136 deletions
Original file line numberDiff line numberDiff line change
@@ -1,138 +1,102 @@
1-
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2-
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3-
<modelVersion>4.0.0</modelVersion>
4-
<groupId>com.baeldung</groupId>
5-
<artifactId>core-java9</artifactId>
6-
<version>0.1-SNAPSHOT</version>
7-
8-
<name>core-java9</name>
9-
10-
<dependencies>
11-
12-
<!-- utils
13-
14-
<dependency>
15-
<groupId>commons-io</groupId>
16-
<artifactId>commons-io</artifactId>
17-
<version>2.4</version>
18-
</dependency>
19-
20-
<dependency>
21-
<groupId>com.google.guava</groupId>
22-
<artifactId>guava</artifactId>
23-
<version>${guava.version}</version>
24-
</dependency>
25-
26-
<dependency>
27-
<groupId>org.apache.commons</groupId>
28-
<artifactId>commons-collections4</artifactId>
29-
<version>4.0</version>
30-
</dependency>
31-
32-
<dependency>
33-
<groupId>commons-codec</groupId>
34-
<artifactId>commons-codec</artifactId>
35-
<version>1.10</version>
36-
</dependency>
37-
38-
<dependency>
39-
<groupId>org.apache.commons</groupId>
40-
<artifactId>commons-lang3</artifactId>
41-
<version>3.3.2</version>
42-
</dependency>
43-
-->
44-
<dependency>
45-
<groupId>org.slf4j</groupId>
46-
<artifactId>slf4j-api</artifactId>
47-
<version>${org.slf4j.version}</version>
48-
</dependency>
49-
50-
51-
52-
<dependency>
53-
<groupId>org.hamcrest</groupId>
54-
<artifactId>hamcrest-library</artifactId>
55-
<version>${org.hamcrest.version}</version>
56-
<scope>test</scope>
57-
</dependency>
58-
59-
<dependency>
60-
<groupId>junit</groupId>
61-
<artifactId>junit</artifactId>
62-
<version>${junit.version}</version>
63-
<scope>test</scope>
64-
</dependency>
65-
66-
<dependency>
67-
<groupId>org.mockito</groupId>
68-
<artifactId>mockito-core</artifactId>
69-
<version>${mockito.version}</version>
70-
<scope>test</scope>
71-
</dependency>
72-
73-
</dependencies>
74-
75-
<build>
76-
<finalName>core-java-9</finalName>
77-
<resources>
78-
<resource>
79-
<directory>src/main/resources</directory>
80-
<filtering>true</filtering>
81-
</resource>
82-
</resources>
83-
84-
<plugins>
85-
86-
<plugin>
87-
<groupId>org.apache.maven.plugins</groupId>
88-
<artifactId>maven-compiler-plugin</artifactId>
89-
<version>${maven-compiler-plugin.version}</version>
90-
<configuration>
91-
<source>1.8</source>
92-
<target>1.8</target>
93-
94-
<verbose>true</verbose>
95-
<executable>C:\develop\jdks\jdk-9_ea122\bin\javac</executable>
96-
<compilerVersion>1.9</compilerVersion>
97-
</configuration>
98-
99-
</plugin>
100-
101-
<plugin>
102-
<groupId>org.apache.maven.plugins</groupId>
103-
<artifactId>maven-surefire-plugin</artifactId>
104-
<version>${maven-surefire-plugin.version}</version>
105-
</plugin>
106-
107-
</plugins>
108-
109-
</build>
110-
111-
<properties>
112-
<!-- logging -->
113-
<org.slf4j.version>1.7.13</org.slf4j.version>
114-
<logback.version>1.0.13</logback.version>
115-
116-
<!-- various -->
117-
<hibernate-validator.version>5.1.3.Final</hibernate-validator.version>
118-
119-
<!-- util -->
120-
<guava.version>19.0</guava.version>
121-
<commons-lang3.version>3.4</commons-lang3.version>
122-
123-
<!-- testing -->
124-
<org.hamcrest.version>1.3</org.hamcrest.version>
125-
<junit.version>4.12</junit.version>
126-
<mockito.version>1.10.19</mockito.version>
127-
128-
<!-- maven plugins -->
129-
<maven-compiler-plugin.version>3.5.1</maven-compiler-plugin.version>
130-
131-
<!-- <maven-compiler-plugin.version>3.6-jigsaw-SNAPSHOT</maven-compiler-plugin.version> -->
132-
<maven-war-plugin.version>2.6</maven-war-plugin.version>
133-
<maven-surefire-plugin.version>2.19.1</maven-surefire-plugin.version>
134-
<maven-resources-plugin.version>2.7</maven-resources-plugin.version>
135-
136-
</properties>
1+
<project xmlns="http://maven.apache.org/POM/4.0.0"
2+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<groupId>com.baeldung</groupId>
6+
<artifactId>core-java9</artifactId>
7+
<version>0.2-SNAPSHOT</version>
8+
9+
<name>core-java9</name>
10+
11+
<pluginRepositories>
12+
<pluginRepository>
13+
<id>apache.snapshots</id>
14+
<url>http://repository.apache.org/snapshots/</url>
15+
</pluginRepository>
16+
</pluginRepositories>
17+
18+
<dependencies>
19+
20+
<dependency>
21+
<groupId>org.slf4j</groupId>
22+
<artifactId>slf4j-api</artifactId>
23+
<version>${org.slf4j.version}</version>
24+
</dependency>
25+
26+
27+
28+
<dependency>
29+
<groupId>org.hamcrest</groupId>
30+
<artifactId>hamcrest-library</artifactId>
31+
<version>${org.hamcrest.version}</version>
32+
<scope>test</scope>
33+
</dependency>
34+
35+
<dependency>
36+
<groupId>junit</groupId>
37+
<artifactId>junit</artifactId>
38+
<version>${junit.version}</version>
39+
<scope>test</scope>
40+
</dependency>
41+
42+
<dependency>
43+
<groupId>org.mockito</groupId>
44+
<artifactId>mockito-core</artifactId>
45+
<version>${mockito.version}</version>
46+
<scope>test</scope>
47+
</dependency>
48+
49+
</dependencies>
50+
51+
<build>
52+
<finalName>core-java-9</finalName>
53+
54+
<plugins>
55+
56+
<plugin>
57+
<groupId>org.apache.maven.plugins</groupId>
58+
<artifactId>maven-compiler-plugin</artifactId>
59+
<version>${maven-compiler-plugin.version}</version>
60+
<configuration>
61+
<source>1.9</source>
62+
<target>1.9</target>
63+
64+
<verbose>true</verbose>
65+
<!-- <executable>C:\develop\jdks\jdk-9_ea122\bin\javac</executable>
66+
<compilerVersion>1.9</compilerVersion> -->
67+
</configuration>
68+
69+
</plugin>
70+
71+
<plugin>
72+
<groupId>org.apache.maven.plugins</groupId>
73+
<artifactId>maven-surefire-plugin</artifactId>
74+
<version>${maven-surefire-plugin.version}</version>
75+
</plugin>
76+
77+
</plugins>
78+
79+
</build>
80+
81+
<properties>
82+
<!-- logging -->
83+
<org.slf4j.version>1.7.13</org.slf4j.version>
84+
<logback.version>1.0.13</logback.version>
85+
86+
87+
<!-- maven plugins -->
88+
<!--
89+
<maven-war-plugin.version>2.6</maven-war-plugin.version>
90+
maven-compiler-plugin.version>3.5.1</maven-compiler-plugin.version> -->
91+
<maven-compiler-plugin.version>3.6-jigsaw-SNAPSHOT</maven-compiler-plugin.version>
92+
93+
94+
<maven-surefire-plugin.version>2.19.1</maven-surefire-plugin.version>
95+
96+
<!-- testing -->
97+
<org.hamcrest.version>1.3</org.hamcrest.version>
98+
<junit.version>4.12</junit.version>
99+
<mockito.version>1.10.19</mockito.version>
100+
</properties>
137101

138102
</project>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.baeldung.java9.language;
2+
3+
public interface PrivateInterface {
4+
5+
private static String staticPrivate() {
6+
return "static private";
7+
}
8+
9+
private String instancePrivate() {
10+
return "instance private";
11+
}
12+
13+
public default void check(){
14+
String result = staticPrivate();
15+
if (!result.equals("static private"))
16+
throw new AssertionError("Incorrect result for static private interface method");
17+
PrivateInterface pvt = new PrivateInterface() {
18+
};
19+
result = pvt.instancePrivate();
20+
if (!result.equals("instance private"))
21+
throw new AssertionError("Incorrect result for instance private interface method");
22+
}
23+
}

core-java-9/src/main/java/com/baeldung/java9/process/ProcessUtils.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@
88
import java.time.Instant;
99
import java.util.stream.Stream;
1010

11-
import org.junit.Before;
12-
import org.junit.Test;
13-
14-
import junit.framework.Assert;
1511

1612
public class ProcessUtils {
1713

core-java-9/src/test/java/com/baeldung/java9/httpclient/SimpleHttpRequestsTest.java

Lines changed: 19 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
package com.baeldung.java9.httpclient;
1+
package com.baeldung.java9.httpclient;
2+
3+
24

35
import static java.net.HttpURLConnection.HTTP_OK;
46
import static org.junit.Assert.assertTrue;
@@ -24,61 +26,40 @@
2426
import org.junit.Before;
2527
import org.junit.Test;
2628

27-
public class SimpleHttpRequests {
29+
public class SimpleHttpRequestsTest {
2830

29-
// private URI httpURI =
31+
private URI httpURI;
3032

3133
@Before
32-
public void init() {
33-
34+
public void init() throws URISyntaxException {
35+
httpURI = new URI("http://www.baeldung.com/");
3436
}
3537

3638
@Test
3739
public void quickGet() throws IOException, InterruptedException, URISyntaxException {
38-
HttpRequest request = HttpRequest.create(new URI("http://localhost:8080")).GET();
40+
HttpRequest request = HttpRequest.create( httpURI ).GET();
3941
HttpResponse response = request.response();
40-
System.out.println(printHeaders(response.headers()));
42+
int responseStatusCode = response.statusCode();
4143
String responseBody = response.body(HttpResponse.asString());
42-
assertTrue("Get response body size", responseBody.length() > 10);
44+
assertTrue("Get response status code is bigger then 400", responseStatusCode < 400);
4345
}
4446

4547
@Test
46-
public void asyncGet() throws URISyntaxException, IOException, InterruptedException, ExecutionException{
47-
HttpRequest request = HttpRequest.create(new URI("http://localhost:8080")).GET();
48+
public void asynchronousGet() throws URISyntaxException, IOException, InterruptedException, ExecutionException{
49+
HttpRequest request = HttpRequest.create(httpURI).GET();
4850
long before = System.currentTimeMillis();
4951
CompletableFuture<HttpResponse> futureResponse = request.responseAsync();
5052
futureResponse.thenAccept( response -> {
51-
HttpHeaders hs = response.headers();
52-
System.out.println(Thread.currentThread()+"\nHeaders:----------------------\n"+ printHeaders(hs));
5353
String responseBody = response.body(HttpResponse.asString());
54-
55-
56-
//System.out.println(responseBody);
57-
});
58-
59-
60-
61-
62-
long after = System.currentTimeMillis();
63-
System.out.println(Thread.currentThread()+" waits "+ (after - before));
64-
assertTrue("Thread waits", (after - before) < 1500);
65-
66-
futureResponse.join();
67-
68-
// Calculate some other thing in this Thread
69-
//HttpResponse response = futureResponse.get();
70-
long afterAfter = System.currentTimeMillis();
71-
System.out.println(Thread.currentThread()+ "(afterAfter - before)"+ (afterAfter - before));
72-
73-
//String responseBody = response.body(HttpResponse.asString());
74-
//HttpHeaders hs = response.headers();
75-
//System.out.println(responseBody);
76-
// assertTrue("Get response body size", responseBody.length() > 10);
54+
});
55+
HttpResponse resp = futureResponse.get();
56+
HttpHeaders hs = resp.headers();
57+
assertTrue("There should be more then 1 header.", hs.map().size() >1);
7758
}
7859

7960
@Test
80-
public void PostMehtod() throws URISyntaxException, IOException, InterruptedException {
81-
HttpRequest.Builder requestBuilder = HttpRequest.create(new URI("http://localhost:8080"));
61+
public void postMehtod() throws URISyntaxException, IOException, InterruptedException {
62+
HttpRequest.Builder requestBuilder = HttpRequest.create(httpURI);
8263
requestBuilder.body(HttpRequest.fromString("param1=foo,param2=bar")).followRedirects(HttpClient.Redirect.SECURE);
8364
HttpRequest request = requestBuilder.POST();
8465
HttpResponse response = request.response();
@@ -96,12 +77,11 @@ public void configureHttpClient() throws NoSuchAlgorithmException, URISyntaxExce
9677
HttpClient.Builder hcBuilder = HttpClient.create();
9778
hcBuilder.cookieManager(cManager).sslContext(SSLContext.getDefault()).sslParameters(sslParam);
9879
HttpClient httpClient = hcBuilder.build();
99-
HttpRequest.Builder reqBuilder = httpClient.request(new URI("https://localhost:8443"));
80+
HttpRequest.Builder reqBuilder = httpClient.request(new URI("https://www.facebook.com"));
10081

10182
HttpRequest request = reqBuilder.followRedirects(HttpClient.Redirect.ALWAYS).GET();
10283
HttpResponse response = request.response();
10384
int statusCode = response.statusCode();
104-
System.out.println(response.body(HttpResponse.asString()));
10585
assertTrue("HTTP return code", statusCode == HTTP_OK);
10686
}
10787

0 commit comments

Comments
 (0)