### Question:
SchemaCommand extends BaseDatasetCommand { @Override @edu.umd.cs.findbugs.annotations.SuppressWarnings( value={"NP_GUARANTEED_DEREF", "NP_NULL_ON_SOME_PATH"}, justification="Null case checked by precondition") public int run() throws IOException { Preconditions.checkArgument( datasets != null && !datasets.isEmpty(), "Missing dataset name"); if (merge || datasets.size() == 1) { Schema mergedSchema = null; for (String uriOrPath : datasets) { mergedSchema = merge(mergedSchema, schema(uriOrPath)); } Preconditions.checkNotNull(mergedSchema, "No valid schema found"); output(mergedSchema.toString(!minimize), console, outputPath); } else { Preconditions.checkArgument(outputPath == null, "Cannot output multiple schemas to one file"); for (String name : datasets) { console.info("Dataset \"{}\" schema: {}", name, schema(name).toString(!minimize)); } } return 0; } SchemaCommand(Logger console); @Override @edu.umd.cs.findbugs.annotations.SuppressWarnings( value={"NP_GUARANTEED_DEREF", "NP_NULL_ON_SOME_PATH"}, justification="Null case checked by precondition") int run(); @Override List<String> getExamples();  }### Answer:
@Test public void testSchemaStdout() throws Exception { command.datasets = Lists.newArrayList("users"); int rc = command.run(); Assert.assertEquals("Should return success code", 0, rc); verify(console).info(argThat(TestUtil.matchesSchema(schema))); verify(console).trace(contains("repo:hive")); verifyNoMoreInteractions(console); }
@Test public void testMultipleSchemasStdout() throws Exception { TestUtil.run("create", "users_2", "--schema", "resource:schema/user.avsc"); command.datasets = Lists.newArrayList("users", "users_2"); int rc = command.run(); Assert.assertEquals("Should return success code", 0, rc); verify(console).info(anyString(), eq("users"), argThat(TestUtil.matchesSchema(schema))); verify(console).info(anyString(), eq("users_2"), argThat(TestUtil.matchesSchema(schema))); verify(console).trace(contains("repo:hive")); verifyNoMoreInteractions(console); }
@Test public void testSchemaToFile() throws Exception { command.datasets = Lists.newArrayList("users"); command.outputPath = "target/user.avsc"; int rc = command.run(); Assert.assertEquals("Should return success code", 0, rc); String fileContent = Files.toString( new File("target/user.avsc"), BaseCommand.UTF8); Assert.assertTrue("File should contain pretty printed schema", TestUtil.matchesSchema(schema).matches(fileContent)); verify(console).trace(contains("repo:hive")); verifyNoMoreInteractions(console); }
@Test public void testMultipleSchemasToFileFails() throws Exception { command.datasets = Lists.newArrayList("users", "users_2"); command.outputPath = "target/user_schemas.avsc"; TestHelpers.assertThrows("Should reject saving multiple schemas in a file", IllegalArgumentException.class, new Callable<Void>() { @Override public Void call() throws Exception { command.run(); return null; } }); verifyNoMoreInteractions(console); }
@Test public void testMinimize() throws Exception { command.datasets = Lists.newArrayList("users"); command.minimize = true; int rc = command.run(); Assert.assertEquals("Should return success code", 0, rc); verify(console).info(argThat(TestUtil.matchesMinimizedSchema(schema))); verify(console).trace(contains("repo:hive")); verifyNoMoreInteractions(console); }
@Test public void testMissingDatasetName() { TestHelpers.assertThrows("Should complain when no dataset name is given", IllegalArgumentException.class, new Callable<Void>() { @Override public Void call() throws Exception { command.run(); return null; } }); verifyZeroInteractions(console); }