Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

ServerTest.java 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /*
  2. * Copyright (c) 2006-2013 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;
  23. import com.dmdirc.commandparser.parsers.CommandParser;
  24. import com.dmdirc.interfaces.CommandController;
  25. import com.dmdirc.interfaces.config.AggregateConfigProvider;
  26. import com.dmdirc.interfaces.config.ConfigProvider;
  27. import com.dmdirc.interfaces.config.ConfigProviderMigrator;
  28. import com.dmdirc.interfaces.config.IdentityFactory;
  29. import com.dmdirc.messages.MessageSinkManager;
  30. import com.dmdirc.ui.WindowManager;
  31. import com.dmdirc.ui.input.TabCompleterFactory;
  32. import java.net.URI;
  33. import org.junit.Before;
  34. import org.junit.Test;
  35. import org.mockito.Mock;
  36. import org.mockito.MockitoAnnotations;
  37. import static org.junit.Assert.assertEquals;
  38. import static org.mockito.Matchers.anyString;
  39. import static org.mockito.Mockito.when;
  40. public class ServerTest {
  41. @Mock private ServerManager serverManager;
  42. @Mock private ConfigProvider profile;
  43. @Mock private AggregateConfigProvider configManager;
  44. @Mock private ConfigProviderMigrator configMigrator;
  45. @Mock private CommandParser commandParser;
  46. @Mock private ParserFactory parserFactory;
  47. @Mock private IdentityFactory identityFactory;
  48. @Mock private TabCompleterFactory tabCompleterFactory;
  49. @Mock private CommandController commandController;
  50. @Mock private MessageSinkManager messageSinkManager;
  51. @Mock private WindowManager windowManager;
  52. private Server server;
  53. @Before
  54. public void setUp() throws Exception {
  55. MockitoAnnotations.initMocks(this);
  56. when(configManager.getOptionInt(anyString(), anyString())).thenReturn(Integer.MAX_VALUE);
  57. when(configMigrator.getConfigProvider()).thenReturn(configManager);
  58. server = new Server(
  59. serverManager,
  60. configMigrator,
  61. commandParser,
  62. parserFactory,
  63. tabCompleterFactory,
  64. commandController,
  65. identityFactory,
  66. messageSinkManager,
  67. windowManager,
  68. new URI("irc-test://255.255.255.255"),
  69. profile);
  70. }
  71. @Test
  72. public void testGetNetworkFromServerName() {
  73. final String[][] tests = {
  74. {"foo.com", "foo.com"},
  75. {"bar.foo.com", "foo.com"},
  76. {"irc.us.foo.com", "foo.com"},
  77. {"irc.foo.co.uk", "foo.co.uk"},
  78. {"com", "com"},
  79. {"localhost", "localhost"},
  80. {"foo.de", "foo.de"}
  81. };
  82. for (String[] test : tests) {
  83. assertEquals(test[1], Server.getNetworkFromServerName(test[0]));
  84. }
  85. }
  86. @Test
  87. public void testDuplicateInviteRemoval() {
  88. server.addInvite(new Invite(server, "#chan1", "a!b@c"));
  89. server.addInvite(new Invite(server, "#chan1", "d!e@f"));
  90. assertEquals(1, server.getInvites().size());
  91. }
  92. @Test
  93. public void testRemoveInvites() {
  94. server.addInvite(new Invite(server, "#chan1", "a!b@c"));
  95. server.addInvite(new Invite(server, "#chan2", "d!e@f"));
  96. server.removeInvites("#chan1");
  97. assertEquals(1, server.getInvites().size());
  98. server.removeInvites("#chan2");
  99. assertEquals(0, server.getInvites().size());
  100. }
  101. }