Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

StatsTest.java 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /*
  2. * SonarScanner CLI
  3. * Copyright (C) 2011-2022 SonarSource SA
  4. * mailto:info AT sonarsource DOT 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 License
  17. * along with this program; if not, write to the Free Software Foundation,
  18. * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  19. */
  20. package org.sonarsource.scanner.cli;
  21. import java.io.PrintStream;
  22. import org.junit.Test;
  23. import org.mockito.Mockito;
  24. import static org.assertj.core.api.Assertions.assertThat;
  25. import static org.mockito.Mockito.mock;
  26. import static org.mockito.Mockito.verify;
  27. public class StatsTest {
  28. private final PrintStream stdOut = mock(PrintStream.class);
  29. private final PrintStream stdErr = mock(PrintStream.class);
  30. private final Logs logs = new Logs(stdOut, stdErr);
  31. @Test
  32. public void shouldPrintStats() {
  33. new Stats(logs).start().stop();
  34. verify(stdOut).println(Mockito.contains("Total time: "));
  35. verify(stdOut).println(Mockito.contains("Final Memory: "));
  36. }
  37. @Test
  38. public void shouldFormatTime() {
  39. assertThat(Stats.formatTime(1 * 60 * 60 * 1000 + 2 * 60 * 1000 + 3 * 1000 + 400)).isEqualTo("1:02:03.400s");
  40. assertThat(Stats.formatTime(2 * 60 * 1000 + 3 * 1000 + 400)).isEqualTo("2:03.400s");
  41. assertThat(Stats.formatTime(3 * 1000 + 400)).isEqualTo("3.400s");
  42. assertThat(Stats.formatTime(400)).isEqualTo("0.400s");
  43. }
  44. }