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

https://bitbucket.org/mmeinhold/amps · Unknown · 65 lines · 52 code · 13 blank · 0 comment · 0 complexity · 304fd5cc637d56b34f80511975624ee7 MD5 · raw file

  1. package ${PACKAGE};
  2. import com.atlassian.stash.scm.ssh.ExitCodeCallback;
  3. import com.atlassian.stash.scm.ssh.SshScmRequest;
  4. import org.junit.Before;
  5. import org.junit.Test;
  6. import org.junit.runner.RunWith;
  7. import org.mockito.Mock;
  8. import org.mockito.runners.MockitoJUnitRunner;
  9. import java.io.InputStream;
  10. import java.io.OutputStream;
  11. import static junit.framework.Assert.assertNull;
  12. import static org.hamcrest.MatcherAssert.assertThat;
  13. import static org.hamcrest.Matchers.instanceOf;
  14. import ${FQ_CLASS_UNDER_TEST};
  15. import ${FQ_REQUEST_CLASSNAME};
  16. @RunWith(MockitoJUnitRunner.class)
  17. public class ${CLASSNAME}
  18. {
  19. @Mock
  20. InputStream in;
  21. @Mock
  22. OutputStream out;
  23. @Mock
  24. OutputStream error;
  25. @Mock
  26. ExitCodeCallback exitCodeCallback;
  27. ${CLASS_UNDER_TEST} sshRequestHandler;
  28. @Before
  29. public void setUp()
  30. {
  31. sshRequestHandler = new ${CLASS_UNDER_TEST}();
  32. }
  33. @Test
  34. public void echo()
  35. {
  36. assertCommandMatches("echo");
  37. assertCommandMatches("eChO");
  38. }
  39. @Test
  40. public void notEcho()
  41. {
  42. assertNull(createSshRequest("fishsticks"));
  43. }
  44. private void assertCommandMatches(String command)
  45. {
  46. assertThat(createSshRequest(command), instanceOf(${REQUEST_CLASSNAME}.class));
  47. }
  48. private SshScmRequest createSshRequest(String command)
  49. {
  50. return sshRequestHandler.create(command, in, out, error, exitCodeCallback);
  51. }
  52. }