Skip to content

Commit

Permalink
Merge branch 'master' into patch-3
Browse files Browse the repository at this point in the history
  • Loading branch information
Dibyajyoti1515 authored Oct 6, 2024
2 parents 221e07e + 084817f commit 5891d28
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 20 deletions.
27 changes: 27 additions & 0 deletions .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -3168,6 +3168,33 @@
"contributions": [
"code"
]
},
{
"login": "Xcyq",
"name": "Xcyq",
"avatar_url": "https://avatars.githubusercontent.com/u/39086666?v=4",
"profile": "https://github.com/Xcyq",
"contributions": [
"code"
]
},
{
"login": "Ritabrata1080",
"name": "Ritabrata",
"avatar_url": "https://avatars.githubusercontent.com/u/60834250?v=4",
"profile": "https://github.com/Ritabrata1080",
"contributions": [
"review"
]
},
{
"login": "trivikr",
"name": "Trivikram Kamat",
"avatar_url": "https://avatars.githubusercontent.com/u/16024985?v=4",
"profile": "https://github.com/trivikr",
"contributions": [
"code"
]
}
],
"contributorsPerLine": 6,
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/maven-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,20 @@ jobs:
steps:

- name: Checkout Code
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
# Disabling shallow clone for improving relevancy of SonarQube reporting
fetch-depth: 0

- name: Set up JDK 17
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
cache: 'maven'

- name: Cache local Maven repository
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
Expand All @@ -64,7 +64,7 @@ jobs:
# Cache Sonar packages which as used to run analysis and collect metrics
- name: Cache SonarCloud packages
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/maven-pr-builder.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,19 @@ jobs:
steps:

- name: Checkout Code
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}

- name: Set up JDK 17
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
cache: 'maven'

- name: Cache local Maven repository
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
Expand All @@ -63,7 +63,7 @@ jobs:
# Cache Sonar packages which as used to run analysis and collect metrics
- name: Cache SonarCloud packages
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
Expand Down
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
[![Coverage](https://sonarcloud.io/api/project_badges/measure?project=iluwatar_java-design-patterns&metric=coverage)](https://sonarcloud.io/dashboard?id=iluwatar_java-design-patterns)
[![Join the chat at https://gitter.im/iluwatar/java-design-patterns](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/iluwatar/java-design-patterns?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
[![All Contributors](https://img.shields.io/badge/all_contributors-347-orange.svg?style=flat-square)](#contributors-)
[![All Contributors](https://img.shields.io/badge/all_contributors-350-orange.svg?style=flat-square)](#contributors-)
<!-- ALL-CONTRIBUTORS-BADGE:END -->

<br/>
Expand Down Expand Up @@ -522,6 +522,11 @@ This project is licensed under the terms of the MIT license.
<td align="center" valign="top" width="16.66%"><a href="https://github.com/romannimets"><img src="https://avatars.githubusercontent.com/u/137268574?v=4?s=100" width="100px;" alt="romannimets"/><br /><sub><b>romannimets</b></sub></a><br /><a href="https://github.com/iluwatar/java-design-patterns/commits?author=romannimets" title="Code">💻</a></td>
<td align="center" valign="top" width="16.66%"><a href="https://github.com/Joel-Dandin"><img src="https://avatars.githubusercontent.com/u/60149879?v=4?s=100" width="100px;" alt="Joel"/><br /><sub><b>Joel</b></sub></a><br /><a href="https://github.com/iluwatar/java-design-patterns/commits?author=Joel-Dandin" title="Code">💻</a></td>
<td align="center" valign="top" width="16.66%"><a href="https://github.com/244Walyson"><img src="https://avatars.githubusercontent.com/u/125759796?v=4?s=100" width="100px;" alt="Walyson Moises"/><br /><sub><b>Walyson Moises</b></sub></a><br /><a href="https://github.com/iluwatar/java-design-patterns/commits?author=244Walyson" title="Code">💻</a></td>
<td align="center" valign="top" width="16.66%"><a href="https://github.com/Xcyq"><img src="https://avatars.githubusercontent.com/u/39086666?v=4?s=100" width="100px;" alt="Xcyq"/><br /><sub><b>Xcyq</b></sub></a><br /><a href="https://github.com/iluwatar/java-design-patterns/commits?author=Xcyq" title="Code">💻</a></td>
</tr>
<tr>
<td align="center" valign="top" width="16.66%"><a href="https://github.com/Ritabrata1080"><img src="https://avatars.githubusercontent.com/u/60834250?v=4?s=100" width="100px;" alt="Ritabrata"/><br /><sub><b>Ritabrata</b></sub></a><br /><a href="https://github.com/iluwatar/java-design-patterns/pulls?q=is%3Apr+reviewed-by%3ARitabrata1080" title="Reviewed Pull Requests">👀</a></td>
<td align="center" valign="top" width="16.66%"><a href="https://github.com/trivikr"><img src="https://avatars.githubusercontent.com/u/16024985?v=4?s=100" width="100px;" alt="Trivikram Kamat"/><br /><sub><b>Trivikram Kamat</b></sub></a><br /><a href="https://github.com/iluwatar/java-design-patterns/commits?author=trivikr" title="Code">💻</a></td>
</tr>
</tbody>
</table>
Expand Down
2 changes: 1 addition & 1 deletion event-based-asynchronous/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
<dependency>
<groupId>org.awaitility</groupId>
<artifactId>awaitility</artifactId>
<version>4.2.1</version>
<version>4.2.2</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
package com.iluwatar.partialresponse;

import java.lang.reflect.Field;
import java.util.StringJoiner;

/**
* Map a video to json.
Expand All @@ -39,18 +40,15 @@ public class FieldJsonMapper {
* @return json of required fields from video
*/
public String toJson(Video video, String[] fields) throws Exception {
var json = new StringBuilder().append("{");
var json = new StringJoiner(",", "{", "}");

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(",");
}
json.add(getString(video, Video.class.getDeclaredField(fields[i])));
i++;
}
json.append("}");

return json.toString();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public String toString() {
+ "\"length\": " + length + ","
+ "\"description\": \"" + description + "\","
+ "\"director\": \"" + director + "\","
+ "\"language\": \"" + language + "\","
+ "\"language\": \"" + language + "\""
+ "}";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ void shouldGiveVideoDetailsById() throws Exception {
var actualDetails = resource.getDetails(1);

var expectedDetails = "{\"id\": 1,\"title\": \"Avatar\",\"length\": 178,\"description\": "
+ "\"epic science fiction film\",\"director\": \"James Cameron\",\"language\": \"English\",}";
+ "\"epic science fiction film\",\"director\": \"James Cameron\",\"language\": \"English\"}";
Assertions.assertEquals(expectedDetails, actualDetails);
}

Expand All @@ -78,4 +78,17 @@ void shouldGiveSpecifiedFieldsInformationOfVideo() throws Exception {

Assertions.assertEquals(expectedDetails, actualFieldsDetails);
}
}

@Test
void shouldAllSpecifiedFieldsInformationOfVideo() throws Exception {
var fields = new String[]{"id", "title", "length", "description", "director", "language"};

var expectedDetails = "{\"id\": 1,\"title\": \"Avatar\",\"length\": 178,\"description\": "
+ "\"epic science fiction film\",\"director\": \"James Cameron\",\"language\": \"English\"}";
Mockito.when(fieldJsonMapper.toJson(any(Video.class), eq(fields))).thenReturn(expectedDetails);

var actualFieldsDetails = resource.getDetails(1, fields);

Assertions.assertEquals(expectedDetails, actualFieldsDetails);
}
}
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
<maven-checkstyle-plugin.version>3.4.0</maven-checkstyle-plugin.version>
<license-maven-plugin.version>4.5</license-maven-plugin.version>
<urm-maven-plugin.version>2.1.1</urm-maven-plugin.version>
<slf4j.version>2.0.13</slf4j.version>
<slf4j.version>2.0.16</slf4j.version>
<logback.version>1.5.6</logback.version>
<!-- SonarCloud -->
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
Expand Down

0 comments on commit 5891d28

Please sign in to comment.