PageRenderTime 46ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/src/test/java/com/atlassian/jira/plugins/bitbucket/api/impl/TestDefaultAuthenticationFactory.java

https://bitbucket.org/atlassian/jira-bitbucket-connector/
Java | 56 lines | 47 code | 9 blank | 0 comment | 0 complexity | cfb2c750e0001c45a68e0ad922ca5a34 MD5 | raw file
  1. package com.atlassian.jira.plugins.bitbucket.api.impl;
  2. import static junit.framework.Assert.assertEquals;
  3. import static junit.framework.Assert.assertTrue;
  4. import static org.mockito.Mockito.when;
  5. import org.junit.Before;
  6. import org.junit.Test;
  7. import org.mockito.Mock;
  8. import org.mockito.MockitoAnnotations;
  9. import com.atlassian.jira.plugins.bitbucket.api.Authentication;
  10. import com.atlassian.jira.plugins.bitbucket.api.SourceControlRepository;
  11. public class TestDefaultAuthenticationFactory
  12. {
  13. @Mock
  14. private SourceControlRepository repository;
  15. @Before
  16. public void setup() throws Exception
  17. {
  18. MockitoAnnotations.initMocks(this);
  19. }
  20. @Test
  21. public void anonymous()
  22. {
  23. DefaultAuthenticationFactory authenticationFactory = new DefaultAuthenticationFactory();
  24. Authentication authentication = authenticationFactory.getAuthentication(repository);
  25. assertEquals(Authentication.ANONYMOUS,authentication);
  26. }
  27. @Test
  28. public void oauth()
  29. {
  30. when(repository.getUsername()).thenReturn("");
  31. when(repository.getPassword()).thenReturn("");
  32. when(repository.getAccessToken()).thenReturn("abc");
  33. DefaultAuthenticationFactory authenticationFactory = new DefaultAuthenticationFactory();
  34. Authentication authentication = authenticationFactory.getAuthentication(repository);
  35. assertTrue(authentication instanceof GithubOAuthAuthentication);
  36. }
  37. @Test
  38. public void basic()
  39. {
  40. when(repository.getUsername()).thenReturn("abc");
  41. when(repository.getPassword()).thenReturn("");
  42. when(repository.getAccessToken()).thenReturn("");
  43. DefaultAuthenticationFactory authenticationFactory = new DefaultAuthenticationFactory();
  44. Authentication authentication = authenticationFactory.getAuthentication(repository);
  45. assertTrue(authentication instanceof BasicAuthentication);
  46. }
  47. }