您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

LogsTest.java 2.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*
  2. * SonarQube Runner - CLI - Distribution
  3. * Copyright (C) 2011 SonarSource
  4. * sonarqube@googlegroups.com
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 3 of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
  19. */
  20. package org.sonar.runner.cli;
  21. import org.junit.Before;
  22. import org.junit.Test;
  23. import org.mockito.Mock;
  24. import org.mockito.MockitoAnnotations;
  25. import java.io.PrintStream;
  26. import static org.mockito.Mockito.verifyNoMoreInteractions;
  27. import static org.mockito.Mockito.verify;
  28. public class LogsTest {
  29. @Mock
  30. private PrintStream stdOut;
  31. @Mock
  32. private PrintStream stdErr;
  33. private Logs logs;
  34. @Before
  35. public void setUp() {
  36. MockitoAnnotations.initMocks(this);
  37. logs = new Logs(stdOut, stdErr);
  38. }
  39. @Test
  40. public void testInfo() {
  41. logs.info("info");
  42. verify(stdOut).println("INFO: info");
  43. verifyNoMoreInteractions(stdOut, stdErr);
  44. }
  45. @Test
  46. public void testError() {
  47. Exception e = new NullPointerException("exception");
  48. logs.setDisplayStackTrace(false);
  49. logs.error("error1");
  50. verify(stdErr).println("ERROR: error1");
  51. logs.error("error2", e);
  52. verify(stdErr).println("ERROR: error2");
  53. verifyNoMoreInteractions(stdOut, stdErr);
  54. logs.setDisplayStackTrace(true);
  55. logs.error("error3", e);
  56. verify(stdErr).println("ERROR: error3");
  57. // other interactions to print the exception..
  58. }
  59. @Test
  60. public void testDebug() {
  61. logs.setDebugEnabled(true);
  62. logs.debug("debug");
  63. verify(stdOut).println("DEBUG: debug");
  64. logs.setDebugEnabled(false);
  65. logs.debug("debug");
  66. verifyNoMoreInteractions(stdOut, stdErr);
  67. }
  68. }