Skip to content

Commit

Permalink
fix spotless
Browse files Browse the repository at this point in the history
Signed-off-by: Brindrajsinh-Chauhan <[email protected]>
  • Loading branch information
Brindrajsinh-Chauhan committed Apr 10, 2024
1 parent d8e5a79 commit c10f356
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -281,9 +281,7 @@ private void readInput() {
try (Scanner scanner = new Scanner(parentCommand.in, UTF_8.name())) {
inputData = scanner.nextLine();
} catch (NoSuchElementException e) {
throw new ParameterException(
spec.commandLine(),
"Unable to read input data." + e);
throw new ParameterException(spec.commandLine(), "Unable to read input data." + e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,16 +264,16 @@ public void encodeWithEmptyStdInputMustRaiseAnError() throws Exception {
public void decodeWithoutPathMustWriteToStandardOutput() {

final String inputData =
"0xf853a00000000000000000000000000000000000000000000000000000000000000000ea94be068f726a13c8d"
+ "46c44be6ce9d275600e1735a4945ff6f4b66a46a2b2310a6f3a93aaddc0d9a1c193808400000000c0";
"0xf853a00000000000000000000000000000000000000000000000000000000000000000ea94be068f726a13c8d"
+ "46c44be6ce9d275600e1735a4945ff6f4b66a46a2b2310a6f3a93aaddc0d9a1c193808400000000c0";

// set stdin
final ByteArrayInputStream stdIn = new ByteArrayInputStream(inputData.getBytes(UTF_8));

parseCommand(stdIn, RLP_SUBCOMMAND_NAME, RLP_DECODE_SUBCOMMAND_NAME);

final String expectedValidatorString =
"[0xbe068f726a13c8d46c44be6ce9d275600e1735a4, 0x5ff6f4b66a46a2b2310a6f3a93aaddc0d9a1c193]";
"[0xbe068f726a13c8d46c44be6ce9d275600e1735a4, 0x5ff6f4b66a46a2b2310a6f3a93aaddc0d9a1c193]";
assertThat(commandOutput.toString(UTF_8)).contains(expectedValidatorString);
assertThat(commandErrorOutput.toString(UTF_8)).isEmpty();
}
Expand All @@ -282,16 +282,16 @@ public void decodeWithoutPathMustWriteToStandardOutput() {
public void decodeQBFTWithoutPathMustWriteToStandardOutput() {

final String inputData =
"0xf84fa00000000000000000000000000000000000000000000000000000000000000000ea94241f804efb46f71acaa"
+ "5be94a62f7798e89c3724946cdf72da457453063ea92e7fa5ac30afbcec28cdc080c0";
"0xf84fa00000000000000000000000000000000000000000000000000000000000000000ea94241f804efb46f71acaa"
+ "5be94a62f7798e89c3724946cdf72da457453063ea92e7fa5ac30afbcec28cdc080c0";

// set stdin
final ByteArrayInputStream stdIn = new ByteArrayInputStream(inputData.getBytes(UTF_8));

parseCommand(stdIn, RLP_SUBCOMMAND_NAME, RLP_DECODE_SUBCOMMAND_NAME, "--type", RLP_QBFT_TYPE);

final String expectedValidatorString =
"[0x241f804efb46f71acaa5be94a62f7798e89c3724, 0x6cdf72da457453063ea92e7fa5ac30afbcec28cd]";
"[0x241f804efb46f71acaa5be94a62f7798e89c3724, 0x6cdf72da457453063ea92e7fa5ac30afbcec28cd]";
assertThat(commandOutput.toString(UTF_8)).contains(expectedValidatorString);
assertThat(commandErrorOutput.toString(UTF_8)).isEmpty();
}
Expand All @@ -302,16 +302,16 @@ public void decodeWithOutputFileMustWriteInThisFile() throws Exception {
final File file = File.createTempFile("ibftValidators", "rlp");

final String inputData =
"0xf853a00000000000000000000000000000000000000000000000000000000000000000ea94be068f726a13c8d"
+ "46c44be6ce9d275600e1735a4945ff6f4b66a46a2b2310a6f3a93aaddc0d9a1c193808400000000c0";
"0xf853a00000000000000000000000000000000000000000000000000000000000000000ea94be068f726a13c8d"
+ "46c44be6ce9d275600e1735a4945ff6f4b66a46a2b2310a6f3a93aaddc0d9a1c193808400000000c0";

// set stdin
final ByteArrayInputStream stdIn = new ByteArrayInputStream(inputData.getBytes(UTF_8));

parseCommand(stdIn, RLP_SUBCOMMAND_NAME, RLP_DECODE_SUBCOMMAND_NAME, "--to", file.getPath());

final String expectedValidatorString =
"[0xbe068f726a13c8d46c44be6ce9d275600e1735a4, 0x5ff6f4b66a46a2b2310a6f3a93aaddc0d9a1c193]";
"[0xbe068f726a13c8d46c44be6ce9d275600e1735a4, 0x5ff6f4b66a46a2b2310a6f3a93aaddc0d9a1c193]";

assertThat(contentOf(file)).contains(expectedValidatorString);

Expand All @@ -326,7 +326,7 @@ public void decodeWithInputFilePathMustReadFromThisFile(final @TempDir Path dir)
try (final BufferedWriter fileWriter = Files.newBufferedWriter(tempJsonFile, UTF_8)) {

fileWriter.write(
"0xf853a00000000000000000000000000000000000000000000000000000000000000000ea94be068f726a13c8d46c44be6ce9d275600e1735a4945ff6f4b66a46a2b2310a6f3a93aaddc0d9a1c193808400000000c0");
"0xf853a00000000000000000000000000000000000000000000000000000000000000000ea94be068f726a13c8d46c44be6ce9d275600e1735a4945ff6f4b66a46a2b2310a6f3a93aaddc0d9a1c193808400000000c0");

fileWriter.flush();

Expand All @@ -337,22 +337,21 @@ public void decodeWithInputFilePathMustReadFromThisFile(final @TempDir Path dir)
tempJsonFile.toFile().getAbsolutePath());

final String expectedValidatorString =
"[0xbe068f726a13c8d46c44be6ce9d275600e1735a4, 0x5ff6f4b66a46a2b2310a6f3a93aaddc0d9a1c193]";
"[0xbe068f726a13c8d46c44be6ce9d275600e1735a4, 0x5ff6f4b66a46a2b2310a6f3a93aaddc0d9a1c193]";

assertThat(commandOutput.toString(UTF_8)).contains(expectedValidatorString);
assertThat(commandErrorOutput.toString(UTF_8)).isEmpty();
}
}

@Test
public void decodeWithInputFilePathToOutputFile(final @TempDir Path dir)
throws Exception {
public void decodeWithInputFilePathToOutputFile(final @TempDir Path dir) throws Exception {
final Path tempInputFile = Files.createTempFile(dir, "input", "json");
final File tempOutputFile = File.createTempFile("ibftValidators", "rlp");
try (final BufferedWriter fileWriter = Files.newBufferedWriter(tempInputFile, UTF_8)) {

fileWriter.write(
"0xf853a00000000000000000000000000000000000000000000000000000000000000000ea94be068f726a13c8d46c44be6ce9d275600e1735a4945ff6f4b66a46a2b2310a6f3a93aaddc0d9a1c193808400000000c0");
"0xf853a00000000000000000000000000000000000000000000000000000000000000000ea94be068f726a13c8d46c44be6ce9d275600e1735a4945ff6f4b66a46a2b2310a6f3a93aaddc0d9a1c193808400000000c0");

fileWriter.flush();

Expand All @@ -362,12 +361,11 @@ public void decodeWithInputFilePathToOutputFile(final @TempDir Path dir)
"--from",
tempInputFile.toFile().getAbsolutePath(),
"--to",
tempOutputFile.getPath()
);
tempOutputFile.getPath());

final String expectedValidatorString =
"[0xbe068f726a13c8d46c44be6ce9d275600e1735a4, 0x5ff6f4b66a46a2b2310a6f3a93aaddc0d9a1c193]";
"[0xbe068f726a13c8d46c44be6ce9d275600e1735a4, 0x5ff6f4b66a46a2b2310a6f3a93aaddc0d9a1c193]";

assertThat(contentOf(tempOutputFile)).contains(expectedValidatorString);
assertThat(commandOutput.toString(UTF_8)).isEmpty();
assertThat(commandErrorOutput.toString(UTF_8)).isEmpty();
Expand All @@ -384,26 +382,19 @@ public void decodeWithEmptyStdInputMustRaiseAnError() throws Exception {
parseCommand(stdIn, RLP_SUBCOMMAND_NAME, RLP_DECODE_SUBCOMMAND_NAME);

assertThat(commandOutput.toString(UTF_8)).isEmpty();
assertThat(commandErrorOutput.toString(UTF_8))
.startsWith("Unable to read input data.");
assertThat(commandErrorOutput.toString(UTF_8)).startsWith("Unable to read input data.");
}

@Test
public void decodeWithInputFilePathMustThrowErrorFileNotExist(final @TempDir Path dir)
throws Exception {

final String nonExistingFileName = "/incorrectPath/wrongFile.json";
final String nonExistingFileName = "/incorrectPath/wrongFile.json";

parseCommand(
RLP_SUBCOMMAND_NAME,
RLP_DECODE_SUBCOMMAND_NAME,
"--from",
nonExistingFileName);
parseCommand(RLP_SUBCOMMAND_NAME, RLP_DECODE_SUBCOMMAND_NAME, "--from", nonExistingFileName);

assertThat(commandOutput.toString(UTF_8)).isEmpty();
assertThat(commandErrorOutput.toString(UTF_8))
.contains(
"Unable to read input file");
assertThat(commandOutput.toString(UTF_8)).isEmpty();
assertThat(commandErrorOutput.toString(UTF_8)).contains("Unable to read input file");
}

@Test
Expand Down

0 comments on commit c10f356

Please sign in to comment.