Skip to content

Commit a007126

Browse files
committed
Simplify unit tests
1 parent efb1a4d commit a007126

File tree

1 file changed

+28
-69
lines changed

1 file changed

+28
-69
lines changed

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

Lines changed: 28 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -275,9 +275,10 @@ void call_withoutMaxThreads_shouldDefaultToAvailableProcessors() {
275275
}
276276

277277
@Test
278-
void call_withDeprecatedIncludeMetadataOption_shouldParseWithoutError() {
279-
// Simulate command line parsing with deprecated --include-metadata option
280-
String[] args = {
278+
void call_withDeprecatedIncludeMetadataOption_shouldParseAndDetectOption() {
279+
// Test that the deprecated option can be parsed without crashing
280+
// and is detected for warning purposes (both long and short forms)
281+
String[] argsWithLongForm = {
281282
"--config",
282283
"scalardb.properties",
283284
"--namespace",
@@ -288,27 +289,8 @@ void call_withDeprecatedIncludeMetadataOption_shouldParseWithoutError() {
288289
"JSON",
289290
"--include-metadata"
290291
};
291-
ExportCommand command = new ExportCommand();
292-
CommandLine cmd = new CommandLine(command);
293-
cmd.parseArgs(args);
294-
295-
// Verify the deprecated option was parsed
296-
// Since it has defaultValue = "false", using the flag sets it to true
297-
assertEquals(true, command.includeTransactionMetadata);
298-
299-
// Verify that the spec was set correctly
300-
command.spec = cmd.getCommandSpec();
301-
302-
// Verify that the command line has the deprecated option matched
303-
assertTrue(
304-
cmd.getParseResult()
305-
.hasMatchedOption(ExportCommandOptions.DEPRECATED_INCLUDE_METADATA_OPTION));
306-
}
307292

308-
@Test
309-
void call_withDeprecatedIncludeMetadataShortOption_shouldParseWithoutError() {
310-
// Simulate command line parsing with deprecated -m short option
311-
String[] args = {
293+
String[] argsWithShortForm = {
312294
"--config",
313295
"scalardb.properties",
314296
"--namespace",
@@ -319,55 +301,36 @@ void call_withDeprecatedIncludeMetadataShortOption_shouldParseWithoutError() {
319301
"JSON",
320302
"-m"
321303
};
322-
ExportCommand command = new ExportCommand();
323-
CommandLine cmd = new CommandLine(command);
324-
cmd.parseArgs(args);
325304

326-
// Verify the deprecated option was parsed
327-
assertEquals(true, command.includeTransactionMetadata);
305+
// Test long form
306+
ExportCommand commandLong = new ExportCommand();
307+
CommandLine cmdLong = new CommandLine(commandLong);
308+
cmdLong.parseArgs(argsWithLongForm);
309+
commandLong.spec = cmdLong.getCommandSpec();
328310

329-
// Verify that the spec was set correctly
330-
command.spec = cmd.getCommandSpec();
331-
332-
// Verify that the command line has the deprecated short option matched
311+
// Verify the option is detected (so warning will trigger)
333312
assertTrue(
334-
cmd.getParseResult()
335-
.hasMatchedOption(ExportCommandOptions.DEPRECATED_INCLUDE_METADATA_OPTION_SHORT));
336-
}
337-
338-
@Test
339-
void call_withDeprecatedIncludeMetadataFalse_shouldParseWithoutError() {
340-
// Simulate command line parsing with deprecated --include-metadata=false option
341-
String[] args = {
342-
"--config",
343-
"scalardb.properties",
344-
"--namespace",
345-
"scalar",
346-
"--table",
347-
"asset",
348-
"--format",
349-
"JSON",
350-
"--include-metadata=false"
351-
};
352-
ExportCommand command = new ExportCommand();
353-
CommandLine cmd = new CommandLine(command);
354-
cmd.parseArgs(args);
355-
356-
// Verify the deprecated option was parsed with explicit false value
357-
assertEquals(false, command.includeTransactionMetadata);
313+
cmdLong
314+
.getParseResult()
315+
.hasMatchedOption(ExportCommandOptions.DEPRECATED_INCLUDE_METADATA_OPTION));
358316

359-
// Verify that the spec was set correctly
360-
command.spec = cmd.getCommandSpec();
317+
// Test short form
318+
ExportCommand commandShort = new ExportCommand();
319+
CommandLine cmdShort = new CommandLine(commandShort);
320+
cmdShort.parseArgs(argsWithShortForm);
321+
commandShort.spec = cmdShort.getCommandSpec();
361322

362-
// Verify that the command line has the deprecated option matched
323+
// Verify the short option is detected (so warning will trigger)
363324
assertTrue(
364-
cmd.getParseResult()
365-
.hasMatchedOption(ExportCommandOptions.DEPRECATED_INCLUDE_METADATA_OPTION));
325+
cmdShort
326+
.getParseResult()
327+
.hasMatchedOption(ExportCommandOptions.DEPRECATED_INCLUDE_METADATA_OPTION_SHORT));
366328
}
367329

368330
@Test
369-
void call_withoutDeprecatedIncludeMetadataOption_shouldHaveDefaultValue() {
370-
// Simulate command line parsing without the deprecated option
331+
void call_withoutDeprecatedIncludeMetadataOption_shouldNotDetectOption() {
332+
// Verify that when the deprecated option is NOT used, it's not detected
333+
// (so warning won't trigger incorrectly)
371334
String[] args = {
372335
"--config",
373336
"scalardb.properties",
@@ -378,17 +341,13 @@ void call_withoutDeprecatedIncludeMetadataOption_shouldHaveDefaultValue() {
378341
"--format",
379342
"JSON"
380343
};
344+
381345
ExportCommand command = new ExportCommand();
382346
CommandLine cmd = new CommandLine(command);
383347
cmd.parseArgs(args);
384-
385-
// Verify the option has its default value (false)
386-
assertEquals(false, command.includeTransactionMetadata);
387-
388-
// Verify that the spec was set correctly
389348
command.spec = cmd.getCommandSpec();
390349

391-
// Verify that the command line does NOT have the deprecated option matched
350+
// Verify the option is NOT detected (so warning won't trigger)
392351
assertEquals(
393352
false,
394353
cmd.getParseResult()

0 commit comments

Comments
 (0)