Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

FeedbackHelperTest.java 5.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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.feedback;
  23. import com.dmdirc.ServerState;
  24. import com.dmdirc.interfaces.Connection;
  25. import com.dmdirc.interfaces.ConnectionManager;
  26. import com.dmdirc.config.provider.AggregateConfigProvider;
  27. import com.dmdirc.parser.interfaces.Parser;
  28. import com.dmdirc.util.ClientInfo;
  29. import com.google.common.collect.Lists;
  30. import java.nio.file.Path;
  31. import java.util.Optional;
  32. import org.junit.Before;
  33. import org.junit.Test;
  34. import org.junit.runner.RunWith;
  35. import org.mockito.Mock;
  36. import org.mockito.runners.MockitoJUnitRunner;
  37. import static junit.framework.TestCase.assertEquals;
  38. import static org.mockito.Mockito.when;
  39. @RunWith(MockitoJUnitRunner.class)
  40. public class FeedbackHelperTest {
  41. private static final String VERSION = "0.1";
  42. private static final String PATH = "/path/to/config";
  43. private static final String JAVA = "javaInfo";
  44. private static final String OS = "osInfo";
  45. private static final String SERVER_NAME = "serverName";
  46. private static final String NETWORK_NAME = "networkName";
  47. private static final String SERVER_SOFTWARE = "serverSoftware";
  48. private static final String SERVER_SOFTWARE_TYPE = "serverSoftwareType";
  49. private static final String BOOLEAN_MODES = "booleanModes";
  50. private static final String LIST_MODES = "listChannelModes";
  51. private static final String PARAM_MODES = "paramModes";
  52. private static final String DOUBLE_PARAM_MODES = "doubleParamModes";
  53. @Mock private Path path;
  54. @Mock private ClientInfo clientInfo;
  55. @Mock private Connection connection;
  56. @Mock private Parser parser;
  57. @Mock private AggregateConfigProvider config;
  58. @Mock private ConnectionManager connectionManager;
  59. private FeedbackHelper instance;
  60. @Before
  61. public void setUp() throws Exception {
  62. when(config.getOption("version", "version")).thenReturn(VERSION);
  63. when(clientInfo.getVersionInformation()).thenReturn(VERSION);
  64. when(path.toString()).thenReturn(PATH);
  65. when(clientInfo.getJavaInformation()).thenReturn(JAVA);
  66. when(clientInfo.getOperatingSystemInformation()).thenReturn(OS);
  67. when(connectionManager.getConnections()).thenReturn(Lists.newArrayList(connection));
  68. when(connection.getParser()).thenReturn(Optional.of(parser));
  69. when(parser.getServerName()).thenReturn(SERVER_NAME);
  70. when(connection.getState()).thenReturn(ServerState.CONNECTED);
  71. when(connection.getNetwork()).thenReturn(NETWORK_NAME);
  72. when(parser.getServerSoftware()).thenReturn(SERVER_SOFTWARE);
  73. when(parser.getServerSoftwareType()).thenReturn(SERVER_SOFTWARE_TYPE);
  74. when(parser.getBooleanChannelModes()).thenReturn(BOOLEAN_MODES);
  75. when(parser.getListChannelModes()).thenReturn(LIST_MODES);
  76. when(parser.getParameterChannelModes()).thenReturn(PARAM_MODES);
  77. when(parser.getDoubleParameterChannelModes()).thenReturn(DOUBLE_PARAM_MODES);
  78. instance = new FeedbackHelper(path, clientInfo, connectionManager, config);
  79. }
  80. private String getServerInfoOutput() {
  81. return "Actual name: " + SERVER_NAME + '\n'
  82. + "Network: " + NETWORK_NAME + '\n'
  83. + "IRCd: " + SERVER_SOFTWARE + " - " + SERVER_SOFTWARE_TYPE + '\n'
  84. + "Modes: " + BOOLEAN_MODES + ' ' + LIST_MODES + ' ' + PARAM_MODES + ' '
  85. + DOUBLE_PARAM_MODES;
  86. }
  87. private String getDMDircInfoOutput() {
  88. return "DMDirc version: " + VERSION + '\n'
  89. + "Profile directory: " + PATH + '\n'
  90. + "Java version: " + JAVA + '\n'
  91. + "OS Version: " + OS;
  92. }
  93. @Test
  94. public void testGetDMDircInfo() {
  95. assertEquals(getDMDircInfoOutput(), instance.getDMDircInfo());
  96. }
  97. @Test
  98. public void testGetServerInfo_Single() {
  99. assertEquals(getServerInfoOutput() + '\n', instance.getServerInfo());
  100. }
  101. @Test
  102. public void testGetServerInfo_Multiple() {
  103. when(connectionManager.getConnections()).thenReturn(
  104. Lists.newArrayList(connection, connection));
  105. assertEquals(getServerInfoOutput() + '\n' + getServerInfoOutput() + '\n',
  106. instance.getServerInfo());
  107. }
  108. @Test
  109. public void testGetServerInfoConnection() {
  110. assertEquals(getServerInfoOutput(), instance.getServerInfo(connection));
  111. }
  112. @Test
  113. public void testGetServerInfoConnection_Disconnected() {
  114. when(connection.getState()).thenReturn(ServerState.DISCONNECTED);
  115. assertEquals("", instance.getServerInfo(connection));
  116. }
  117. @Test
  118. public void testGetVersion() {
  119. assertEquals(VERSION, instance.getVersion());
  120. }
  121. }