bilhej/backend/src/test/java/se/bilhalsning/entity/SubscriptionConverterTest.java
Joakim Mörling f6825ec885 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
2026-05-15 19:58:18 +02:00

46 lines
1.4 KiB
Java

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));
}
}
}