package com.jetbrains.python.sdk;

import com.intellij.openapi.projectRoots.Sdk;
import com.intellij.openapi.projectRoots.SdkAdditionalData;
import com.intellij.remote.VagrantBasedCredentialsHolder;
import com.jetbrains.python.remote.PyRemoteSdkAdditionalDataBase;
import junit.framework.TestCase;
import org.junit.Assert;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;

import static org.mockito.Mockito.when;

/**
 * @author Alexander Koshevoy
 */
public class PythonSdkTypeTest extends TestCase {
  @Mock
  private Sdk sdk;
  @Mock
  private PyRemoteSdkAdditionalDataBase remoteSdkAdditionalData;
  @Mock
  private SdkAdditionalData sdkAdditionalData;
  @Mock
  private VagrantBasedCredentialsHolder vagrantBasedCredentialsHolder;

  @Override
  public void setUp() throws Exception {
    super.setUp();
    MockitoAnnotations.initMocks(this);
  }

  public void testLocalSdk() throws Exception {
    when(sdk.getSdkAdditionalData()).thenReturn(sdkAdditionalData);
    Assert.assertFalse(PythonSdkType.hasInvalidRemoteCredentials(sdk));
  }

  public void testAbsentRemoteSdkCredentials() throws Exception {
    when(sdk.getSdkAdditionalData()).thenReturn(remoteSdkAdditionalData);
    Assert.assertFalse(PythonSdkType.hasInvalidRemoteCredentials(sdk));
  }

  public void testValidRemoteSdkCredentials() throws Exception {
    when(vagrantBasedCredentialsHolder.getVagrantFolder()).thenReturn("/home/vagrant/box");
    mockSwitchOnConnectionType(remoteSdkAdditionalData, vagrantBasedCredentialsHolder);
    when(sdk.getSdkAdditionalData()).thenReturn(remoteSdkAdditionalData);
    Assert.assertFalse(PythonSdkType.hasInvalidRemoteCredentials(sdk));
  }

  public void testInvalidRemoteSdkCredentials() throws Exception {
    when(vagrantBasedCredentialsHolder.getVagrantFolder()).thenReturn("");
    mockSwitchOnConnectionType(remoteSdkAdditionalData, vagrantBasedCredentialsHolder);
    when(sdk.getSdkAdditionalData()).thenReturn(remoteSdkAdditionalData);
    Assert.assertTrue(PythonSdkType.hasInvalidRemoteCredentials(sdk));
  }

  private static void mockSwitchOnConnectionType(PyRemoteSdkAdditionalDataBase data, final VagrantBasedCredentialsHolder credentials) {
    // TODO: fix
    //Mockito.doAnswer(new Answer() {
    //  @Override
    //  public Void answer(InvocationOnMock invocation) {
    //    ((RemoteSdkConnectionAcceptor)invocation.getArguments()[0]).vagrant(credentials);
    //    return null;
    //  }
    //}).when(data).switchOnConnectionType(any(RemoteSdkConnectionAcceptor.class));
  }
}
@@ -192,16 +192,183 @@
 Holder;%0A
+import com.intellij.remote.ext.CredentialsCase;%0Aimport com.intellij.remote.ext.CredentialsLanguageContribution;%0Aimport com.intellij.testFramework.PlatformLiteFixture;%0A
 import c
@@ -429,41 +429,8 @@
 se;%0A
-import junit.framework.TestCase;%0A
 impo
@@ -475,16 +475,44 @@
 o.Mock;%0A
+import org.mockito.Mockito;%0A
 import o
@@ -543,16 +543,56 @@
 tions;%0A%0A
+import static org.mockito.Matchers.any;%0A
 import s
@@ -705,15 +705,26 @@
 nds 
-TestCas
+PlatformLiteFixtur
 e %7B%0A
@@ -956,16 +956,99 @@
 sHolder;
+%0A  @Mock%0A  private CredentialsLanguageContribution credentialsLanguageContribution;
 %0A%0A  @Ove
@@ -1153,16 +1153,113 @@
 (this);%0A
+    registerExtension(CredentialsLanguageContribution.EP_NAME, credentialsLanguageContribution);%0A
   %7D%0A%0A  p
@@ -2585,174 +2585,72 @@
     
-// TODO: fix%0A    //Mockito.doAnswer(new Answer() %7B%0A    //  @Override%0A    //  public Void answer(InvocationOnMock invocation)
+Mockito.doAnswer(invocation -%3E
  %7B%0A   
- //
    
- 
 ((
-RemoteSdkConnectionAcceptor
+CredentialsCase.Vagrant
 )inv
@@ -2676,23 +2676,23 @@
 s()%5B0%5D).
-vagrant
+process
 (credent
@@ -2700,20 +2700,16 @@
 als);%0A  
-  //
     retu
@@ -2725,20 +2725,8 @@
     
-//  %7D%0A    //
 %7D).w
@@ -2766,35 +2766,31 @@
 any(
-RemoteSdkConnectionAcceptor
+CredentialsCase.Vagrant
 .cla

Test fails of PythonSdkTypeTest after merging python_docker branch fixed