### Question:
ObjectSchemaCommand extends BaseCommand { @Override public int run() throws IOException { Preconditions.checkArgument(classNames != null && !classNames.isEmpty(), "Java class name is required"); Preconditions.checkArgument(classNames.size() == 1, "Only one java class name can be given"); ClassLoader loader = loaderFor(jars, libs); String className = classNames.get(0); Class<?> recordClass; try { recordClass = loader.loadClass(className); } catch (ClassNotFoundException e) { throw new IllegalArgumentException("Cannot find class: " + className, e); } DatasetDescriptor descriptor = new DatasetDescriptor.Builder() .schema(recordClass) .build(); String schema = descriptor.getSchema().toString(!minimize); output(schema, console, outputPath); return 0; } ObjectSchemaCommand(Logger console); @Override int run(); @Override List<String> getExamples();  }### Answer:
@Test public void testSchemaStdout() throws Exception { command.classNames = Lists.newArrayList("org.kitesdk.cli.example.User"); int rc = command.run(); Assert.assertEquals("Should return success code", 0, rc); verify(console).info(argThat(TestUtil.matchesSchema(schema))); verifyNoMoreInteractions(console); }
@Test public void testSchemaToFile() throws Exception { command.classNames = Lists.newArrayList("org.kitesdk.cli.example.User"); 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)); verifyNoMoreInteractions(console); }
@Test public void testMultipleSClassesFail() throws Exception { command.classNames = Lists.newArrayList( "org.kitesdk.cli.example.User", "org.kitesdk.data.Format"); 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.classNames = Lists.newArrayList("org.kitesdk.cli.example.User"); command.minimize = true; int rc = command.run(); Assert.assertEquals("Should return success code", 0, rc); verify(console).info(argThat(TestUtil.matchesMinimizedSchema(schema))); verifyNoMoreInteractions(console); }
@Test public void testMissingSamplePath() { TestHelpers.assertThrows("Should complain when no class name is given", IllegalArgumentException.class, new Callable<Void>() { @Override public Void call() throws Exception { command.run(); return null; } }); verifyZeroInteractions(console); }