OAuth2StateUtil { public static boolean isValid( OAuth2State oAuth2State, HttpServletRequest httpServletRequest) { if (Validator.isNotNull( ParamUtil.getString(httpServletRequest, "error"))) { return false; } String state = ParamUtil.getString(httpServletRequest, "state"); return oAuth2State.isValid(state); }  static void cleanUp(HttpServletRequest httpServletRequest); static Optional<OAuth2State> getOAuth2StateOptional(
		HttpServletRequest httpServletRequest); static boolean isValid(
		OAuth2State oAuth2State, HttpServletRequest httpServletRequest); static void save(
		HttpServletRequest httpServletRequest, OAuth2State oAuth2State);  }
@Test public void testIsValidWithDifferentState() { MockHttpServletRequest mockHttpServletRequest = new MockHttpServletRequest(); mockHttpServletRequest.setParameter( "state", RandomTestUtil.randomString(5)); OAuth2State oAuth2State = new OAuth2State( RandomTestUtil.randomLong(), RandomTestUtil.randomString(), RandomTestUtil.randomString(), RandomTestUtil.randomString(5)); Assert.assertFalse( OAuth2StateUtil.isValid(oAuth2State, mockHttpServletRequest)); }
@Test public void testIsValidWithSameState() { MockHttpServletRequest mockHttpServletRequest = new MockHttpServletRequest(); String state = RandomTestUtil.randomString(); mockHttpServletRequest.setParameter("state", state); OAuth2State oAuth2State = new OAuth2State( RandomTestUtil.randomLong(), RandomTestUtil.randomString(), RandomTestUtil.randomString(), state); Assert.assertTrue( OAuth2StateUtil.isValid(oAuth2State, mockHttpServletRequest)); }