### Question:
OathMechanism extends Mechanism { @Override public abstract String toJson(); protected  OathMechanism(String mechanismUID, String issuer, String accountName, String type, TokenType oathType,
                            String algorithm, String secret, int digits, Calendar timeCreated); int getDigits(); String getAlgorithm(); TokenType getOathType(); abstract OathTokenCode getOathTokenCode(); @Override abstract String toJson();  }### Answer:
@Test public void testShouldParseHOTPToJsonSuccessfully() { String json = "{" + "\"id\":\"issuer1-user1-otpauth\"," + "\"issuer\":\"issuer1\"," + "\"accountName\":\"user1\"," + "\"mechanismUID\":\"b162b325-ebb1-48e0-8ab7-b38cf341da95\"," + "\"secret\":\"REMOVED\"," + "\"type\":\"otpauth\"," + "\"oathType\":\"HOTP\"," + "\"algorithm\":\"sha1\"," + "\"digits\":6," + "\"counter\":\"REMOVED\"" + "}"; OathMechanism mechanism = HOTPMechanism.builder() .setMechanismUID(MECHANISM_UID) .setIssuer(ISSUER) .setAccountName(ACCOUNT_NAME) .setAlgorithm(ALGORITHM) .setSecret(SECRET) .setDigits(DIGITS) .setCounter(COUNTER) .build(); String mechanismAsJson = mechanism.toJson(); assertNotNull(mechanismAsJson); assertEquals(json, mechanismAsJson); }
@Test public void testShouldParseTOTPToJsonSuccessfully() { String json = "{" + "\"id\":\"issuer1-user1-otpauth\"," + "\"issuer\":\"issuer1\"," + "\"accountName\":\"user1\"," + "\"mechanismUID\":\"b162b325-ebb1-48e0-8ab7-b38cf341da95\"," + "\"secret\":\"REMOVED\"," + "\"type\":\"otpauth\"," + "\"oathType\":\"TOTP\"," + "\"algorithm\":\"sha1\"," + "\"digits\":6," + "\"period\":30" + "}"; OathMechanism mechanism = TOTPMechanism.builder() .setMechanismUID(MECHANISM_UID) .setIssuer(ISSUER) .setAccountName(ACCOUNT_NAME) .setAlgorithm(ALGORITHM) .setSecret(SECRET) .setDigits(DIGITS) .setPeriod(PERIOD) .build(); String mechanismAsJson = mechanism.toJson(); assertNotNull(mechanismAsJson); assertEquals(json, mechanismAsJson); }