/plugin-module-codegen-engine/src/main/resources/templates/stash/ssh/SshScmRequestTest.java.vtl

https://bitbucket.org/mmeinhold/amps · Unknown · 64 lines · 50 code · 14 blank · 0 comment · 0 complexity · 0aa824ed06c3f4734054b64ba5183612 MD5 · raw file

  1. package ${PACKAGE};
  2. import com.atlassian.stash.scm.ssh.ExitCodeCallback;
  3. import org.junit.Before;
  4. import org.junit.Test;
  5. import org.junit.runner.RunWith;
  6. import org.mockito.Mock;
  7. import org.mockito.runners.MockitoJUnitRunner;
  8. import java.io.ByteArrayInputStream;
  9. import java.io.ByteArrayOutputStream;
  10. import java.io.FilterInputStream;
  11. import static junit.framework.Assert.assertEquals;
  12. import static org.mockito.Matchers.eq;
  13. import static org.mockito.Mockito.verify;
  14. import ${FQ_HANDLER_CLASSNAME};
  15. import ${FQ_REQUEST_CLASSNAME};
  16. @RunWith(MockitoJUnitRunner.class)
  17. public class ${REQUEST_CLASSNAME}Test
  18. {
  19. @Mock
  20. ExitCodeCallback exitCodeCallback;
  21. ${REQUEST_CLASSNAME} sshRequest;
  22. ByteArrayOutputStream out;
  23. SettableInputStream in;
  24. @Before
  25. public void setup()
  26. {
  27. in = new SettableInputStream();
  28. out = new ByteArrayOutputStream();
  29. sshRequest = new ${REQUEST_CLASSNAME}(in, out, exitCodeCallback);
  30. }
  31. @Test
  32. public void echo() throws Exception
  33. {
  34. in.setBytes("Hello, Stash!".getBytes());
  35. sshRequest.handleRequest();
  36. assertEquals("Unexpected output from handleRequest()!", "Hello, Stash!", out.toString());
  37. verify(exitCodeCallback).onExit(eq(0));
  38. }
  39. private static class SettableInputStream extends FilterInputStream
  40. {
  41. private SettableInputStream()
  42. {
  43. super(new ByteArrayInputStream(new byte[0]));
  44. }
  45. public void setBytes(byte[] bytes)
  46. {
  47. in = new ByteArrayInputStream(bytes);
  48. }
  49. }
  50. }