// Path: src/test/java/org/jenkinsci/tools/configcloner/handler/Helper.java
// public static CommandResponseMatcher stdoutContains(final String expected) {
//     return new CommandResponseMatcher("Standard output should contain string " + expected) {
//         @Override protected boolean match(Accumulator item, Description desc) {
//             return item.stdout().contains(expected);
//         }
//     };
// }
// 
// Path: src/test/java/org/jenkinsci/tools/configcloner/handler/Helper.java
// public static CommandResponseMatcher succeeded() {
//     return new CommandResponseMatcher("Command suceeded") {
//         @Override protected boolean match(Accumulator item, Description desc) {
//             return item.succeeded();
//         }
//     };
// }
// 
// Path: src/main/java/org/jenkinsci/tools/configcloner/CommandResponse.java
// public static class Accumulator extends CommandResponse{
// 
//     final ByteArrayOutputStream out;
//     final ByteArrayOutputStream err;
// 
//     private Accumulator(final ByteArrayOutputStream out, final ByteArrayOutputStream err) {
// 
//         super(new PrintStream(out), new PrintStream(err));
// 
//         this.out = out;
//         this.err = err;
//     }
// 
//     public String stdout() {
// 
//         return asString(out);
//     }
// 
//     public String stdout(final String pattern) {
// 
//         return decorate(out, pattern);
//     }
// 
//     public String stderr() {
// 
//         return asString(err);
//     }
// 
//     public String stderr(final String pattern) {
// 
//         return decorate(err, pattern);
//     }
// 
//     public void dump(final String operation) {
// 
//         System.out.println(operation + ": " + returnCode());
//         System.err.print(stderr("err > %s"));
//         System.out.print(stdout("out > %s"));
//     }
// 
//     private String decorate(final ByteArrayOutputStream stream, String pattern) {
// 
//         if (!pattern.endsWith("\n")) {
// 
//             pattern += "\n";
//         }
// 
//         final String in = asString(stream);
//         if (in.isEmpty()) return "";
// 
//         final StringBuilder builder = new StringBuilder(in.length());
//         for (final String line: asString(stream).split("\n")) {
// 
//             builder.append(String.format(pattern, line));
//         }
// 
//         return builder.toString();
//     }
// 
//     private String asString(final ByteArrayOutputStream stream) {
// 
//         try {
// 
//             return stream.toString("UTF-8");
//         } catch (final UnsupportedEncodingException ex) {
// 
//             throw new AssertionError(ex);
//         }
//     }
// 
//     @Override
//     public Accumulator returnCode(final int ret) {
// 
//         return (Accumulator) super.returnCode(ret);
//     }
// }
// 
// Path: src/main/java/org/jenkinsci/tools/configcloner/handler/Usage.java
// public class Usage implements Handler {
// 
//     private final Main main;
// 
//     public Usage(final Main main) {
//         this.main = main;
//     }
// 
//     public CommandResponse run(final CommandResponse response) {
//         response.out().println("Usage: ");
//         for(Handler handler: main.commandMapping().values()) {
//             final PrintStream o = response.out();
//             o.println();
//             o.format("%-10s %s\n", handler.name(), handler.description());
//             new CmdLineParser(handler).printUsage(o);
//         }
// 
//         return response;
//     }
// 
//     public String name() {
//         return "help";
//     }
// 
//     public String description() {
//         return "Print usage";
//     }
// }


import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.text.IsEmptyString.isEmptyString;
import static org.jenkinsci.tools.configcloner.handler.Helper.stdoutContains;
import static org.jenkinsci.tools.configcloner.handler.Helper.succeeded;
import org.jenkinsci.tools.configcloner.CommandResponse.Accumulator;
import org.jenkinsci.tools.configcloner.handler.Usage;
import org.junit.Test;
package org.jenkinsci.tools.configcloner;



public class MainTest {

    final Accumulator rsp = CommandResponse.accumulate();

    @Test
    public void getUsageWhenNoArgsProvided() {

        assertThat(run().getHandler(), instanceOf(Usage.class));
    }

    @Test
    public void getUsageWhenInvalidArgsProvided() {

        assertThat(run("no-such-command").getHandler(), instanceOf(Usage.class));
    }

    @Test
    public void failedValidationShouldInvokeUsage() {

        run("job", "invalid-arg");

// Path: src/test/java/org/jenkinsci/tools/configcloner/handler/Helper.java
// public static CommandResponseMatcher stdoutContains(final String expected) {
//     return new CommandResponseMatcher("Standard output should contain string " + expected) {
//         @Override protected boolean match(Accumulator item, Description desc) {
//             return item.stdout().contains(expected);
//         }
//     };
// }
// 
// Path: src/test/java/org/jenkinsci/tools/configcloner/handler/Helper.java
// public static CommandResponseMatcher succeeded() {
//     return new CommandResponseMatcher("Command suceeded") {
//         @Override protected boolean match(Accumulator item, Description desc) {
//             return item.succeeded();
//         }
//     };
// }
// 
// Path: src/main/java/org/jenkinsci/tools/configcloner/CommandResponse.java
// public static class Accumulator extends CommandResponse{
// 
//     final ByteArrayOutputStream out;
//     final ByteArrayOutputStream err;
// 
//     private Accumulator(final ByteArrayOutputStream out, final ByteArrayOutputStream err) {
// 
//         super(new PrintStream(out), new PrintStream(err));
// 
//         this.out = out;
//         this.err = err;
//     }
// 
//     public String stdout() {
// 
//         return asString(out);
//     }
// 
//     public String stdout(final String pattern) {
// 
//         return decorate(out, pattern);
//     }
// 
//     public String stderr() {
// 
//         return asString(err);
//     }
// 
//     public String stderr(final String pattern) {
// 
//         return decorate(err, pattern);
//     }
// 
//     public void dump(final String operation) {
// 
//         System.out.println(operation + ": " + returnCode());
//         System.err.print(stderr("err > %s"));
//         System.out.print(stdout("out > %s"));
//     }
// 
//     private String decorate(final ByteArrayOutputStream stream, String pattern) {
// 
//         if (!pattern.endsWith("\n")) {
// 
//             pattern += "\n";
//         }
// 
//         final String in = asString(stream);
//         if (in.isEmpty()) return "";
// 
//         final StringBuilder builder = new StringBuilder(in.length());
//         for (final String line: asString(stream).split("\n")) {
// 
//             builder.append(String.format(pattern, line));
//         }
// 
//         return builder.toString();
//     }
// 
//     private String asString(final ByteArrayOutputStream stream) {
// 
//         try {
// 
//             return stream.toString("UTF-8");
//         } catch (final UnsupportedEncodingException ex) {
// 
//             throw new AssertionError(ex);
//         }
//     }
// 
//     @Override
//     public Accumulator returnCode(final int ret) {
// 
//         return (Accumulator) super.returnCode(ret);
//     }
// }
// 
// Path: src/main/java/org/jenkinsci/tools/configcloner/handler/Usage.java
// public class Usage implements Handler {
// 
//     private final Main main;
// 
//     public Usage(final Main main) {
//         this.main = main;
//     }
// 
//     public CommandResponse run(final CommandResponse response) {
//         response.out().println("Usage: ");
//         for(Handler handler: main.commandMapping().values()) {
//             final PrintStream o = response.out();
//             o.println();
//             o.format("%-10s %s\n", handler.name(), handler.description());
//             new CmdLineParser(handler).printUsage(o);
//         }
// 
//         return response;
//     }
// 
//     public String name() {
//         return "help";
//     }
// 
//     public String description() {
//         return "Print usage";
//     }
// }


// Path: src/test/java/org/jenkinsci/tools/configcloner/MainTest.java
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.text.IsEmptyString.isEmptyString;
import static org.jenkinsci.tools.configcloner.handler.Helper.stdoutContains;
import static org.jenkinsci.tools.configcloner.handler.Helper.succeeded;
import org.jenkinsci.tools.configcloner.CommandResponse.Accumulator;
import org.jenkinsci.tools.configcloner.handler.Usage;
import org.junit.Test;

package org.jenkinsci.tools.configcloner;



public class MainTest {

    final Accumulator rsp = CommandResponse.accumulate();

    @Test
    public void getUsageWhenNoArgsProvided() {

        assertThat(run().getHandler(), instanceOf(Usage.class));
    }

    @Test
    public void getUsageWhenInvalidArgsProvided() {

        assertThat(run("no-such-command").getHandler(), instanceOf(Usage.class));
    }

    @Test
    public void failedValidationShouldInvokeUsage() {

        run("job", "invalid-arg");

        assertThat(rsp, not(succeeded()));