Coverage Report - com.ctrip.framework.apollo.common.utils.RequestPrecondition
 
Classes in this File Line Coverage Branch Coverage Complexity
RequestPrecondition
0%
0/15
0%
0/8
2.25
 
 1  
 package com.ctrip.framework.apollo.common.utils;
 2  
 
 3  
 
 4  
 import com.ctrip.framework.apollo.core.exception.BadRequestException;
 5  
 import com.ctrip.framework.apollo.core.utils.StringUtils;
 6  
 
 7  
 
 8  0
 public class RequestPrecondition {
 9  
 
 10  0
   private static String CONTAIN_EMPTY_ARGUMENT = "request payload should not be contain empty.";
 11  
 
 12  0
   private static String ILLEGAL_MODEL = "request model is invalid";
 13  
 
 14  0
   private static String ILLEGAL_NUMBER = "number should be positive";
 15  
 
 16  
 
 17  
   public static void checkArgument(String... args) {
 18  0
     checkArgument(!StringUtils.isContainEmpty(args), CONTAIN_EMPTY_ARGUMENT);
 19  0
   }
 20  
 
 21  
   public static void checkModel(boolean valid){
 22  0
     checkArgument(valid, ILLEGAL_MODEL);
 23  0
   }
 24  
 
 25  
   public static void checkArgument(boolean expression, Object errorMessage) {
 26  0
     if (!expression) {
 27  0
       throw new BadRequestException(String.valueOf(errorMessage));
 28  
     }
 29  0
   }
 30  
 
 31  
   public static void checkNumberPositive(int... args){
 32  0
     for (int num: args){
 33  0
       if (num <= 0){
 34  0
         throw new BadRequestException(ILLEGAL_NUMBER);
 35  
       }
 36  
     }
 37  0
   }
 38  
 
 39  
 
 40  
 
 41  
 }