This commit is contained in:
2026-08-18 11:46:10 +08:00
parent cad9a81d21
commit 4e4d047862
2 changed files with 16 additions and 1 deletions
@@ -15,7 +15,8 @@ public class InboundCodeModeProvider {
private final Mode mode;
public InboundCodeModeProvider(@Value("${baiyue.order.inbound-code-mode}") String configuredMode) {
public InboundCodeModeProvider(
@Value("${baiyue.order.inbound-code-mode:LEGACY_MANUAL}") String configuredMode) {
if (!StringUtils.hasText(configuredMode)) {
throw new IllegalStateException("baiyue.order.inbound-code-mode 必须显式配置");
}
@@ -1,11 +1,25 @@
package com.baiyue.order.config;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Value;
import java.lang.reflect.Constructor;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
class InboundCodeModeProviderTest {
@Test
void springPlaceholderDefaultsToLegacyManualWhenEnvironmentPropertyIsMissing() {
Constructor<?> constructor = InboundCodeModeProvider.class.getDeclaredConstructors()[0];
Value value = constructor.getParameters()[0].getAnnotation(Value.class);
assertThat(value.value())
.isEqualTo("${baiyue.order.inbound-code-mode:LEGACY_MANUAL}");
assertThat(new InboundCodeModeProvider("LEGACY_MANUAL").mode())
.isEqualTo(InboundCodeModeProvider.Mode.LEGACY_MANUAL);
}
@Test
void parsesBothSupportedModesCaseInsensitively() {
assertThat(new InboundCodeModeProvider("auto").mode())