HashMap如何解决取Value值为Null

场景: 用HashMap方法时候,取Keys时候自认为敲的肯定是准确无误,然后能得到对应的Values 值。  但写脚本代码时候不好习惯,没事总喜欢敲个空格建,导致取Keys之后多空格。

 

 

Feature示例:

  And I add period details for 李尔考勤周期
      |名称       |  年      | 月    | 开始时间       | 结束时间     |
      |201701    | 2017     | 8     | 2017-07-01    | 2017-07-31 |

 

错误代码示例:

 @And("^I add period details for (.+)$")
     public void i_add_period_details_for(String penseeSoftCycle, DataTable data) throws Throwable {
         HashMap<String, String> hash = DataTableUtils.toHashMap(data);
         String cycleName = hash.get("名称");
         String year = hash.get("年");
         String month = hash.get("月 ");
         String startDate = hash.get("开始时间");
         String endDate = hash.get("结束时间");
         vp.addPeriod(penseeSoftCycle, cycleName, year, month, startDate, endDate); 

导致效果:

    Data集合是可以取到键值对的,

 

解决方法:需要Debug调试,得到取到对应的值是否取到。 养成良好的编码习惯,避免犯低级错误!

posted @ 2017-11-14 14:17  vame  Views(3122)  Comments(0Edit  收藏  举报