Federation { public static FederationResponse resolve(String value) { String[] tokens = value.split("\\*"); if (tokens.length == 1) { return new FederationResponse(null, value, null, null); } else if (tokens.length == 2) { String domain = tokens[1]; FederationServer server = FederationServer.createForDomain(domain); return server.resolveAddress(value); } else { throw new MalformedAddressException(); } } private  Federation(); static FederationResponse resolve(String value);  }
@Test public void testResolveSuccess() throws IOException { Response mockResponseToml = new Response.Builder() .code(200) .message("OK") .protocol(Protocol.HTTP_1_1) .body(ResponseBody.create(MediaType.parse("application/json"), stellarToml)) .request(new Request.Builder() .url("http: .get() .build()) .build(); Response mockResponseSuccess = new Response.Builder() .code(200) .message("OK") .protocol(Protocol.HTTP_1_1) .body(ResponseBody.create(MediaType.parse("application/json"), successResponse)) .request(new Request.Builder() .url("http: .get() .build()) .build(); when(mockCall.execute()).thenReturn(mockResponseToml, mockResponseSuccess); FederationResponse response = Federation.resolve("bob*stellar.org"); assertEquals(response.getStellarAddress(), "bob*stellar.org"); assertEquals(response.getAccountId(), "GCW667JUHCOP5Y7KY6KGDHNPHFM4CS3FCBQ7QWDUALXTX3PGXLSOEALY"); assertNull(response.getMemoType()); assertNull(response.getMemo()); }
@Test public void testMalformedAddress() { try { FederationResponse response = Federation.resolve("bob*stellar.org*test"); fail("Expected exception"); } catch (MalformedAddressException e) { } }