Skip to content

Commit

Permalink
chore(Response.java): Refactored the code to return sorted plain comm…
Browse files Browse the repository at this point in the history
…and results.
  • Loading branch information
AsifNawaz-cnic committed Nov 9, 2023
1 parent 657b285 commit 56af0e0
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 14 deletions.
15 changes: 15 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// .devcontainer/devcontainer.json
{
"name": "Java",
"image": "mcr.microsoft.com/devcontainers/java",
"customizations": {
"vscode": {
"settings": {
"terminal.integrated.shell.linux": "/bin/bash"
}
},
"extensions": [
"vscjava.vscode-java-pack"
]
}
}
5 changes: 3 additions & 2 deletions .github/workflows/auto-merge-dependabot-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ on:
permissions:
contents: write
pull-requests: write

deployments: write

jobs:
tests:
uses: ./.github/workflows/test.yml
Expand All @@ -31,4 +32,4 @@ jobs:
run: gh pr merge --auto --merge "$PR_URL"
env:
PR_URL: ${{github.event.pull_request.html_url}}
GITHUB_TOKEN: ${{secrets.RTLDEV_MW_CI_TOKEN}}
GITHUB_TOKEN: ${{secrets.RTLDEV_MW_CI_TOKEN}}
1 change: 1 addition & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ jobs:
contents: write
issues: write
deployments: write

needs: build
steps:
- name: Checkout
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
runs-on: ${{ vars.RTLDEV_MW_CI_OS }}
permissions:
contents: read
packages: read

steps:
- name: Checkout
uses: actions/checkout@v4
Expand All @@ -32,7 +32,6 @@ jobs:
runs-on: ${{ vars.RTLDEV_MW_CI_OS }}
permissions:
contents: write
packages: write
deployments: write

strategy:
Expand Down
6 changes: 5 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@
<version>3.6.2</version>
<configuration>
<verbose>true</verbose>
<source>8</source>
<additionalOptions>-html5</additionalOptions>
</configuration>
<executions>
Expand Down Expand Up @@ -123,6 +122,11 @@
<artifactId>maven-install-plugin</artifactId>
<version>3.1.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>3.4.5</version> <!-- Use the desired version -->
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
Expand Down
17 changes: 9 additions & 8 deletions src/main/java/net/hexonet/apiconnector/Response.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

/**
Expand Down Expand Up @@ -303,13 +304,13 @@ public Map<String, String> getCommand() {
*/
public String getCommandPlain() {
StringBuilder tmp = new StringBuilder("");
Iterator<Map.Entry<String, String>> it = this.command.entrySet().iterator();
while (it.hasNext()) {
Map.Entry<String, String> pair = it.next();
tmp.append(pair.getKey());
tmp.append(" = ");
tmp.append(pair.getValue());
tmp.append("\n");
List<Map.Entry<String, String>> sortedEntries = new ArrayList<>(this.command.entrySet());
sortedEntries.sort(Map.Entry.comparingByKey());
for (Map.Entry<String, String> pair : sortedEntries) {
tmp.append(pair.getKey())
.append(" = ")
.append(pair.getValue())
.append("\n");
}
return tmp.toString();
}
Expand Down Expand Up @@ -625,4 +626,4 @@ private boolean hasNextRecord() {
private boolean hasPreviousRecord() {
return (this.recordIndex > 0 && this.hasCurrentRecord());
}
}
}
2 changes: 1 addition & 1 deletion src/test/java/net/hexonet/apiconnector/ResponseTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public void getCommandPlainSecure() {
cmd.put("SUBUSER", "test.user");
cmd.put("PASSWORD", "test.passw0rd");
Response r = new Response("", cmd);
String str = "SUBUSER = test.user\nCOMMAND = CheckAuthentication\nPASSWORD = ***\n";
String str = "COMMAND = CheckAuthentication\nPASSWORD = ***\nSUBUSER = test.user\n";
assertEquals(str, r.getCommandPlain());
}

Expand Down

0 comments on commit 56af0e0

Please sign in to comment.