### Question:
TOTPMechanism extends OathMechanism { public static TOTPBuilder builder() { return new TOTPBuilder(); } private  TOTPMechanism(String mechanismUID, String issuer, String accountName, String type, TokenType oathType,
                          String algorithm, String secret, int digits, int period, Calendar timeCreated); long getPeriod(); @Override OathTokenCode getOathTokenCode(); @Override String toJson(); static TOTPBuilder builder();  }### Answer:
@Test public void testShouldBeEqualEquivalentTOTPMechanism() { Mechanism mechanism1 = TOTPMechanism.builder() .setMechanismUID(MECHANISM_UID) .setIssuer(ISSUER) .setAccountName(ACCOUNT_NAME) .setAlgorithm(ALGORITHM) .setSecret(SECRET) .setDigits(DIGITS) .setPeriod(PERIOD) .build(); Mechanism mechanism2 = TOTPMechanism.builder() .setMechanismUID(MECHANISM_UID) .setIssuer(ISSUER) .setAccountName(ACCOUNT_NAME) .setAlgorithm(ALGORITHM) .setSecret(SECRET) .setDigits(DIGITS) .setPeriod(PERIOD) .build(); assertEquals(mechanism1, mechanism2); assertTrue(mechanism1.matches(mechanism2)); assertEquals(mechanism1.hashCode(), mechanism2.hashCode()); }
@Test public void testShouldNotBeEqualDifferentTOTPMechanismWithAccountName() { Mechanism mechanism1 = TOTPMechanism.builder() .setMechanismUID(MECHANISM_UID) .setIssuer(ISSUER) .setAccountName(ACCOUNT_NAME) .setAlgorithm(ALGORITHM) .setSecret(SECRET) .setDigits(DIGITS) .setPeriod(PERIOD) .build(); Mechanism mechanism2 = TOTPMechanism.builder() .setMechanismUID(MECHANISM_UID) .setIssuer(ISSUER) .setAccountName(OTHER_ACCOUNT_NAME) .setAlgorithm(ALGORITHM) .setSecret(SECRET) .setDigits(DIGITS) .setPeriod(PERIOD) .build(); assertFalse(mechanism1.equals(mechanism2)); assertFalse(mechanism1.matches(mechanism2)); }
@Test public void testShouldNotBeEqualDifferentTOTPMechanismWithAccountIssuer() { Mechanism mechanism1 = TOTPMechanism.builder() .setMechanismUID(MECHANISM_UID) .setIssuer(ISSUER) .setAccountName(ACCOUNT_NAME) .setAlgorithm(ALGORITHM) .setSecret(SECRET) .setDigits(DIGITS) .setPeriod(PERIOD) .build(); Mechanism mechanism2 = TOTPMechanism.builder() .setMechanismUID(MECHANISM_UID) .setIssuer(OTHER_ISSUER) .setAccountName(ACCOUNT_NAME) .setAlgorithm(ALGORITHM) .setSecret(SECRET) .setDigits(DIGITS) .setPeriod(PERIOD) .build(); assertFalse(mechanism1.equals(mechanism2)); assertFalse(mechanism1.matches(mechanism2)); }