Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Unit testing 向enum添加值以测试交换机';s默认情况_Unit Testing_Groovy_Enums_Switch Statement - Fatal编程技术网

Unit testing 向enum添加值以测试交换机';s默认情况

Unit testing 向enum添加值以测试交换机';s默认情况,unit-testing,groovy,enums,switch-statement,Unit Testing,Groovy,Enums,Switch Statement,给定以下枚举: public enum SupportedLoanProcessor { PRE_AUTHORIZED, ACCURED_INTEREST } 如果类型支持LoanProessor,则使用开关处理值 switch(processorType){ case SupportedLoanProcessor.PRE_AUTHORIZED: result = processPreAuthorized allLendingsWithALoan,

给定以下枚举:

public enum SupportedLoanProcessor {
    PRE_AUTHORIZED,
    ACCURED_INTEREST
 }
如果类型支持LoanProessor,则使用开关处理值

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。
我认为在运行时修改枚举是可能的。但是我不知道如何执行。

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

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

public enum SupportedLoanProcessor {
    None = 0,
    PRE_AUTHORIZED,
    ACCURED_INTEREST
}

您是否仅为测试添加此值?单独的测试和应用程序代码如何?不,我将其永久添加到枚举中。当使用零时,它还具有作为.NET中枚举的默认值的属性。我不知道它在Java中是如何工作的。我认为它不是很干净。您混合了测试和业务逻辑测试。当我回答时,我没有意识到这是一个Groovy/Java问题。在.NET中,如果将实际值指定为0,这将是默认值,这在业务逻辑中通常是不可取的。应该有助于解决这个问题