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

StatsTest.java 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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 java.io.ByteArrayOutputStream;
  22. import java.io.PrintStream;
  23. import java.io.UnsupportedEncodingException;
  24. import org.junit.Test;
  25. import static org.fest.assertions.Assertions.assertThat;
  26. public class StatsTest {
  27. Logs logs = new Logs();
  28. @Test
  29. public void shouldPrintStats() throws UnsupportedEncodingException {
  30. PrintStream backupOut = System.out;
  31. ByteArrayOutputStream baos = new ByteArrayOutputStream();
  32. try {
  33. System.setOut(new PrintStream(baos));
  34. new Stats(logs).start().stop();
  35. String out = baos.toString();
  36. String[] lines = out.split(System.lineSeparator());
  37. assertThat(lines).hasSize(2);
  38. assertThat(lines[0]).contains("Total time: ");
  39. assertThat(lines[1]).contains("Final Memory: ");
  40. } finally {
  41. System.setOut(backupOut);
  42. }
  43. }
  44. @Test
  45. public void shouldFormatTime() {
  46. assertThat(Stats.formatTime(1 * 60 * 60 * 1000 + 2 * 60 * 1000 + 3 * 1000 + 400)).isEqualTo("1:02:03.400s");
  47. assertThat(Stats.formatTime(2 * 60 * 1000 + 3 * 1000 + 400)).isEqualTo("2:03.400s");
  48. assertThat(Stats.formatTime(3 * 1000 + 400)).isEqualTo("3.400s");
  49. assertThat(Stats.formatTime(400)).isEqualTo("0.400s");
  50. }
  51. }