選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

CoreAboutDialogModelTest.java 6.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /*
  2. * Copyright (c) 2006-2014 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.ui.core.about;
  23. import com.dmdirc.DMDircMBassador;
  24. import com.dmdirc.interfaces.config.AggregateConfigProvider;
  25. import com.dmdirc.plugins.PluginInfo;
  26. import com.dmdirc.plugins.PluginManager;
  27. import com.dmdirc.plugins.PluginMetaData;
  28. import com.dmdirc.util.ClientInfo;
  29. import com.dmdirc.util.io.FileUtils;
  30. import com.google.common.collect.Lists;
  31. import java.nio.file.Path;
  32. import java.util.List;
  33. import org.junit.Before;
  34. import org.junit.Test;
  35. import org.junit.runner.RunWith;
  36. import org.mockito.Mock;
  37. import org.mockito.runners.MockitoJUnitRunner;
  38. import static junit.framework.TestCase.assertEquals;
  39. import static junit.framework.TestCase.assertTrue;
  40. import static org.mockito.Mockito.when;
  41. @RunWith(MockitoJUnitRunner.class)
  42. public class CoreAboutDialogModelTest {
  43. @Mock private ClientInfo clientInfo;
  44. @Mock private AggregateConfigProvider globalConfig;
  45. @Mock private Path path;
  46. @Mock private DMDircMBassador eventBus;
  47. @Mock private PluginManager pluginManager;
  48. @Mock private PluginMetaData pluginMetaData1;
  49. @Mock private PluginMetaData pluginMetaData2;
  50. @Mock private PluginInfo pluginInfo1;
  51. @Mock private PluginInfo pluginInfo2;
  52. private Path pluginPath1;
  53. private Path pluginPath2;
  54. private CoreAboutDialogModel instance;
  55. @Before
  56. public void setUp() throws Exception {
  57. pluginPath1 = FileUtils.getPathForResource(getClass().getResource("license1"));
  58. pluginPath2 = FileUtils.getPathForResource(getClass().getResource("license2"));
  59. when(clientInfo.getVersionInformation()).thenReturn("DMDirc Version");
  60. when(clientInfo.getOperatingSystemInformation()).thenReturn("OS Version");
  61. when(clientInfo.getJavaInformation()).thenReturn("Java Version");
  62. when(globalConfig.getOption("identity", "modealiasversion")).thenReturn("ModeAlias Version");
  63. when(pluginManager.getPluginInfos()).thenReturn(Lists.newArrayList(pluginInfo1, pluginInfo2));
  64. when(pluginInfo1.getPath("/META-INF/licenses/")).thenReturn(pluginPath1);
  65. when(pluginInfo2.getPath("/META-INF/licenses/")).thenReturn(pluginPath2);
  66. when(pluginInfo1.getMetaData()).thenReturn(pluginMetaData1);
  67. when(pluginInfo2.getMetaData()).thenReturn(pluginMetaData2);
  68. when(pluginMetaData1.getFriendlyName()).thenReturn("Plugin1");
  69. when(pluginMetaData2.getFriendlyName()).thenReturn("Plugin2");
  70. instance = new CoreAboutDialogModel(globalConfig, path, clientInfo, eventBus, pluginManager);
  71. instance.load();
  72. }
  73. @Test
  74. public void testGetAbout() throws Exception {
  75. final String about = instance.getAbout();
  76. assertTrue(about.contains("DMDirc"));
  77. assertTrue(about.contains("The intelligent IRC client."));
  78. assertTrue(about.contains("<a href=\"https://www.dmdirc.com\">www.dmdirc.com</a>"));
  79. }
  80. @Test
  81. public void testGetMainDevelopers() throws Exception {
  82. assertEquals(3, instance.getMainDevelopers().size());
  83. assertTrue(instance.getMainDevelopers().get(0).getName().contains("MD87"));
  84. assertTrue(instance.getMainDevelopers().get(1).getName().contains("Greboid"));
  85. assertTrue(instance.getMainDevelopers().get(2).getName().contains("Dataforce"));
  86. }
  87. @Test
  88. public void testGetOtherDevelopers() throws Exception {
  89. assertEquals(1, instance.getOtherDevelopers().size());
  90. assertTrue(instance.getOtherDevelopers().get(0).getName().contains("Demented-Idiot"));
  91. }
  92. @Test
  93. public void testGetInfo() throws Exception {
  94. assertEquals(7, instance.getInfo().size());
  95. }
  96. @Test
  97. public void testGetLicensedComponents() throws Exception {
  98. final List<LicensedComponent> licensedComponents = instance.getLicensedComponents();
  99. assertEquals(3, licensedComponents.size());
  100. assertEquals("DMDirc", licensedComponents.get(0).getName());
  101. assertEquals("Plugin1", licensedComponents.get(1).getName());
  102. assertEquals("Plugin2", licensedComponents.get(2).getName());
  103. assertEquals(1, licensedComponents.get(0).getLicences().size());
  104. assertEquals("dmdirc", licensedComponents.get(0).getLicences().get(0).getComponent());
  105. assertEquals("license4", licensedComponents.get(0).getLicences().get(0).getName());
  106. assertEquals("License4-Body", licensedComponents.get(0).getLicences().get(0).getBody());
  107. assertEquals(2, licensedComponents.get(1).getLicences().size());
  108. assertEquals("component1", licensedComponents.get(1).getLicences().get(0).getComponent());
  109. assertEquals("license1", licensedComponents.get(1).getLicences().get(0).getName());
  110. assertEquals("License1-Body", licensedComponents.get(1).getLicences().get(0).getBody());
  111. assertEquals("component2", licensedComponents.get(1).getLicences().get(1).getComponent());
  112. assertEquals("license2", licensedComponents.get(1).getLicences().get(1).getName());
  113. assertEquals("License2-Body", licensedComponents.get(1).getLicences().get(1).getBody());
  114. assertEquals(1, licensedComponents.get(2).getLicences().size());
  115. assertEquals("component3", licensedComponents.get(2).getLicences().get(0).getComponent());
  116. assertEquals("license3", licensedComponents.get(2).getLicences().get(0).getName());
  117. assertEquals("License3-Body", licensedComponents.get(2).getLicences().get(0).getBody());
  118. }
  119. }