Package com.jcabi.ssh

Class Shell.Fake

  • All Implemented Interfaces:
    Shell
    Enclosing interface:
    Shell

    @Immutable
    public static final class Shell.Fake
    extends Object
    implements Shell
    Fake shell for unit testing.

    It doesn't do anything, but imitates the behavior of a real shell, returning the code and the output provided in the ctor.

    Since:
    1.6
    • Constructor Detail

      • Fake

        public Fake()
        Ctor.
      • Fake

        public Fake​(int exit,
                    String out,
                    String err)
        Ctor.
        Parameters:
        exit - Exit code to return
        out - Stdout to return
        err - Stderr to return
      • Fake

        public Fake​(int exit,
                    byte[] out,
                    byte[] err)
        Ctor.
        Parameters:
        exit - Exit code to return
        out - Stdout to return
        err - Stderr to return
    • Method Detail

      • exec

        public int exec​(String command,
                        InputStream stdin,
                        OutputStream sout,
                        OutputStream serr)
                 throws IOException
        Description copied from interface: Shell
        Execute and return exit code.
        Specified by:
        exec in interface Shell
        Parameters:
        command - Command
        stdin - Stdin (will be closed)
        sout - Stdout (will be closed)
        serr - Stderr (will be closed)
        Returns:
        Exit code
        Throws:
        IOException - If fails