比如,我们想要获取user的预期取值范围,代码可以这么写:

         public BaseUserDO getExpectUser(String nick){

                 

                   //给取值范围里的nick分组,只有在这个组里面的用户才存在,否则均返回null

                   String[] exsitUserNicks= {Nick.b2bNick.value, Nick.subB2BNick.value};

                 

                   if(ArrayUtil.contains(exsitUserNicks, nick)){

                          

                            //根据nick查出用户信息返回

                            ResultDO<BaseUserDO> callback = uicReadServiceClient.getUserInfoByNick(nick);

                          

                            Assert.assertTrue(callback.getErrMsg(), callback.isSuccess());

                            Assert.assertNotNull(callback.getModule());

                          

                            return callback.getModule();

                   }

                   return null;

         }

  代码中“Nick.b2bNick.value”,Nick是一个枚举,方便输入数据值域归类:

         public enum Nick{

                   blankNick(""),

                   nullNick(null),

                   notExsitNick("1233211"),

                  tbNick("leizang_test"),

                   b2bNick("leizang_btob_1"),

                   subB2BNick("leizang_btob_1:subnick01");

                 

                   String value;

                   Nick(String value){

                            this.value= value;

                   }

         }

  类似地,我们需要编写如下方法:

 

中间对象

被依赖对象

编写获取方法(省去类型)

user

nick

getExpectUser(nick)

ruleCode

user, wwLimitData

getExpectRuleCode(user, wwLimitData)

isFrozen

user, wwLimitData

getExpectIsFrozen(user, wwLimitData)

suspended

user, isFrozen

getExpectSuspended(user, isFrozen)

punishData

user, punishData, suspended

getExpectPunishData(user, punishData, suspended)

mmpData

user, mmpData

getExpectMmpData(user, mmpData)

  这样,我们产出结果的预期数据有了,终的比对形式应该是这样子,resultMap为接口返回实际结果:

         public void verify(String nick, String wwLimitData,

                            String punishData, String mmpData, Map<String, String> resultMap){

                 

                   BaseUserDO expectUser= getExpectUser(nick);

                   String expectRuleCode= getExpectRuleCode(expectUser, wwLimitData);

                   boolean expectIsFrozen= getExpectIsFrozen(expectUser, wwLimitData);

                   String expectSuspended= getExpectSuspended(expectUser, expectIsFrozen);

                   String expectPunishData= getExpectPunishData(expectUser, punishData, expectSuspended);

                   String expectMmpData= getExpectMmpData(expectUser, mmpData);

                 

                   Assert.assertEquals("user", expectUser, resultMap.get("user"));

                   Assert.assertEquals("ruleCode", expectRuleCode, resultMap.get("ruleCode"));

                   Assert.assertEquals("suspended", expectSuspended, resultMap.get("suspended"));

                   Assert.assertEquals("punishData", expectPunishData, resultMap.get("punishData"));

                   Assert.assertEquals("mmpData", expectMmpData, resultMap.get("mmpData"));

         }