Search in sources :

Example 1 with TransportHttp

use of org.eclipse.jgit.transport.TransportHttp in project che by eclipse.

the class JGitConnectionTest method shouldDoNothingWhenTransportHttpReceived.

@Test
public void shouldDoNothingWhenTransportHttpReceived() throws Exception {
    //given
    /*
         * We need create {@link TransportHttp} mock, but this class has parent
         * abstract class {@link Transport}. Class Transport uses fields of children
         * classes for static initialization collection {@link Transport#protocols}.
         * When we create mock for {@link TransportHttp} - Mockito mocks fields and
         * they return null value. For full mock creation TransportHttp Mockito
         * launches static block in the parent class {@link Transport}, but static
         * block initializes collection with help mocked children fields which
         * return null values, so Transport class loses real field value in the
         * collection. It creates troubles in other tests when we use real object
         * of TransportHttp(collection 'protocols' contains not all values).
         * To realize right initialization {@link Transport#protocols} we create
         * mock of {@link Transport} and this class initializes collection "protocols"
         * with  help real children {@link TransportHttp}, which returns real not null
         * value. And then we can create mock {@link TransportHttp}.
         */
    mock(Transport.class);
    TransportHttp transportHttp = mock(TransportHttp.class);
    when(sshKeyProvider.getPrivateKey(anyString())).thenReturn(new byte[0]);
    doAnswer(invocation -> {
        TransportConfigCallback callback = (TransportConfigCallback) invocation.getArguments()[0];
        callback.configure(transportHttp);
        return null;
    }).when(transportCommand).setTransportConfigCallback(any());
    //when
    jGitConnection.executeRemoteCommand("ssh://host.xz/repo.git", transportCommand, null, null);
    //then
    verifyZeroInteractions(transportHttp);
}
Also used : TransportHttp(org.eclipse.jgit.transport.TransportHttp) TransportConfigCallback(org.eclipse.jgit.api.TransportConfigCallback) Test(org.testng.annotations.Test)

Aggregations

TransportConfigCallback (org.eclipse.jgit.api.TransportConfigCallback)1 TransportHttp (org.eclipse.jgit.transport.TransportHttp)1 Test (org.testng.annotations.Test)1