AuthenticatorUrlUtilsTest.java 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. package com.owncloud.android.authentication;
  2. import org.junit.Assert;
  3. import org.junit.Test;
  4. import org.junit.runner.RunWith;
  5. import org.junit.runners.Suite;
  6. @RunWith(Suite.class)
  7. @Suite.SuiteClasses(AuthenticatorUrlUtilsTest.NormalizeScheme.class)
  8. public class AuthenticatorUrlUtilsTest {
  9. public static class NormalizeScheme {
  10. @Test
  11. public void noScheme() {
  12. // GIVEN
  13. // input URL has no scheme
  14. String url = "host.net/index.php/apps/ABC/def/?";
  15. // WHEN
  16. // scheme is normalized
  17. String normalized = AuthenticatorUrlUtils.normalizeScheme(url);
  18. // THEN
  19. // input is returned unchanged
  20. Assert.assertSame(url, normalized);
  21. }
  22. @Test
  23. public void lowercaseScheme() {
  24. // GIVEN
  25. // input URL has scheme
  26. // scheme is lowercase
  27. String url = "https://host.net/index.php/ABC/def/?";
  28. // WHEN
  29. // scheme is normalized
  30. String normalized = AuthenticatorUrlUtils.normalizeScheme(url);
  31. // THEN
  32. // output is equal
  33. Assert.assertEquals(url, normalized);
  34. }
  35. @Test
  36. public void uppercaseScheme() {
  37. // GIVEN
  38. // input URL has scheme
  39. // scheme has uppercase characters
  40. String mixedCaseUrl = "HTtps://host.net/index.php/ABC/def/?";
  41. // WHEN
  42. // scheme is normalized
  43. String normalized = AuthenticatorUrlUtils.normalizeScheme(mixedCaseUrl);
  44. // THEN
  45. // scheme has been lower-cased
  46. // remaining URL part is left unchanged
  47. String expectedUrl = "https://host.net/index.php/ABC/def/?";
  48. Assert.assertEquals(expectedUrl, normalized);
  49. }
  50. @Test
  51. public void emptyInput() {
  52. // GIVEN
  53. // input URL is empty
  54. String emptyUrl = "";
  55. // WHEN
  56. // scheme is normalized
  57. String normalized = AuthenticatorUrlUtils.normalizeScheme(emptyUrl);
  58. // THEN
  59. // output is empty
  60. Assert.assertEquals("", normalized);
  61. }
  62. }
  63. }