PageRenderTime 11ms CodeModel.GetById 1ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

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