LoginInfoJsonParser implements JsonParser<LoginInfo> { @Override public LoginInfo parse(JSONObject json) throws JSONException { final int failedLoginCount = json.optInt("failedLoginCount"); final int loginCount = json.getInt("loginCount"); final DateTime lastFailedLoginTime = JsonParseUtil.parseOptionalDateTime(json, "lastFailedLoginTime"); final DateTime previousLoginTime = JsonParseUtil.parseOptionalDateTime(json, "previousLoginTime"); return new LoginInfo(failedLoginCount, loginCount, lastFailedLoginTime, previousLoginTime); }  @Override LoginInfo parse(JSONObject json);  }
@Test public void testParse() throws Exception { final LoginInfoJsonParser parser = new LoginInfoJsonParser(); final LoginInfo loginInfo = parser.parse(ResourceUtil.getJsonObjectFromResource("/json/loginInfo/valid.json")); assertEquals(new LoginInfo(5, 379, TestUtil.toDateTime("2010-09-13T17:19:20.752+0200"), TestUtil.toDateTime("2010-09-13T17:19:38.220+0200")), loginInfo); }
@Test public void testParseNoFailedLoginBefore() throws Exception { final LoginInfoJsonParser parser = new LoginInfoJsonParser(); final LoginInfo loginInfo = parser.parse(ResourceUtil.getJsonObjectFromResource("/json/loginInfo/valid-no-login-failure.json")); assertEquals(new LoginInfo(0, 379, null, TestUtil.toDateTime("2010-09-13T17:19:38.220+0200")), loginInfo); }
@Test public void testParseNoLoginBefore() throws Exception { final LoginInfoJsonParser parser = new LoginInfoJsonParser(); final LoginInfo loginInfo = parser.parse(ResourceUtil.getJsonObjectFromResource("/json/loginInfo/valid-no-login-so-far.json")); assertEquals(new LoginInfo(0, 1, null, null), loginInfo); }