### Question:
XOauth2Mechanism extends AbstractMechanism { @Override public boolean isApplicable(String username, String password, Principal localPrincipal) { if(username != null && username.length() > 0 && password != null && password.length() > 0) { return ACCESS_TOKEN_PATTERN.matcher(password).matches(); } else { return false; } }  @Override int getPriority(); @Override String getName(); @Override byte[] getInitialResponse(); @Override byte[] getChallengeResponse(byte[] challenge); @Override boolean isApplicable(String username, String password, Principal localPrincipal); @Override String getAdditionalFailureInformation();  }### Answer:
@Test public void testIsNotApplicableWithNoCredentials() { XOauth2Mechanism mech = new XOauth2Mechanism(); assertFalse("Should not be applicable with no credentials", mech.isApplicable(null, null, null)); }
@Test public void testIsNotApplicableWithNoUser() { XOauth2Mechanism mech = new XOauth2Mechanism(); assertFalse("Should not be applicable with no username", mech.isApplicable(null, "pass", null)); }
@Test public void testIsNotApplicableWithNoToken() { XOauth2Mechanism mech = new XOauth2Mechanism(); assertFalse("Should not be applicable with no token", mech.isApplicable("user", null, null)); }
@Test public void testIsNotApplicableWithEmtpyUser() { XOauth2Mechanism mech = new XOauth2Mechanism(); assertFalse("Should not be applicable with empty username", mech.isApplicable("", "pass", null)); }
@Test public void testIsNotApplicableWithEmtpyToken() { XOauth2Mechanism mech = new XOauth2Mechanism(); assertFalse("Should not be applicable with empty token", mech.isApplicable("user", "", null)); }
@Test public void testIsNotApplicableWithIllegalAccessToken() { XOauth2Mechanism mech = new XOauth2Mechanism(); assertFalse("Should not be applicable with non vschars", mech.isApplicable("user", "illegalChar\000", null)); }
@Test public void testIsNotApplicableWithEmtpyUserAndToken() { XOauth2Mechanism mech = new XOauth2Mechanism(); assertFalse("Should not be applicable with empty user and token", mech.isApplicable("", "", null)); }
@Test public void testIsApplicableWithUserAndToken() { XOauth2Mechanism mech = new XOauth2Mechanism(); assertTrue("Should be applicable with user and token", mech.isApplicable("user", "2YotnFZFEjr1zCsicMWpAA", null)); }
@Test public void testIsApplicableWithUserAndPasswordAndPrincipal() { XOauth2Mechanism mech = new XOauth2Mechanism(); assertTrue("Should be applicable with user and token and principal", mech.isApplicable("user", "2YotnFZFEjr1zCsicMWpAA", new Principal() { @Override public String getName() { return "name"; } })); }