Split up test method into smaller ones. Correct code formatting

This commit is contained in:
Marcin Krykowski 2020-05-30 05:32:54 +01:00
parent 5cfe661c8a
commit 3396e92d2d
2 changed files with 60 additions and 52 deletions

View File

@ -10,23 +10,15 @@ public class FormatNumberUnitTest {
private static final double F = 8.6994540927d; private static final double F = 8.6994540927d;
@Test @Test
public void givenDecimalNumber_whenFormatNumberToNDecimalPlaces_thenGetExpectedResult() { public void givenDecimalNumber_whenFormatNumber_withBigDecimal_thenGetExpectedResult() {
assertThat(withBigDecimal(D, 2)).isEqualTo(4.24); assertThat(withBigDecimal(D, 2)).isEqualTo(4.24);
assertThat(withBigDecimal(D, 3)).isEqualTo(4.235); assertThat(withBigDecimal(D, 3)).isEqualTo(4.235);
assertThat(withBigDecimal(F, 2)).isEqualTo(8.7); assertThat(withBigDecimal(F, 2)).isEqualTo(8.7);
assertThat(withBigDecimal(F, 3)).isEqualTo(8.699); assertThat(withBigDecimal(F, 3)).isEqualTo(8.699);
}
assertThat(withMathRound(D, 2)).isEqualTo(4.24); @Test
assertThat(withMathRound(D, 3)).isEqualTo(4.235); public void givenDecimalNumber_whenFormatNumber_withDecimalFormat_thenGetExpectedResult() {
assertThat(withMathRound(F, 2)).isEqualTo(8.7);
assertThat(withMathRound(F, 3)).isEqualTo(8.699);
assertThat(withStringFormat(D, 2)).isEqualTo("4.24");
assertThat(withStringFormat(D, 3)).isEqualTo("4.235");
assertThat(withStringFormat(F, 2)).isEqualTo("8.70");
assertThat(withStringFormat(F, 3)).isEqualTo("8.699");
assertThat(withDecimalFormatLocal(D)).isEqualTo(4.235); assertThat(withDecimalFormatLocal(D)).isEqualTo(4.235);
assertThat(withDecimalFormatLocal(F)).isEqualTo(8.699); assertThat(withDecimalFormatLocal(F)).isEqualTo(8.699);
@ -35,4 +27,20 @@ public class FormatNumberUnitTest {
assertThat(withDecimalFormatPattern(F, 2)).isEqualTo(8.7); assertThat(withDecimalFormatPattern(F, 2)).isEqualTo(8.7);
assertThat(withDecimalFormatPattern(F, 3)).isEqualTo(8.699); assertThat(withDecimalFormatPattern(F, 3)).isEqualTo(8.699);
} }
@Test
public void givenDecimalNumber_whenFormatNumber_withStringFormat_thenGetExpectedResult() {
assertThat(withStringFormat(D, 2)).isEqualTo("4.24");
assertThat(withStringFormat(D, 3)).isEqualTo("4.235");
assertThat(withStringFormat(F, 2)).isEqualTo("8.70");
assertThat(withStringFormat(F, 3)).isEqualTo("8.699");
}
@Test
public void givenDecimalNumber_whenFormatNumber_withMathRound_thenGetExpectedResult() {
assertThat(withMathRound(D, 2)).isEqualTo(4.24);
assertThat(withMathRound(D, 3)).isEqualTo(4.235);
assertThat(withMathRound(F, 2)).isEqualTo(8.7);
assertThat(withMathRound(F, 3)).isEqualTo(8.699);
}
} }