#39 Added some unit tests
This commit is contained in:
58
src/test/java/de/rwu/easydrop/util/FormattingUtilTest.java
Normal file
58
src/test/java/de/rwu/easydrop/util/FormattingUtilTest.java
Normal 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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user