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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*
  2. * Copyright (c) 2006-2017 DMDirc Developers
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
  5. * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
  6. * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
  7. * permit persons to whom the Software is furnished to do so, subject to the following conditions:
  8. *
  9. * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
  10. * Software.
  11. *
  12. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  13. * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
  14. * OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  15. * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  16. */
  17. package com.dmdirc.util;
  18. import org.junit.Test;
  19. import static org.junit.Assert.*;
  20. public class DateUtilsTest {
  21. @Test
  22. public void testFormatDurationSecond() {
  23. assertEquals("1 second", DateUtils.formatDuration(1));
  24. }
  25. @Test
  26. public void testFormatDurationSeconds() {
  27. assertEquals("2 seconds", DateUtils.formatDuration(2));
  28. }
  29. @Test
  30. public void testFormatDurationMinute() {
  31. assertEquals("1 minute", DateUtils.formatDuration(60));
  32. assertEquals("1 minute, 1 second", DateUtils.formatDuration(61));
  33. }
  34. @Test
  35. public void testFormatDurationMinutes() {
  36. assertEquals("2 minutes", DateUtils.formatDuration(120));
  37. assertEquals("2 minutes, 1 second", DateUtils.formatDuration(121));
  38. }
  39. @Test
  40. public void testFormatDurationHour() {
  41. assertEquals("1 hour", DateUtils.formatDuration(3600));
  42. assertEquals("1 hour, 1 second", DateUtils.formatDuration(3601));
  43. }
  44. @Test
  45. public void testFormatDurationHours() {
  46. assertEquals("2 hours", DateUtils.formatDuration(7200));
  47. assertEquals("2 hours, 1 minute, 1 second", DateUtils.formatDuration(7261));
  48. }
  49. @Test
  50. public void testFormatDurationDay() {
  51. assertEquals("1 day", DateUtils.formatDuration(86400));
  52. assertEquals("1 day, 1 hour, 1 minute, 1 second", DateUtils.formatDuration(90061));
  53. }
  54. @Test
  55. public void testFormatDurationDays() {
  56. assertEquals("2 days", DateUtils.formatDuration(172800));
  57. assertEquals("2 days, 1 hour, 1 minute, 1 second", DateUtils.formatDuration(176461));
  58. }
  59. @Test
  60. public void testFormatNoSeconds() {
  61. assertEquals("0 seconds", DateUtils.formatDuration(0));
  62. assertEquals("0 seconds", DateUtils.formatDuration(-100));
  63. }
  64. @Test
  65. public void testFormatDurationAsTimeNoSeconds() {
  66. assertEquals("00:00", DateUtils.formatDurationAsTime(0));
  67. }
  68. @Test
  69. public void testFormatDurationAsTimeSingleDigits() {
  70. assertEquals("01:05", DateUtils.formatDurationAsTime(65));
  71. }
  72. @Test
  73. public void testFormatDurationAsTimeDoubleDigits() {
  74. assertEquals("10:50", DateUtils.formatDurationAsTime(650));
  75. }
  76. @Test
  77. public void testFormatDurationAsTimeHours() {
  78. assertEquals("01:10:50", DateUtils.formatDurationAsTime(4250));
  79. }
  80. @Test
  81. public void testFormatDurationAsTimeHoursOnly() {
  82. assertEquals("01:00:00", DateUtils.formatDurationAsTime(3600));
  83. }
  84. @Test
  85. public void testFormatDurationAsTimeLotsOfHours() {
  86. assertEquals("100:10:50", DateUtils.formatDurationAsTime(360650));
  87. }
  88. }