### Question:
Identity { private void setUpMerchant() throws SignException { if (serialNumber == null && x509Cert != null) { String subjectDN = x509Cert.getSubjectDN().getName(); if (subjectDN != null) { String[] subjectDNrray = subjectDN.split("SERIALNUMBER="); if (subjectDNrray.length != 2) { throw new SignException("Exception while obtaining private key from KeyStore with alias, '" + merchantConfig.getKeyAlias() + "'"); } name = merchantConfig.getMerchantID(); pswd = merchantConfig.getKeyPassword().toCharArray(); serialNumber = subjectDNrray[1]; keyAlias = merchantConfig.getKeyAlias(); } else { throw new SignException("Exception while obtaining private key from KeyStore with alias, '" + merchantConfig.getKeyAlias() + "'"); } } } Identity(MerchantConfig merchantConfig,X509Certificate x509Certificate,Logger logger);  Identity(MerchantConfig merchantConfig,X509Certificate x509Certificate, PrivateKey privateKey, Logger logger); boolean isValid(File keyFile, Logger logger); String getName(); void setName(String name); String getKeyAlias(); void setKeyAlias(String keyAlias); String getSerialNumber(); char[] getPswd(); void setSerialNumber(String serialNumber); X509Certificate getX509Cert(); void setX509Cert(X509Certificate x509Cert); PrivateKey getPrivateKey(); void setPrivateKey(PrivateKey privateKey); @Override String toString();  }### Answer:
@Test public void testSetUpMerchant() throws SignException, ConfigException{ File p12file = Mockito.mock(File.class); MerchantConfig mc = Mockito.mock(MerchantConfig.class); String keyAlias = "CN="+mc.getMerchantID()+",SERIALNUMBER=400000009910179089277"; X509Certificate x509Cert = Mockito.mock(X509Certificate.class); Principal principal = Mockito.mock(Principal.class); PrivateKey pkey = Mockito.mock(PrivateKey.class); Logger logger = Mockito.mock(Logger.class); Mockito.when(x509Cert.getSubjectDN()).thenReturn(principal); Mockito.when(principal.getName()).thenReturn(keyAlias); Mockito.when(mc.getKeyFile()).thenReturn(p12file); Mockito.when(mc.getKeyPassword()).thenReturn("testPwd"); Identity identity = new Identity(mc,x509Cert,pkey,logger); assertEquals(identity.getName(), mc.getMerchantID()); assertEquals(identity.getSerialNumber(), "400000009910179089277"); assertEquals(String.valueOf(identity.getPswd()), "testPwd"); assertNotNull(identity.getPrivateKey()); }