refactor: simplify jt808 daily mileage strategy
This commit is contained in:
@@ -8,9 +8,6 @@ public enum DailyMileageStrategy {
|
||||
return JT808_TOTAL_MILEAGE_DIFF;
|
||||
}
|
||||
String normalized = value.trim();
|
||||
if ("CURRENT_LAST_MINUS_PREVIOUS_LAST".equals(normalized)) {
|
||||
return JT808_TOTAL_MILEAGE_DIFF;
|
||||
}
|
||||
return DailyMileageStrategy.valueOf(normalized);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import org.springframework.jdbc.datasource.DriverManagerDataSource;
|
||||
import java.time.LocalDate;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
|
||||
class JdbcVehicleStatMetricRepositoryTest {
|
||||
|
||||
@@ -147,7 +148,7 @@ class JdbcVehicleStatMetricRepositoryTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void readsLegacyCalculationMethodAsTotalMileageDifference() {
|
||||
void rejectsLegacyPreviousDayCalculationMethod() {
|
||||
JdbcTemplate jdbcTemplate = new JdbcTemplate(new DriverManagerDataSource(
|
||||
"jdbc:h2:mem:vehicle_stat_metric_legacy;MODE=MySQL;DATABASE_TO_LOWER=TRUE;DB_CLOSE_DELAY=-1",
|
||||
"sa",
|
||||
@@ -159,10 +160,8 @@ class JdbcVehicleStatMetricRepositoryTest {
|
||||
VALUES ('VIN001', DATE '2026-06-30', 'daily_mileage_km', 8.5, 'km', 'CURRENT_LAST_MINUS_PREVIOUS_LAST')
|
||||
""");
|
||||
|
||||
assertThat(repository.findDailyStat("VIN001", LocalDate.of(2026, 6, 30)))
|
||||
.isPresent()
|
||||
.get()
|
||||
.extracting(VehicleDailyStatResult::dailyMileageStrategy)
|
||||
.isEqualTo(DailyMileageStrategy.JT808_TOTAL_MILEAGE_DIFF);
|
||||
assertThatThrownBy(() -> repository.findDailyStat("VIN001", LocalDate.of(2026, 6, 30)))
|
||||
.isInstanceOf(IllegalArgumentException.class)
|
||||
.hasMessageContaining("CURRENT_LAST_MINUS_PREVIOUS_LAST");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user