#39 Added some unit tests

This commit is contained in:
Marvin Scham
2023-05-24 00:24:30 +02:00
parent 17bd6ab587
commit da1cad1a59
3 changed files with 283 additions and 13 deletions

View File

@@ -0,0 +1,58 @@
package de.rwu.easydrop.util;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Modifier;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
public class FormattingUtilTest {
@Test
public void testConstructorIsPrivate()
throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
// Check for private constructor
Constructor<FormattingUtil> constructor = FormattingUtil.class.getDeclaredConstructor();
assertTrue(Modifier.isPrivate(constructor.getModifiers()));
// Make sure exception is thrown when instantiating
constructor.setAccessible(true);
assertThrows(InvocationTargetException.class, () -> {
constructor.newInstance();
});
}
@Test
public void testFormatEuro_positiveAmount() {
double amount = 1234.56;
String expectedFormattedAmount = "1.234,56 €";
String formattedAmount = FormattingUtil.formatEuro(amount);
Assertions.assertEquals(expectedFormattedAmount, formattedAmount);
}
@Test
public void testFormatEuro_zeroAmount() {
double amount = 0.0;
String expectedFormattedAmount = "0,00 €";
String formattedAmount = FormattingUtil.formatEuro(amount);
Assertions.assertEquals(expectedFormattedAmount, formattedAmount);
}
@Test
public void testFormatEuro_negativeAmount() {
double amount = -789.12;
String expectedFormattedAmount = "-789,12 €";
String formattedAmount = FormattingUtil.formatEuro(amount);
Assertions.assertEquals(expectedFormattedAmount, formattedAmount);
}
}