### Question:
LocalIdentity { public static LocalIdentity fromString(String str) { Matcher result = regexpPattern.matcher(str); if (!result.matches()) { return null; } return new LocalIdentity( result.group(1), result.group(2), Identity.fromPublicKey(Signature.PublicKey.fromBytes(Bytes.fromBase64String(result.group(3))))); } LocalIdentity(String ip, String port, Identity id);  LocalIdentity(String ip, int port, Identity id);  LocalIdentity(InetSocketAddress addr, Identity id); static LocalIdentity fromString(String str); String toCanonicalForm(); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString();  }### Answer:
@Test void localIdentityFromString() { Identity id = Identity.random(); LocalIdentity localId = new LocalIdentity("0.0.0.0", 45000, id); LocalIdentity fromString = LocalIdentity.fromString("net:0.0.0.0:45000~shs:" + id.publicKeyAsBase64String()); assertEquals(fromString, localId); }
@Test void malformedIdentity() { Identity id = Identity.random(); assertNull(LocalIdentity.fromString("nt:0.0.0.0:45000~shs:" + id.publicKeyAsBase64String())); assertNull(LocalIdentity.fromString("net:0.0.0.0:45000~ss:" + id.publicKeyAsBase64String())); assertNull(LocalIdentity.fromString("nt:0.0.0.0:45000~shs:" + id.publicKeyAsBase64String().substring(12))); }