### Question:
ExternalMechanism extends AbstractMechanism { @Override public boolean isApplicable(String username, String password, Principal localPrincipal) { return localPrincipal != null; }  @Override byte[] getInitialResponse(); @Override byte[] getChallengeResponse(byte[] challenge); @Override int getPriority(); @Override String getName(); @Override boolean isApplicable(String username, String password, Principal localPrincipal);  }### Answer:
@Test public void testIsNotApplicableWithUserAndPasswordButNoPrincipal() { ExternalMechanism mech = new ExternalMechanism(); assertFalse("Should not be applicable with user and password but no principal", mech.isApplicable("user", "password", null)); }
@Test public void testIsApplicableWithUserAndPasswordAndPrincipal() { ExternalMechanism mech = new ExternalMechanism(); assertTrue("Should be applicable with user and password and principal", mech.isApplicable("user", "password", new Principal() { @Override public String getName() { return "name"; } })); }
@Test public void testIsApplicableWithPrincipalOnly() { ExternalMechanism mech = new ExternalMechanism(); assertTrue("Should be applicable with principal only", mech.isApplicable(null, null, new Principal() { @Override public String getName() { return "name"; } })); }