Skip to content

Commit 6b2f321

Browse files
committed
Changed added
1 parent 979ab7c commit 6b2f321

File tree

3 files changed

+58
-10
lines changed

3 files changed

+58
-10
lines changed

data-loader/cli/src/main/java/com/scalar/db/dataloader/cli/command/dataexport/ConsoleExportProgressReporter.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,14 @@ public static void reportError(String message, Throwable throwable) {
6262
}
6363
}
6464

65-
/**
66-
* Prints a formatted waring message to the console.
67-
*
68-
* @param message the error description
69-
*/
70-
public static void reportWarning(String message) {
71-
System.err.println("%n!! Warning: " + message);
72-
}
65+
/**
66+
* Prints a formatted waring message to the console.
67+
*
68+
* @param message the error description
69+
*/
70+
public static void reportWarning(String message) {
71+
System.err.printf("%n⚠️ Warning: %s%n", message);
72+
}
7373

7474
/**
7575
* Formats elapsed time in "Xm Ys" format.

data-loader/cli/src/main/java/com/scalar/db/dataloader/cli/command/dataexport/ExportCommand.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,8 @@ private void warnAboutIgnoredDeprecatedOptions() {
157157
+ "Use the 'scalar.db.consensus_commit.include_metadata.enabled' configuration property "
158158
+ "in your ScalarDB properties file to control whether transaction metadata is included in scan operations.|@");
159159

160-
// logger.warn(warning);
161-
ConsoleExportProgressReporter.reportWarning(warning);
160+
// logger.warn(warning);
161+
ConsoleExportProgressReporter.reportWarning(warning);
162162
}
163163
}
164164

data-loader/cli/src/test/java/com/scalar/db/dataloader/cli/command/dataexport/ConsoleExportProgressReporterTest.java

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,4 +105,52 @@ void testReportError_shouldPrintMessageWithoutExceptionWhenNull()
105105
System.setErr(originalErr);
106106
}
107107
}
108+
109+
@Test
110+
void testReportWarning_shouldPrintFormattedWarningMessage() throws UnsupportedEncodingException {
111+
112+
ByteArrayOutputStream errContent = new ByteArrayOutputStream();
113+
PrintStream originalErr = System.err;
114+
System.setErr(new PrintStream(errContent, true, "UTF-8"));
115+
116+
try {
117+
String warningMessage = "Deprecated option detected";
118+
119+
ConsoleExportProgressReporter.reportWarning(warningMessage);
120+
121+
String output = errContent.toString("UTF-8");
122+
123+
// Expected core formatted message
124+
assertTrue(
125+
output.contains("⚠️ Warning: " + warningMessage), "Expected formatted warning message");
126+
127+
// Should start with a newline produced by %n
128+
assertTrue(
129+
output.startsWith(System.lineSeparator()), "Expected output to start with a newline");
130+
131+
// Should end with a newline from the trailing %n
132+
assertTrue(output.endsWith(System.lineSeparator()), "Expected output to end with a newline");
133+
} finally {
134+
System.setErr(originalErr);
135+
}
136+
}
137+
138+
@Test
139+
void testReportWarning_shouldNotIncludeErrorSpecificFields() throws UnsupportedEncodingException {
140+
141+
ByteArrayOutputStream errContent = new ByteArrayOutputStream();
142+
PrintStream originalErr = System.err;
143+
System.setErr(new PrintStream(errContent, true, "UTF-8"));
144+
145+
try {
146+
ConsoleExportProgressReporter.reportWarning("Check your input");
147+
148+
String output = errContent.toString("UTF-8");
149+
150+
assertFalse(output.contains("Cause:"), "Warning output must not include cause");
151+
assertFalse(output.contains("❌"), "Warning output must not include error symbol");
152+
} finally {
153+
System.setErr(originalErr);
154+
}
155+
}
108156
}

0 commit comments

Comments
 (0)