Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

IdentitiesProfileMigratorTest.java 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /*
  2. * Copyright (c) 2006-2015 DMDirc Developers
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a copy
  5. * of this software and associated documentation files (the "Software"), to deal
  6. * in the Software without restriction, including without limitation the rights
  7. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. * copies of the Software, and to permit persons to whom the Software is
  9. * furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  20. * SOFTWARE.
  21. */
  22. package com.dmdirc.config.profiles;
  23. import com.dmdirc.config.IdentityManager;
  24. import com.dmdirc.config.provider.ConfigProvider;
  25. import com.google.common.collect.Lists;
  26. import java.util.Optional;
  27. import org.junit.Before;
  28. import org.junit.Test;
  29. import org.junit.runner.RunWith;
  30. import org.mockito.Mock;
  31. import org.mockito.runners.MockitoJUnitRunner;
  32. import static junit.framework.TestCase.assertFalse;
  33. import static junit.framework.TestCase.assertTrue;
  34. import static org.mockito.Mockito.verify;
  35. import static org.mockito.Mockito.when;
  36. @RunWith(MockitoJUnitRunner.class)
  37. public class IdentitiesProfileMigratorTest {
  38. @Mock private IdentityManager identityManager;
  39. @Mock private ProfileManager profileManager;
  40. @Mock private ConfigProvider configProvider1;
  41. @Mock private ConfigProvider configProvider2;
  42. @Mock private ConfigProvider configProvider3;
  43. private IdentitiesProfileMigrator instance;
  44. @Before
  45. public void setup() {
  46. instance = new IdentitiesProfileMigrator(identityManager, profileManager);
  47. when(configProvider1.getName()).thenReturn("name1");
  48. when(configProvider1.getOption("profile", "realname")).thenReturn("realname1");
  49. when(configProvider1.getOptionList("profile", "nicknames")).thenReturn(
  50. Lists.newArrayList("nickname1")
  51. );
  52. when(configProvider2.getName()).thenReturn("name2");
  53. when(configProvider2.getOption("profile", "realname")).thenReturn("realname2");
  54. when(configProvider2.hasOptionString("profile", "ident")).thenReturn(true);
  55. when(configProvider2.getOption("profile", "ident")).thenReturn("ident2");
  56. when(configProvider2.getOptionList("profile", "nicknames")).thenReturn(
  57. Lists.newArrayList("nickname2")
  58. );
  59. when(configProvider3.getName()).thenReturn("name3");
  60. when(configProvider3.getOption("profile", "realname")).thenReturn("realname3");
  61. when(configProvider3.hasOptionString("profile", "ident")).thenReturn(true);
  62. when(configProvider3.getOption("profile", "ident")).thenReturn("ident3");
  63. when(configProvider3.getOptionList("profile", "nicknames")).thenReturn(
  64. Lists.newArrayList("nickname31", "nickname32", "nickname33")
  65. );
  66. }
  67. @Test
  68. public void testNeedsMigration_NoProfiles() {
  69. when(identityManager.getProvidersByType("profile")).thenReturn(Lists.newArrayList());
  70. assertFalse(instance.needsMigration());
  71. }
  72. @Test
  73. public void testNeedsMigration_Profiles() {
  74. when(identityManager.getProvidersByType("profile")).thenReturn(
  75. Lists.newArrayList(configProvider1));
  76. assertTrue(instance.needsMigration());
  77. }
  78. @Test
  79. public void testMigrate_NoIdent() {
  80. when(identityManager.getProvidersByType("profile")).thenReturn(
  81. Lists.newArrayList(configProvider1));
  82. instance.migrate();
  83. verify(profileManager).addProfile(Profile.create("name1", "realname1", Optional.empty(),
  84. Lists.newArrayList("nickname1")));
  85. }
  86. @Test
  87. public void testMigrate_Ident() {
  88. when(identityManager.getProvidersByType("profile")).thenReturn(
  89. Lists.newArrayList(configProvider2));
  90. instance.migrate();
  91. verify(profileManager).addProfile(Profile.create("name2", "realname2", Optional.of("ident2"),
  92. Lists.newArrayList("nickname2")));
  93. }
  94. @Test
  95. public void testMigrate_MultipleNicknames() {
  96. when(identityManager.getProvidersByType("profile")).thenReturn(
  97. Lists.newArrayList(configProvider3));
  98. instance.migrate();
  99. verify(profileManager).addProfile(Profile.create("name3", "realname3", Optional.of("ident3"),
  100. Lists.newArrayList("nickname31", "nickname32", "nickname33")));
  101. }
  102. }