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 72cedc5
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 17 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"
]
}
}
12 changes: 7 additions & 5 deletions .github/workflows/auto-merge-dependabot-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,21 @@ on:
- opened
- synchronize

permissions:
contents: write
pull-requests: write

jobs:
tests:
uses: ./.github/workflows/test.yml
secrets: inherit

permissions:
contents: read

dependabot:
name: Auto-merge Dependabot PR
runs-on: ${{ vars.RTLDEV_MW_CI_OS }}
needs: tests
permissions:
contents: write
pull-requests: write

if: ${{ github.actor == 'dependabot[bot]' }}
steps:
- name: Dependabot metadata
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ on:
- master

jobs:
build:
name: Build
tests:
uses: ./.github/workflows/test.yml
permissions:
contents: read
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 72cedc5

Please sign in to comment.