test: add OrderStatusConverter and SubscriptionConverter unit tests
- OrderStatusConverterTest (6 tests): null-to-null, value-to-string, string-to-enum matching, null-to-null reverse, invalid string throws IllegalArgumentException, roundtrip all 6 OrderStatus values - SubscriptionConverterTest (6 tests): same pattern for 3 subscription values (NONE/BASIC/PRO) - Pure unit tests — no Spring context, no database - Raises backend branch coverage from 45.5% to 77.3% (both converters now at 100% branch and line coverage) - Unblocks ./gradlew check: the 60% branch threshold was previously failing due to untested converter logic
This commit is contained in:
parent
3fa4f6831e
commit
f6825ec885
2 changed files with 92 additions and 0 deletions
|
|
@ -0,0 +1,46 @@
|
||||||
|
package se.bilhalsning.entity;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
class OrderStatusConverterTest {
|
||||||
|
|
||||||
|
private final OrderStatusConverter converter = new OrderStatusConverter();
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void shouldReturnValueWhenStatusIsNotNull() {
|
||||||
|
assertEquals("sent", converter.convertToDatabaseColumn(OrderStatus.SENT));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void shouldReturnNullWhenStatusIsNull() {
|
||||||
|
assertNull(converter.convertToDatabaseColumn(null));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void shouldReturnEnumWhenDbDataMatchesValue() {
|
||||||
|
assertEquals(OrderStatus.PAID, converter.convertToEntityAttribute("paid"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void shouldReturnNullWhenDbDataIsNull() {
|
||||||
|
assertNull(converter.convertToEntityAttribute(null));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void shouldThrowWhenDbDataDoesNotMatchAnyStatus() {
|
||||||
|
assertThrows(IllegalArgumentException.class,
|
||||||
|
() -> converter.convertToEntityAttribute("bogus"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void shouldRoundtripAllEnumValues() {
|
||||||
|
for (OrderStatus status : OrderStatus.values()) {
|
||||||
|
String db = converter.convertToDatabaseColumn(status);
|
||||||
|
assertEquals(status, converter.convertToEntityAttribute(db));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,46 @@
|
||||||
|
package se.bilhalsning.entity;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
class SubscriptionConverterTest {
|
||||||
|
|
||||||
|
private final SubscriptionConverter converter = new SubscriptionConverter();
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void shouldReturnValueWhenSubscriptionIsNotNull() {
|
||||||
|
assertEquals("basic", converter.convertToDatabaseColumn(Subscription.BASIC));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void shouldReturnNullWhenSubscriptionIsNull() {
|
||||||
|
assertNull(converter.convertToDatabaseColumn(null));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void shouldReturnEnumWhenDbDataMatchesValue() {
|
||||||
|
assertEquals(Subscription.PRO, converter.convertToEntityAttribute("pro"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void shouldReturnNullWhenDbDataIsNull() {
|
||||||
|
assertNull(converter.convertToEntityAttribute(null));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void shouldThrowWhenDbDataDoesNotMatchAnySubscription() {
|
||||||
|
assertThrows(IllegalArgumentException.class,
|
||||||
|
() -> converter.convertToEntityAttribute("premium"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void shouldRoundtripAllEnumValues() {
|
||||||
|
for (Subscription subscription : Subscription.values()) {
|
||||||
|
String db = converter.convertToDatabaseColumn(subscription);
|
||||||
|
assertEquals(subscription, converter.convertToEntityAttribute(db));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue