You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CoreAboutDialogModelTest.java 6.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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.ui.core.about;
  23. import com.dmdirc.commandline.CommandLineParser;
  24. import com.dmdirc.interfaces.EventBus;
  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 java.util.Optional;
  34. import org.junit.Before;
  35. import org.junit.Ignore;
  36. import org.junit.Test;
  37. import org.junit.runner.RunWith;
  38. import org.mockito.Mock;
  39. import org.mockito.runners.MockitoJUnitRunner;
  40. import static junit.framework.TestCase.assertEquals;
  41. import static junit.framework.TestCase.assertTrue;
  42. import static org.mockito.Mockito.when;
  43. @RunWith(MockitoJUnitRunner.class)
  44. public class CoreAboutDialogModelTest {
  45. @Mock private ClientInfo clientInfo;
  46. @Mock private Path path;
  47. @Mock private EventBus eventBus;
  48. @Mock private PluginManager pluginManager;
  49. @Mock private PluginMetaData pluginMetaData1;
  50. @Mock private PluginMetaData pluginMetaData2;
  51. @Mock private PluginInfo pluginInfo1;
  52. @Mock private PluginInfo pluginInfo2;
  53. @Mock private CommandLineParser commandLineParser;
  54. private CoreAboutDialogModel instance;
  55. @Before
  56. public void setUp() throws Exception {
  57. final Path pluginPath1 = FileUtils.getPathForResource(getClass().getResource("license1"));
  58. final Path 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(pluginManager.getPluginInfos()).thenReturn(Lists.newArrayList(pluginInfo1, pluginInfo2));
  63. when(pluginInfo1.getPath("/META-INF/licences/")).thenReturn(pluginPath1);
  64. when(pluginInfo2.getPath("/META-INF/licences/")).thenReturn(pluginPath2);
  65. when(pluginInfo1.getMetaData()).thenReturn(pluginMetaData1);
  66. when(pluginInfo2.getMetaData()).thenReturn(pluginMetaData2);
  67. when(pluginMetaData1.getFriendlyName()).thenReturn("Plugin1");
  68. when(pluginMetaData2.getFriendlyName()).thenReturn("Plugin2");
  69. when(commandLineParser.getLauncherVersion()).thenReturn(Optional.of("Unknown"));
  70. instance = new CoreAboutDialogModel(path, clientInfo, eventBus, pluginManager,
  71. commandLineParser);
  72. instance.load();
  73. }
  74. @Test
  75. public void testGetAbout() throws Exception {
  76. final String about = instance.getAbout();
  77. assertTrue(about.contains("DMDirc"));
  78. assertTrue(about.contains("The intelligent IRC client."));
  79. assertTrue(about.contains("<a href=\"https://www.dmdirc.com\">www.dmdirc.com</a>"));
  80. }
  81. @Test
  82. public void testGetMainDevelopers() throws Exception {
  83. final Developer MD87 = Developer.create("Chris 'MD87' Smith",
  84. "https://www.md87.co.uk");
  85. final Developer Greboid = Developer.create("Gregory 'Greboid' Holmes",
  86. "https://www.greboid.com");
  87. final Developer Dataforce = Developer.create("Shane 'Dataforce' Mc Cormack",
  88. "http://home.dataforce.org.uk");
  89. assertEquals(3, instance.getMainDevelopers().size());
  90. assertTrue(instance.getMainDevelopers().contains(MD87));
  91. assertTrue(instance.getMainDevelopers().contains(Greboid));
  92. assertTrue(instance.getMainDevelopers().contains(Dataforce));
  93. }
  94. @Test
  95. public void testGetOtherDevelopers() throws Exception {
  96. assertEquals(1, instance.getOtherDevelopers().size());
  97. assertTrue(instance.getOtherDevelopers().get(0).getName().contains("Demented-Idiot"));
  98. }
  99. @Test
  100. public void testGetInfo() throws Exception {
  101. assertEquals(7, instance.getInfo().size());
  102. }
  103. @Test
  104. @Ignore("Flakey")
  105. public void testGetLicensedComponents() throws Exception {
  106. final Licence dmdircLicense = Licence.create("dmdirc", "license4", "License4-Body");
  107. final Licence pligin1Licence1 = Licence.create("component1", "license1", "License1-Body");
  108. final Licence plugin1Licence2 = Licence.create("component2", "license2", "License2-Body");
  109. final Licence plugin2Licence2 = Licence.create("component3", "license3", "License3-Body");
  110. final LicensedComponent dmdirc = LicensedComponent.create("DMDirc",
  111. Lists.newArrayList(dmdircLicense));
  112. final LicensedComponent plugin1 = LicensedComponent.create("Plugin1",
  113. Lists.newArrayList(pligin1Licence1, plugin1Licence2));
  114. final LicensedComponent plugin2 = LicensedComponent.create("Plugin2",
  115. Lists.newArrayList(plugin2Licence2));
  116. final List<LicensedComponent> licensedComponents = instance.getLicensedComponents();
  117. assertEquals(3, licensedComponents.size());
  118. assertTrue(licensedComponents.contains(dmdirc));
  119. assertTrue(licensedComponents.contains(plugin1));
  120. assertTrue(licensedComponents.contains(plugin2));
  121. }
  122. }