0

给定以下枚举:

public enum SupportedLoanProcessor {
    PRE_AUTHORIZED,
    ACCURED_INTEREST
 }

如果类型为 SupportedLoanProessor,则开关在一个值上工作

switch(processorType){
      case SupportedLoanProcessor.PRE_AUTHORIZED:
        result = processPreAuthorized allLendingsWithALoan, date
      break
      case SupportedLoanProcessor.ACCURED_INTEREST:
        result = processAccuredInterest allLendingsWithALoan, date
      break
      default:
        throw new IllegalArgumentException("Unknow loan processor: $processorType")
    }

如何测试默认情况。我正在使用groovy和junit。我想在运行时修改枚举是可能的。但我不知道怎么做。

4

1 回答 1

0

不可能执行默认情况,因为枚举除了开关覆盖的值之外没有其他值。

如果您试图在未来证明您的应用程序,因为当有更多可能的值时,我的方法通常是在枚举中添加一个 None 。

public enum SupportedLoanProcessor {
    None = 0,
    PRE_AUTHORIZED,
    ACCURED_INTEREST
}
于 2013-06-11T13:42:04.283 回答