Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

ProgramErrorTest.java 3.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. * Copyright (c) 2006-2008 Chris Smith, Shane Mc Cormack, Gregory Holmes
  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.logger.ErrorLevel;
  24. import com.dmdirc.logger.ErrorReportStatus;
  25. import com.dmdirc.logger.ProgramError;
  26. import java.util.Arrays;
  27. import java.util.Date;
  28. import org.junit.Before;
  29. import org.junit.Test;
  30. import static org.junit.Assert.*;
  31. public class ProgramErrorTest extends junit.framework.TestCase {
  32. private ErrorLevel level;
  33. private String message;
  34. private String[] trace;
  35. private Date date;
  36. @Before
  37. public void setUp() throws Exception {
  38. level = ErrorLevel.HIGH;
  39. message = "Test error";
  40. trace = new String[]{"line 1", "line 2", };
  41. date = new Date(System.currentTimeMillis());
  42. }
  43. @Test
  44. public void testGetLevel() {
  45. final ProgramError inst = new ProgramError(0, level, message, trace, date);
  46. assertEquals("Level check failed.", level, inst.getLevel());
  47. }
  48. @Test
  49. public void testGetMessage() {
  50. final ProgramError inst = new ProgramError(0, level, message, trace, date);
  51. assertEquals("Message check failed.", message, inst.getMessage());
  52. }
  53. @Test
  54. public void testGetTrace() {
  55. final ProgramError inst = new ProgramError(0, level, message, trace, date);
  56. assertTrue("Trace check failed", Arrays.equals(trace, inst.getTrace())); //NOPMD
  57. }
  58. @Test
  59. public void testGetDate() {
  60. final ProgramError inst = new ProgramError(0, level, message, trace, date);
  61. assertTrue("Date check after failed.", inst.getDate().after(new Date(date.getTime() - 1)));
  62. assertTrue("Date check before failed.", inst.getDate().before(new Date(date.getTime() + 1)));
  63. }
  64. @Test
  65. public void testGetStatus() {
  66. final ProgramError inst = new ProgramError(0, level, message, trace, date);
  67. assertEquals("Get status check failed.", ErrorReportStatus.WAITING, inst.getReportStatus());
  68. }
  69. @Test
  70. public void testSetStatus() {
  71. final ProgramError inst = new ProgramError(0, level, message, trace, date);
  72. assertEquals("Get status check failed.", ErrorReportStatus.WAITING, inst.getReportStatus());
  73. inst.setReportStatus(ErrorReportStatus.FINISHED);
  74. assertEquals("Set status check failed.", ErrorReportStatus.FINISHED, inst.getReportStatus());
  75. }
  76. }