优化
This commit is contained in:
@@ -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())
|
||||
|
||||
Reference in New Issue
Block a user