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ů.

ProgramErrorTest.java 6.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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.logger;
  23. import java.util.Arrays;
  24. import java.util.Date;
  25. import org.junit.Before;
  26. import org.junit.Test;
  27. import org.junit.runner.RunWith;
  28. import org.mockito.Mock;
  29. import org.mockito.runners.MockitoJUnitRunner;
  30. import static org.junit.Assert.*;
  31. @RunWith(MockitoJUnitRunner.class)
  32. public class ProgramErrorTest {
  33. @Mock private ErrorManager errorManager;
  34. @Before
  35. public void setup() {
  36. ErrorManager.setErrorManager(errorManager);
  37. }
  38. @Test(expected = IllegalArgumentException.class)
  39. public void testConstructorNegativeID() {
  40. new ProgramError(-1, ErrorLevel.HIGH, "moo", new String[0], new Date());
  41. }
  42. @Test(expected = IllegalArgumentException.class)
  43. public void testConstructorNullErrorLevel() {
  44. new ProgramError(1, null, "moo", new String[0], new Date());
  45. }
  46. @Test(expected = IllegalArgumentException.class)
  47. public void testConstructorNullMessage() {
  48. new ProgramError(1, ErrorLevel.HIGH, null, new String[0], new Date());
  49. }
  50. @Test(expected = IllegalArgumentException.class)
  51. public void testConstructorEmptyMessage() {
  52. new ProgramError(1, ErrorLevel.HIGH, "", new String[0], new Date());
  53. }
  54. @Test(expected = IllegalArgumentException.class)
  55. public void testConstructorNullTrace() {
  56. new ProgramError(1, ErrorLevel.HIGH, "moo", null, new Date());
  57. }
  58. @Test(expected = IllegalArgumentException.class)
  59. public void testConstructorNullDate() {
  60. new ProgramError(1, ErrorLevel.HIGH, "moo", new String[0], null);
  61. }
  62. @Test
  63. public void testConstructorGood() {
  64. new ProgramError(1, ErrorLevel.HIGH, "moo", new String[0], new Date());
  65. }
  66. @Test
  67. public void testGetLevel() {
  68. final ProgramError pe = new ProgramError(1, ErrorLevel.HIGH, "moo",
  69. new String[0], new Date());
  70. assertEquals(ErrorLevel.HIGH, pe.getLevel());
  71. }
  72. @Test
  73. public void testGetMessage() {
  74. final ProgramError pe = new ProgramError(1, ErrorLevel.HIGH, "moo",
  75. new String[0], new Date());
  76. assertEquals("moo", pe.getMessage());
  77. }
  78. @Test
  79. public void testGetTrace() {
  80. final String[] trace = new String[]{"abc", "def", "ghi", ""};
  81. final ProgramError pe = new ProgramError(1, ErrorLevel.HIGH, "moo",
  82. trace, new Date());
  83. assertTrue(Arrays.equals(trace, pe.getTrace()));
  84. }
  85. @Test
  86. public void testGetDate() {
  87. final Date date = new Date();
  88. final ProgramError pe = new ProgramError(1, ErrorLevel.HIGH, "moo",
  89. new String[0], date);
  90. assertEquals(date, pe.getDate());
  91. }
  92. @Test
  93. public void testReportStatus() {
  94. final ProgramError pe = new ProgramError(1, ErrorLevel.HIGH, "moo",
  95. new String[0], new Date());
  96. assertEquals(ErrorReportStatus.WAITING, pe.getReportStatus());
  97. pe.setReportStatus(null);
  98. assertEquals(ErrorReportStatus.WAITING, pe.getReportStatus());
  99. pe.setReportStatus(ErrorReportStatus.WAITING);
  100. assertEquals(ErrorReportStatus.WAITING, pe.getReportStatus());
  101. pe.setReportStatus(ErrorReportStatus.ERROR);
  102. assertEquals(ErrorReportStatus.ERROR, pe.getReportStatus());
  103. }
  104. @Test
  105. public void testFixedStatus() {
  106. final ProgramError pe = new ProgramError(1, ErrorLevel.HIGH, "moo",
  107. new String[0], new Date());
  108. assertEquals(ErrorFixedStatus.UNKNOWN, pe.getFixedStatus());
  109. pe.setFixedStatus(null);
  110. assertEquals(ErrorFixedStatus.UNKNOWN, pe.getFixedStatus());
  111. pe.setFixedStatus(ErrorFixedStatus.UNKNOWN);
  112. assertEquals(ErrorFixedStatus.UNKNOWN, pe.getFixedStatus());
  113. pe.setFixedStatus(ErrorFixedStatus.INVALID);
  114. assertEquals(ErrorFixedStatus.INVALID, pe.getFixedStatus());
  115. }
  116. @Test
  117. public void testToString() {
  118. final ProgramError pe = new ProgramError(1, ErrorLevel.HIGH, "moo",
  119. new String[0], new Date());
  120. assertTrue(pe.toString().indexOf("moo") > -1);
  121. }
  122. @Test
  123. public void testEquals() {
  124. final ProgramError pe1 = new ProgramError(10, ErrorLevel.LOW, "moo",
  125. new String[0], new Date());
  126. final ProgramError pe2 = new ProgramError(11, ErrorLevel.LOW, "moo",
  127. new String[0], new Date());
  128. final ProgramError pe3 = new ProgramError(10, ErrorLevel.MEDIUM, "moo",
  129. new String[0], new Date());
  130. final ProgramError pe4 = new ProgramError(10, ErrorLevel.LOW, "bar",
  131. new String[0], new Date());
  132. final ProgramError pe5 = new ProgramError(10, ErrorLevel.LOW, "moo",
  133. new String[]{"Hello"}, new Date());
  134. assertFalse(pe1.equals(null));
  135. assertFalse(pe1.equals("moo"));
  136. assertTrue(pe1.equals(pe2));
  137. assertTrue(pe1.equals(pe1));
  138. assertTrue(pe2.equals(pe1));
  139. assertFalse(pe1.equals(pe3));
  140. assertFalse(pe1.equals(pe4));
  141. assertFalse(pe1.equals(pe5));
  142. assertFalse(pe4.equals(pe5));
  143. assertFalse(pe4.equals(pe3));
  144. assertEquals(pe1.hashCode(), pe2.hashCode());
  145. assertEquals(pe1.hashCode(), pe1.hashCode());
  146. }
  147. }