mirror of
https://github.com/aljazceru/lnd-manageJ.git
synced 2026-01-20 22:44:31 +01:00
provide formatter as bean
This commit is contained in:
@@ -5,12 +5,15 @@ import de.cotto.lndmanagej.ui.controller.DashboardController;
|
||||
import de.cotto.lndmanagej.ui.dto.NodeDto;
|
||||
import de.cotto.lndmanagej.ui.dto.OpenChannelDto;
|
||||
import de.cotto.lndmanagej.ui.dto.StatusModel;
|
||||
import de.cotto.lndmanagej.ui.formatting.Formatter;
|
||||
import de.cotto.lndmanagej.ui.page.PageService;
|
||||
import de.cotto.lndmanagej.ui.page.general.DashboardPage;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
import org.springframework.boot.test.context.TestConfiguration;
|
||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
import java.util.List;
|
||||
@@ -51,4 +54,12 @@ class DashboardControllerIT {
|
||||
);
|
||||
mockMvc.perform(get("/")).andExpect(status().isOk());
|
||||
}
|
||||
|
||||
@TestConfiguration
|
||||
static class AdditionalConfiguration {
|
||||
@Bean
|
||||
public Formatter formatter() {
|
||||
return new Formatter();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package de.cotto.lndmanagej.ui.formatting;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.text.NumberFormat;
|
||||
|
||||
@Component
|
||||
public class Formatter {
|
||||
public Formatter() {
|
||||
// default constructor
|
||||
}
|
||||
|
||||
public String formatNumber(long value) {
|
||||
return NumberFormat.getInstance().format(value);
|
||||
}
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
package de.cotto.lndmanagej.ui.formatting;
|
||||
|
||||
import java.text.NumberFormat;
|
||||
|
||||
public final class NumberFormatter {
|
||||
private NumberFormatter() {
|
||||
// utility class
|
||||
}
|
||||
|
||||
public static String format(long value) {
|
||||
return NumberFormat.getInstance().format(value);
|
||||
}
|
||||
}
|
||||
@@ -19,9 +19,9 @@
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr th:each="channel : ${channels}">
|
||||
<td th:text="${T(de.cotto.lndmanagej.ui.formatting.NumberFormatter).format(channel.inbound)}" style="color: darkRed; text-align: right; padding-left:0;"></td>
|
||||
<td th:text="${@formatter.formatNumber(channel.inbound)}" style="color: darkRed; text-align: right; padding-left:0;"></td>
|
||||
<td th:text="${channel.ratio}"></td>
|
||||
<td th:text="${T(de.cotto.lndmanagej.ui.formatting.NumberFormatter).format(channel.outbound)}" style="color: darkGreen; text-align: right;"></td>
|
||||
<td th:text="${@formatter.formatNumber(channel.outbound)}" style="color: darkGreen; text-align: right;"></td>
|
||||
<td th:text="${channel.policies.local.baseFeeMilliSat}" style="text-align: right;"></td>
|
||||
<td th:text="${channel.policies.local.feeRatePpm}" style="text-align: right;"></td>
|
||||
<td th:text="${channel.policies.remote.baseFeeMilliSat}" style="text-align: right;"></td>
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
package de.cotto.lndmanagej.ui.formatting;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
class FormatterTest {
|
||||
private final Formatter formatter = new Formatter();
|
||||
|
||||
@Test
|
||||
void formatNumber_small_number() {
|
||||
assertThat(formatter.formatNumber(123)).isEqualTo("123");
|
||||
}
|
||||
|
||||
@Test
|
||||
void formatNumber_large_number() {
|
||||
assertThat(formatter.formatNumber(123_456_781_111L)).isEqualTo("123,456,781,111");
|
||||
}
|
||||
|
||||
@Test
|
||||
void formatNumber_negative_number() {
|
||||
assertThat(formatter.formatNumber(-123_456_781_111L)).isEqualTo("-123,456,781,111");
|
||||
}
|
||||
|
||||
@Test
|
||||
void formatNumber_zero() {
|
||||
assertThat(formatter.formatNumber(0)).isEqualTo("0");
|
||||
}
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
package de.cotto.lndmanagej.ui.formatting;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
class NumberFormatterTest {
|
||||
@Test
|
||||
void format_small_number() {
|
||||
assertThat(NumberFormatter.format(123)).isEqualTo("123");
|
||||
}
|
||||
|
||||
@Test
|
||||
void format_large_number() {
|
||||
assertThat(NumberFormatter.format(123_456_781_111L)).isEqualTo("123,456,781,111");
|
||||
}
|
||||
|
||||
@Test
|
||||
void format_negative_number() {
|
||||
assertThat(NumberFormatter.format(-123_456_781_111L)).isEqualTo("-123,456,781,111");
|
||||
}
|
||||
|
||||
@Test
|
||||
void format_zero() {
|
||||
assertThat(NumberFormatter.format(0)).isEqualTo("0");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user