Java 11 migrate remaining p (#1122)

* Moves partial-response to Java 11

* Moves pipeline to Java 11

* Moves poison-pill to Java 11

* Moves priority-queue to Java 11

* Moves private-class-data to Java 11

* Moves producer-consumer to Java 11

* Moves promise to Java 11

* Moves property to Java 11

* Moves prototype to Java 11

* Moves proxy to Java 11

* Corrects checkstyle errors

* Fixes build for pipeline pattern
This commit is contained in:
Anurag Agarwal
2020-01-16 11:36:36 +05:30
committed by Ilkka Seppälä
parent 1401accb4f
commit 428efc7d53
82 changed files with 532 additions and 601 deletions

View File

@ -44,30 +44,31 @@ public class App {
* @param args program argument.
*/
public static void main(String[] args) throws Exception {
Map<Integer, Video> videos = Map.of(
var videos = Map.of(
1, new Video(1, "Avatar", 178, "epic science fiction film",
"James Cameron", "English"),
2, new Video(2, "Godzilla Resurgence", 120, "Action & drama movie|",
"Hideaki Anno", "Japanese"),
3, new Video(3, "Interstellar", 169, "Adventure & Sci-Fi",
"Christopher Nolan", "English"));
VideoResource videoResource = new VideoResource(new FieldJsonMapper(), videos);
"Christopher Nolan", "English")
);
var videoResource = new VideoResource(new FieldJsonMapper(), videos);
LOGGER.info("Retrieving full response from server:-");
LOGGER.info("Get all video information:");
String videoDetails = videoResource.getDetails(1);
var videoDetails = videoResource.getDetails(1);
LOGGER.info(videoDetails);
LOGGER.info("----------------------------------------------------------");
LOGGER.info("Retrieving partial response from server:-");
LOGGER.info("Get video @id, @title, @director:");
String specificFieldsDetails = videoResource.getDetails(3, "id", "title", "director");
var specificFieldsDetails = videoResource.getDetails(3, "id", "title", "director");
LOGGER.info(specificFieldsDetails);
LOGGER.info("Get video @id, @length:");
String videoLength = videoResource.getDetails(3, "id", "length");
var videoLength = videoResource.getDetails(3, "id", "length");
LOGGER.info(videoLength);
}
}

View File

@ -38,13 +38,16 @@ public class FieldJsonMapper {
* @return json of required fields from video
*/
public String toJson(Video video, String[] fields) throws Exception {
StringBuilder json = new StringBuilder().append("{");
var json = new StringBuilder().append("{");
for (int i = 0, fieldsLength = fields.length; i < fieldsLength; i++) {
var i = 0;
var fieldsLength = fields.length;
while (i < fieldsLength) {
json.append(getString(video, Video.class.getDeclaredField(fields[i])));
if (i != fieldsLength - 1) {
json.append(",");
}
i++;
}
json.append("}");
return json.toString();
@ -52,7 +55,7 @@ public class FieldJsonMapper {
private String getString(Video video, Field declaredField) throws IllegalAccessException {
declaredField.setAccessible(true);
Object value = declaredField.get(video);
var value = declaredField.get(video);
if (declaredField.get(video) instanceof Integer) {
return "\"" + declaredField.getName() + "\"" + ": " + value;
}

View File

@ -32,8 +32,7 @@ public class AppTest {
@Test
public void main() throws Exception {
String[] args = {};
App.main(args);
App.main(new String[]{});
}
}

View File

@ -23,11 +23,11 @@
package com.iluwatar.partialresponse;
import static org.junit.Assert.assertEquals;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
/**
* tests {@link FieldJsonMapper}.
*/
@ -41,12 +41,15 @@ public class FieldJsonMapperTest {
@Test
public void shouldReturnJsonForSpecifiedFieldsInVideo() throws Exception {
String[] fields = new String[]{"id", "title", "length"};
Video video = new Video(2, "Godzilla Resurgence", 120, "Action & drama movie|", "Hideaki Anno", "Japanese");
var fields = new String[]{"id", "title", "length"};
var video = new Video(
2, "Godzilla Resurgence", 120,
"Action & drama movie|", "Hideaki Anno", "Japanese"
);
String jsonFieldResponse = mapper.toJson(video, fields);
var jsonFieldResponse = mapper.toJson(video, fields);
String expectedDetails = "{\"id\": 2,\"title\": \"Godzilla Resurgence\",\"length\": 120}";
var expectedDetails = "{\"id\": 2,\"title\": \"Godzilla Resurgence\",\"length\": 120}";
assertEquals(expectedDetails, jsonFieldResponse);
}
}

View File

@ -23,19 +23,18 @@
package com.iluwatar.partialresponse;
import static org.junit.Assert.assertEquals;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.when;
import java.util.Map;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import java.util.Map;
import static org.junit.Assert.assertEquals;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.when;
/**
* tests {@link VideoResource}.
*/
@ -48,33 +47,33 @@ public class VideoResourceTest {
@Before
public void setUp() {
Map<Integer, Video> videos = Map.of(
1, new Video(1, "Avatar", 178, "epic science fiction film",
"James Cameron", "English"),
2, new Video(2, "Godzilla Resurgence", 120, "Action & drama movie|",
"Hideaki Anno", "Japanese"),
3, new Video(3, "Interstellar", 169, "Adventure & Sci-Fi",
"Christopher Nolan", "English"));
var videos = Map.of(
1, new Video(1, "Avatar", 178, "epic science fiction film",
"James Cameron", "English"),
2, new Video(2, "Godzilla Resurgence", 120, "Action & drama movie|",
"Hideaki Anno", "Japanese"),
3, new Video(3, "Interstellar", 169, "Adventure & Sci-Fi",
"Christopher Nolan", "English"));
resource = new VideoResource(fieldJsonMapper, videos);
}
@Test
public void shouldGiveVideoDetailsById() throws Exception {
String actualDetails = resource.getDetails(1);
var actualDetails = resource.getDetails(1);
String expectedDetails = "{\"id\": 1,\"title\": \"Avatar\",\"length\": 178,\"description\": "
var expectedDetails = "{\"id\": 1,\"title\": \"Avatar\",\"length\": 178,\"description\": "
+ "\"epic science fiction film\",\"director\": \"James Cameron\",\"language\": \"English\",}";
assertEquals(expectedDetails, actualDetails);
}
@Test
public void shouldGiveSpecifiedFieldsInformationOfVideo() throws Exception {
String[] fields = new String[]{"id", "title", "length"};
var fields = new String[]{"id", "title", "length"};
String expectedDetails = "{\"id\": 1,\"title\": \"Avatar\",\"length\": 178}";
var expectedDetails = "{\"id\": 1,\"title\": \"Avatar\",\"length\": 178}";
when(fieldJsonMapper.toJson(any(Video.class), eq(fields))).thenReturn(expectedDetails);
String actualFieldsDetails = resource.getDetails(2, fields);
var actualFieldsDetails = resource.getDetails(2, fields);
assertEquals(expectedDetails, actualFieldsDetails);
}