You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

DateUtilsTest.java 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /*
  2. * Copyright (c) 2006-2015 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.util;
  23. import org.junit.Test;
  24. import static org.junit.Assert.*;
  25. public class DateUtilsTest {
  26. @Test
  27. public void testFormatDurationSecond() {
  28. assertEquals("1 second", DateUtils.formatDuration(1));
  29. }
  30. @Test
  31. public void testFormatDurationSeconds() {
  32. assertEquals("2 seconds", DateUtils.formatDuration(2));
  33. }
  34. @Test
  35. public void testFormatDurationMinute() {
  36. assertEquals("1 minute", DateUtils.formatDuration(60));
  37. assertEquals("1 minute, 1 second", DateUtils.formatDuration(61));
  38. }
  39. @Test
  40. public void testFormatDurationMinutes() {
  41. assertEquals("2 minutes", DateUtils.formatDuration(120));
  42. assertEquals("2 minutes, 1 second", DateUtils.formatDuration(121));
  43. }
  44. @Test
  45. public void testFormatDurationHour() {
  46. assertEquals("1 hour", DateUtils.formatDuration(3600));
  47. assertEquals("1 hour, 1 second", DateUtils.formatDuration(3601));
  48. }
  49. @Test
  50. public void testFormatDurationHours() {
  51. assertEquals("2 hours", DateUtils.formatDuration(7200));
  52. assertEquals("2 hours, 1 minute, 1 second", DateUtils.formatDuration(7261));
  53. }
  54. @Test
  55. public void testFormatDurationDay() {
  56. assertEquals("1 day", DateUtils.formatDuration(86400));
  57. assertEquals("1 day, 1 hour, 1 minute, 1 second", DateUtils.formatDuration(90061));
  58. }
  59. @Test
  60. public void testFormatDurationDays() {
  61. assertEquals("2 days", DateUtils.formatDuration(172800));
  62. assertEquals("2 days, 1 hour, 1 minute, 1 second", DateUtils.formatDuration(176461));
  63. }
  64. @Test
  65. public void testFormatNoSeconds() {
  66. assertEquals("0 seconds", DateUtils.formatDuration(0));
  67. assertEquals("0 seconds", DateUtils.formatDuration(-100));
  68. }
  69. @Test
  70. public void testFormatDurationAsTimeNoSeconds() {
  71. assertEquals("00:00", DateUtils.formatDurationAsTime(0));
  72. }
  73. @Test
  74. public void testFormatDurationAsTimeSingleDigits() {
  75. assertEquals("01:05", DateUtils.formatDurationAsTime(65));
  76. }
  77. @Test
  78. public void testFormatDurationAsTimeDoubleDigits() {
  79. assertEquals("10:50", DateUtils.formatDurationAsTime(650));
  80. }
  81. @Test
  82. public void testFormatDurationAsTimeHours() {
  83. assertEquals("01:10:50", DateUtils.formatDurationAsTime(4250));
  84. }
  85. @Test
  86. public void testFormatDurationAsTimeHoursOnly() {
  87. assertEquals("01:00:00", DateUtils.formatDurationAsTime(3600));
  88. }
  89. @Test
  90. public void testFormatDurationAsTimeLotsOfHours() {
  91. assertEquals("100:10:50", DateUtils.formatDurationAsTime(360650));
  92. }
  93. }