commit
bc6c7238d7
@ -28,8 +28,104 @@
|
|||||||
<version>${junit.platform.version}</version>
|
<version>${junit.platform.version}</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.awaitility</groupId>
|
||||||
|
<artifactId>awaitility</artifactId>
|
||||||
|
<version>${awaitility.version}</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
<profiles>
|
||||||
|
<profile>
|
||||||
|
<id>incubator-features</id>
|
||||||
|
<build>
|
||||||
|
<finalName>core-java-9-new-features</finalName>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<version>${maven-compiler-plugin.version}</version>
|
||||||
|
<configuration>
|
||||||
|
<source>${maven.compiler.source}</source>
|
||||||
|
<target>${maven.compiler.target}</target>
|
||||||
|
<compilerArgument>--add-modules=jdk.incubator.httpclient</compilerArgument>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
|
<configuration>
|
||||||
|
<argLine>--add-modules=jdk.incubator.httpclient</argLine>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
</profile>
|
||||||
|
<profile>
|
||||||
|
<id>mrjar-generation</id>
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>compile-java-8</id>
|
||||||
|
<goals>
|
||||||
|
<goal>compile</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<source>1.8</source>
|
||||||
|
<target>1.8</target>
|
||||||
|
<compileSourceRoots>
|
||||||
|
<compileSourceRoot>${project.basedir}/src/main/java8</compileSourceRoot>
|
||||||
|
</compileSourceRoots>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
<execution>
|
||||||
|
<id>compile-java-9</id>
|
||||||
|
<phase>compile</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>compile</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<release>9</release>
|
||||||
|
<compileSourceRoots>
|
||||||
|
<compileSourceRoot>${project.basedir}/src/main/java9</compileSourceRoot>
|
||||||
|
</compileSourceRoots>
|
||||||
|
<outputDirectory>${project.build.outputDirectory}/META-INF/versions/9</outputDirectory>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
<execution>
|
||||||
|
<id>default-testCompile</id>
|
||||||
|
<phase>test-compile</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>testCompile</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<skip>true</skip>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-jar-plugin</artifactId>
|
||||||
|
<version>${maven-jar-plugin.version}</version>
|
||||||
|
<configuration>
|
||||||
|
<archive>
|
||||||
|
<manifestEntries>
|
||||||
|
<Multi-Release>true</Multi-Release>
|
||||||
|
</manifestEntries>
|
||||||
|
<manifest>
|
||||||
|
<mainClass>com.baeldung.multireleaseapp.App</mainClass>
|
||||||
|
</manifest>
|
||||||
|
</archive>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
</profile>
|
||||||
|
</profiles>
|
||||||
<build>
|
<build>
|
||||||
<finalName>core-java-9-new-features</finalName>
|
<finalName>core-java-9-new-features</finalName>
|
||||||
<plugins>
|
<plugins>
|
||||||
@ -56,8 +152,10 @@
|
|||||||
<!-- testing -->
|
<!-- testing -->
|
||||||
<assertj.version>3.10.0</assertj.version>
|
<assertj.version>3.10.0</assertj.version>
|
||||||
<junit.platform.version>1.2.0</junit.platform.version>
|
<junit.platform.version>1.2.0</junit.platform.version>
|
||||||
|
<awaitility.version>4.0.2</awaitility.version>
|
||||||
<maven.compiler.source>1.9</maven.compiler.source>
|
<maven.compiler.source>1.9</maven.compiler.source>
|
||||||
<maven.compiler.target>1.9</maven.compiler.target>
|
<maven.compiler.target>1.9</maven.compiler.target>
|
||||||
|
<maven-jar-plugin.version>3.2.0</maven-jar-plugin.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
@ -0,0 +1,14 @@
|
|||||||
|
package com.baeldung.multireleaseapp;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
public class App {
|
||||||
|
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(App.class);
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
logger.info(String.format("Running on %s", new DefaultVersion().version()));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
package com.baeldung.multireleaseapp;
|
||||||
|
|
||||||
|
public class DefaultVersion implements Version {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String version() {
|
||||||
|
return System.getProperty("java.version");
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,5 @@
|
|||||||
|
package com.baeldung.multireleaseapp;
|
||||||
|
|
||||||
|
interface Version {
|
||||||
|
public String version();
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
package com.baeldung.multireleaseapp;
|
||||||
|
|
||||||
|
public class DefaultVersion implements Version {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String version() {
|
||||||
|
return Runtime.version().toString();
|
||||||
|
}
|
||||||
|
}
|
@ -24,7 +24,7 @@ import static org.junit.Assert.assertThat;
|
|||||||
/**
|
/**
|
||||||
* Created by adam.
|
* Created by adam.
|
||||||
*/
|
*/
|
||||||
public class HttpClientTest {
|
public class HttpClientIntegrationTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldReturnSampleDataContentWhenConnectViaSystemProxy() throws IOException, InterruptedException, URISyntaxException {
|
public void shouldReturnSampleDataContentWhenConnectViaSystemProxy() throws IOException, InterruptedException, URISyntaxException {
|
||||||
@ -55,7 +55,7 @@ public class HttpClientTest {
|
|||||||
.send(request, HttpResponse.BodyHandler.asString());
|
.send(request, HttpResponse.BodyHandler.asString());
|
||||||
|
|
||||||
assertThat(response.statusCode(), equalTo(HttpURLConnection.HTTP_MOVED_PERM));
|
assertThat(response.statusCode(), equalTo(HttpURLConnection.HTTP_MOVED_PERM));
|
||||||
assertThat(response.body(), containsString("https://stackoverflow.com/"));
|
assertThat(response.body(), containsString(""));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
@ -22,7 +22,7 @@ import static org.junit.Assert.assertThat;
|
|||||||
/**
|
/**
|
||||||
* Created by adam.
|
* Created by adam.
|
||||||
*/
|
*/
|
||||||
public class HttpRequestTest {
|
public class HttpRequestIntegrationTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldReturnStatusOKWhenSendGetRequest() throws IOException, InterruptedException, URISyntaxException {
|
public void shouldReturnStatusOKWhenSendGetRequest() throws IOException, InterruptedException, URISyntaxException {
|
@ -18,7 +18,7 @@ import static org.junit.Assert.assertThat;
|
|||||||
/**
|
/**
|
||||||
* Created by adam.
|
* Created by adam.
|
||||||
*/
|
*/
|
||||||
public class HttpResponseTest {
|
public class HttpResponseIntegrationTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldReturnStatusOKWhenSendGetRequest() throws IOException, InterruptedException, URISyntaxException {
|
public void shouldReturnStatusOKWhenSendGetRequest() throws IOException, InterruptedException, URISyntaxException {
|
@ -5,10 +5,12 @@ import org.junit.Test;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.SubmissionPublisher;
|
import java.util.concurrent.SubmissionPublisher;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import static org.assertj.core.api.Java6Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.awaitility.Awaitility.await;
|
||||||
|
|
||||||
public class ReactiveStreamsTest {
|
public class ReactiveStreamsUnitTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenPublisher_whenSubscribeToIt_thenShouldConsumeAllElements() throws InterruptedException {
|
public void givenPublisher_whenSubscribeToIt_thenShouldConsumeAllElements() throws InterruptedException {
|
||||||
@ -25,7 +27,7 @@ public class ReactiveStreamsTest {
|
|||||||
|
|
||||||
//then
|
//then
|
||||||
|
|
||||||
await().atMost(1000, TimeUnit.MILLISECONDS).until(
|
await().atMost(1000, TimeUnit.MILLISECONDS).untilAsserted(
|
||||||
() -> assertThat(subscriber.consumedElements).containsExactlyElementsOf(items)
|
() -> assertThat(subscriber.consumedElements).containsExactlyElementsOf(items)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -46,7 +48,7 @@ public class ReactiveStreamsTest {
|
|||||||
publisher.close();
|
publisher.close();
|
||||||
|
|
||||||
//then
|
//then
|
||||||
await().atMost(1000, TimeUnit.MILLISECONDS).until(
|
await().atMost(1000, TimeUnit.MILLISECONDS).untilAsserted(
|
||||||
() -> assertThat(subscriber.consumedElements).containsExactlyElementsOf(expectedResult)
|
() -> assertThat(subscriber.consumedElements).containsExactlyElementsOf(expectedResult)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -66,7 +68,7 @@ public class ReactiveStreamsTest {
|
|||||||
publisher.close();
|
publisher.close();
|
||||||
|
|
||||||
//then
|
//then
|
||||||
await().atMost(1000, TimeUnit.MILLISECONDS).until(
|
await().atMost(1000, TimeUnit.MILLISECONDS).untilAsserted(
|
||||||
() -> assertThat(subscriber.consumedElements).containsExactlyElementsOf(expected)
|
() -> assertThat(subscriber.consumedElements).containsExactlyElementsOf(expected)
|
||||||
);
|
);
|
||||||
}
|
}
|
@ -7,7 +7,7 @@ import java.lang.invoke.VarHandle;
|
|||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
public class VariableHandlesTest {
|
public class VariableHandlesUnitTest {
|
||||||
|
|
||||||
public int publicTestVariable = 1;
|
public int publicTestVariable = 1;
|
||||||
private int privateTestVariable = 1;
|
private int privateTestVariable = 1;
|
||||||
@ -20,22 +20,22 @@ public class VariableHandlesTest {
|
|||||||
public void whenVariableHandleForPublicVariableIsCreated_ThenItIsInitializedProperly() throws NoSuchFieldException, IllegalAccessException {
|
public void whenVariableHandleForPublicVariableIsCreated_ThenItIsInitializedProperly() throws NoSuchFieldException, IllegalAccessException {
|
||||||
VarHandle publicIntHandle = MethodHandles
|
VarHandle publicIntHandle = MethodHandles
|
||||||
.lookup()
|
.lookup()
|
||||||
.in(VariableHandlesTest.class)
|
.in(VariableHandlesUnitTest.class)
|
||||||
.findVarHandle(VariableHandlesTest.class, "publicTestVariable", int.class);
|
.findVarHandle(VariableHandlesUnitTest.class, "publicTestVariable", int.class);
|
||||||
|
|
||||||
assertThat(publicIntHandle.coordinateTypes().size() == 1);
|
assertThat(publicIntHandle.coordinateTypes().size() == 1);
|
||||||
assertThat(publicIntHandle.coordinateTypes().get(0) == VariableHandles.class);
|
assertThat(publicIntHandle.coordinateTypes().get(0) == VariableHandlesUnitTest.class);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenVariableHandleForPrivateVariableIsCreated_ThenItIsInitializedProperly() throws NoSuchFieldException, IllegalAccessException {
|
public void whenVariableHandleForPrivateVariableIsCreated_ThenItIsInitializedProperly() throws NoSuchFieldException, IllegalAccessException {
|
||||||
VarHandle privateIntHandle = MethodHandles
|
VarHandle privateIntHandle = MethodHandles
|
||||||
.privateLookupIn(VariableHandlesTest.class, MethodHandles.lookup())
|
.privateLookupIn(VariableHandlesUnitTest.class, MethodHandles.lookup())
|
||||||
.findVarHandle(VariableHandlesTest.class, "privateTestVariable", int.class);
|
.findVarHandle(VariableHandlesUnitTest.class, "privateTestVariable", int.class);
|
||||||
|
|
||||||
assertThat(privateIntHandle.coordinateTypes().size() == 1);
|
assertThat(privateIntHandle.coordinateTypes().size() == 1);
|
||||||
assertThat(privateIntHandle.coordinateTypes().get(0) == VariableHandlesTest.class);
|
assertThat(privateIntHandle.coordinateTypes().get(0) == VariableHandlesUnitTest.class);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -52,8 +52,8 @@ public class VariableHandlesTest {
|
|||||||
public void givenVarHandle_whenGetIsInvoked_ThenValueOfVariableIsReturned() throws NoSuchFieldException, IllegalAccessException {
|
public void givenVarHandle_whenGetIsInvoked_ThenValueOfVariableIsReturned() throws NoSuchFieldException, IllegalAccessException {
|
||||||
VarHandle publicIntHandle = MethodHandles
|
VarHandle publicIntHandle = MethodHandles
|
||||||
.lookup()
|
.lookup()
|
||||||
.in(VariableHandlesTest.class)
|
.in(VariableHandlesUnitTest.class)
|
||||||
.findVarHandle(VariableHandlesTest.class, "publicTestVariable", int.class);
|
.findVarHandle(VariableHandlesUnitTest.class, "publicTestVariable", int.class);
|
||||||
|
|
||||||
assertThat((int) publicIntHandle.get(this) == 1);
|
assertThat((int) publicIntHandle.get(this) == 1);
|
||||||
}
|
}
|
||||||
@ -62,8 +62,8 @@ public class VariableHandlesTest {
|
|||||||
public void givenVarHandle_whenSetIsInvoked_ThenValueOfVariableIsChanged() throws NoSuchFieldException, IllegalAccessException {
|
public void givenVarHandle_whenSetIsInvoked_ThenValueOfVariableIsChanged() throws NoSuchFieldException, IllegalAccessException {
|
||||||
VarHandle publicIntHandle = MethodHandles
|
VarHandle publicIntHandle = MethodHandles
|
||||||
.lookup()
|
.lookup()
|
||||||
.in(VariableHandlesTest.class)
|
.in(VariableHandlesUnitTest.class)
|
||||||
.findVarHandle(VariableHandlesTest.class, "variableToSet", int.class);
|
.findVarHandle(VariableHandlesUnitTest.class, "variableToSet", int.class);
|
||||||
publicIntHandle.set(this, 15);
|
publicIntHandle.set(this, 15);
|
||||||
|
|
||||||
assertThat((int) publicIntHandle.get(this) == 15);
|
assertThat((int) publicIntHandle.get(this) == 15);
|
||||||
@ -73,8 +73,8 @@ public class VariableHandlesTest {
|
|||||||
public void givenVarHandle_whenCompareAndSetIsInvoked_ThenValueOfVariableIsChanged() throws NoSuchFieldException, IllegalAccessException {
|
public void givenVarHandle_whenCompareAndSetIsInvoked_ThenValueOfVariableIsChanged() throws NoSuchFieldException, IllegalAccessException {
|
||||||
VarHandle publicIntHandle = MethodHandles
|
VarHandle publicIntHandle = MethodHandles
|
||||||
.lookup()
|
.lookup()
|
||||||
.in(VariableHandlesTest.class)
|
.in(VariableHandlesUnitTest.class)
|
||||||
.findVarHandle(VariableHandlesTest.class, "variableToCompareAndSet", int.class);
|
.findVarHandle(VariableHandlesUnitTest.class, "variableToCompareAndSet", int.class);
|
||||||
publicIntHandle.compareAndSet(this, 1, 100);
|
publicIntHandle.compareAndSet(this, 1, 100);
|
||||||
|
|
||||||
assertThat((int) publicIntHandle.get(this) == 100);
|
assertThat((int) publicIntHandle.get(this) == 100);
|
||||||
@ -84,8 +84,8 @@ public class VariableHandlesTest {
|
|||||||
public void givenVarHandle_whenGetAndAddIsInvoked_ThenValueOfVariableIsChanged() throws NoSuchFieldException, IllegalAccessException {
|
public void givenVarHandle_whenGetAndAddIsInvoked_ThenValueOfVariableIsChanged() throws NoSuchFieldException, IllegalAccessException {
|
||||||
VarHandle publicIntHandle = MethodHandles
|
VarHandle publicIntHandle = MethodHandles
|
||||||
.lookup()
|
.lookup()
|
||||||
.in(VariableHandlesTest.class)
|
.in(VariableHandlesUnitTest.class)
|
||||||
.findVarHandle(VariableHandlesTest.class, "variableToGetAndAdd", int.class);
|
.findVarHandle(VariableHandlesUnitTest.class, "variableToGetAndAdd", int.class);
|
||||||
int before = (int) publicIntHandle.getAndAdd(this, 200);
|
int before = (int) publicIntHandle.getAndAdd(this, 200);
|
||||||
|
|
||||||
assertThat(before == 0);
|
assertThat(before == 0);
|
||||||
@ -96,8 +96,8 @@ public class VariableHandlesTest {
|
|||||||
public void givenVarHandle_whenGetAndBitwiseOrIsInvoked_ThenValueOfVariableIsChanged() throws NoSuchFieldException, IllegalAccessException {
|
public void givenVarHandle_whenGetAndBitwiseOrIsInvoked_ThenValueOfVariableIsChanged() throws NoSuchFieldException, IllegalAccessException {
|
||||||
VarHandle publicIntHandle = MethodHandles
|
VarHandle publicIntHandle = MethodHandles
|
||||||
.lookup()
|
.lookup()
|
||||||
.in(VariableHandlesTest.class)
|
.in(VariableHandlesUnitTest.class)
|
||||||
.findVarHandle(VariableHandlesTest.class, "variableToBitwiseOr", byte.class);
|
.findVarHandle(VariableHandlesUnitTest.class, "variableToBitwiseOr", byte.class);
|
||||||
byte before = (byte) publicIntHandle.getAndBitwiseOr(this, (byte) 127);
|
byte before = (byte) publicIntHandle.getAndBitwiseOr(this, (byte) 127);
|
||||||
|
|
||||||
assertThat(before == 0);
|
assertThat(before == 0);
|
Loading…
x
Reference in New Issue
Block a user