73 lines
2.4 KiB
Java
73 lines
2.4 KiB
Java
package de.rwu.easydrop.util;
|
|
|
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
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;
|
|
|
|
class FormattingUtilTest {
|
|
|
|
@Test
|
|
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
|
|
void testFormatEuro_positiveAmount() {
|
|
double amount = 1234.56;
|
|
String expectedFormattedAmount = "1.234,56 Euro";
|
|
|
|
String formattedAmount = FormattingUtil.formatEuro(amount);
|
|
|
|
Assertions.assertEquals(expectedFormattedAmount, formattedAmount);
|
|
}
|
|
|
|
@Test
|
|
void testFormatEuro_zeroAmount() {
|
|
double amount = 0.0;
|
|
String expectedFormattedAmount = "0,00 Euro";
|
|
|
|
String formattedAmount = FormattingUtil.formatEuro(amount);
|
|
|
|
Assertions.assertEquals(expectedFormattedAmount, formattedAmount);
|
|
}
|
|
|
|
@Test
|
|
void testFormatEuro_negativeAmount() {
|
|
double amount = -789.12;
|
|
String expectedFormattedAmount = "-789,12 Euro";
|
|
|
|
String formattedAmount = FormattingUtil.formatEuro(amount);
|
|
|
|
Assertions.assertEquals(expectedFormattedAmount, formattedAmount);
|
|
}
|
|
|
|
@Test
|
|
void testRemoveSpaces_RemovesAllSpaces() {
|
|
String test1 = FormattingUtil.removeSpaces("this is a test");
|
|
String test2 = FormattingUtil.removeSpaces("another test");
|
|
String test3 = FormattingUtil.removeSpaces(" daring today, aren't we? ");
|
|
String test4 = FormattingUtil.removeSpaces("hehe");
|
|
|
|
assertEquals("thisisatest", test1);
|
|
assertEquals("anothertest", test2);
|
|
assertEquals("daringtoday,aren'twe?", test3);
|
|
assertEquals("hehe", test4);
|
|
}
|
|
}
|