/*
 * This file is part of Bisq.
 *
 * Bisq is free software: you can redistribute it and/or modify it
 * under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or (at
 * your option) any later version.
 *
 * Bisq is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
 * License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with Bisq. If not, see <http://www.gnu.org/licenses/>.
 */

package io.bisq.gui.util;

import io.bisq.common.locale.Res;
import org.junit.Before;
import org.junit.Test;

import java.util.Locale;
import java.util.concurrent.TimeUnit;

import static org.junit.Assert.assertEquals;

public class BSFormatterTest {

    private BSFormatter formatter;

    @Before
    public void setup() {
        Locale.setDefault(new Locale("en", "US"));
        formatter = new BSFormatter();
        Res.setBaseCurrencyCode("BTC");
        Res.setBaseCurrencyName("Bitcoin");
    }

    @Test
    public void testIsValid() {
        assertEquals("0 days", formatter.formatAccountAge(TimeUnit.HOURS.toMillis(23)));
        assertEquals("0 days", formatter.formatAccountAge(0));
        assertEquals("0 days", formatter.formatAccountAge(-1));
        assertEquals("1 day", formatter.formatAccountAge(TimeUnit.DAYS.toMillis(1)));
        assertEquals("2 days", formatter.formatAccountAge(TimeUnit.DAYS.toMillis(2)));
        assertEquals("30 days", formatter.formatAccountAge(TimeUnit.DAYS.toMillis(30)));
        assertEquals("60 days", formatter.formatAccountAge(TimeUnit.DAYS.toMillis(60)));
    }

    @Test
    public void testFormatDurationAsWords() {
        assertEquals("1 hour, 0 minutes", formatter.formatDurationAsWords(60 * 60 * 1000));
        assertEquals("1 day, 0 hours, 0 minutes", formatter.formatDurationAsWords(24 * 60 * 60 * 1000));
        assertEquals("2 days, 0 hours, 1 minute", formatter.formatDurationAsWords((2 * 24 * 60 + 1) * 60 * 1000));
        assertEquals("2 days, 0 hours, 2 minutes", formatter.formatDurationAsWords((2 * 24 * 60 + 2) * 60 * 1000));
        assertEquals("1 hour, 0 minutes, 0 seconds", formatter.formatDurationAsWords(60 * 60 * 1000, true));
        assertEquals("1 hour, 0 minutes, 1 second", formatter.formatDurationAsWords((60 * 60 + 1) * 1000, true));
        assertEquals("1 hour, 0 minutes, 2 seconds", formatter.formatDurationAsWords((60 * 60 + 2) * 1000, true));
        assertEquals("Trade period is over", formatter.formatDurationAsWords(0));
    }
}

@@ -1850,24 +1850,235 @@
 AsWords() %7B%0A
+        long oneDay = TimeUnit.DAYS.toMillis(1);%0A        long oneHour = TimeUnit.HOURS.toMillis(1);%0A        long oneMinute = TimeUnit.MINUTES.toMillis(1);%0A        long oneSecond = TimeUnit.SECONDS.toMillis(1);%0A%0A
         asse
@@ -2139,30 +2139,23 @@
 AsWords(
-60 * 60 * 1000
+oneHour
 ));%0A    
@@ -2236,27 +2236,14 @@
 rds(
-24 * 60 * 60 * 1000
+oneDay
 ));%0A
@@ -2328,37 +2328,30 @@
 rds(
-(2 * 24 * 60 + 1) * 60 * 1000
+oneDay * 2 + oneMinute
 ));%0A
@@ -2437,37 +2437,34 @@
 rds(
-(2 * 24 * 60 + 2) * 60 * 1000
+oneDay * 2 + oneMinute * 2
 ));%0A
@@ -2552,22 +2552,15 @@
 rds(
-60 * 60 * 1000
+oneHour
 , tr
@@ -2653,28 +2653,27 @@
 rds(
-(60 * 60 + 1) * 1000
+oneHour + oneSecond
 , tr
@@ -2767,28 +2767,31 @@
 rds(
-(60 * 60 + 2) * 1000
+oneHour + oneSecond * 2
 , tr

Use TimeUnit