@Test public void discover() { ServerConnection connection = ServerConnection.getInstance(); Whitebox.setInternalState(connection, "connectionsClient", mockClient); assertNotEquals(null, Whitebox.getInternalState(connection, "connectionsClient")); ConnectCallback callback = new ConnectCallback() { @Override public void success(String message) { } @Override public void failure(String message) { } }; connection.discover(callback, connection.buildEndpointDiscoveryCallback("", callback)); List<String> expected = Arrays.asList("endName", "endName2", "endNameD1"); assertEquals(expected, connection.getClients()); }
public void discover(ConnectCallback callback, EndpointDiscoveryCallback discoveryCallback) { if (connectionsClient == null) { Log.e(TAG, "connectionsClient is null, cannot discover."); return; } resetDiscovery(); DiscoveryOptions discoveryOptions = new DiscoveryOptions.Builder().setStrategy(STRATEGY).build(); connectionsClient.startDiscovery("com.amos.server", discoveryCallback, discoveryOptions) .addOnSuccessListener((Void unused) -> Log.e(TAG, "Success discover")) .addOnFailureListener((Exception e) -> { Log.e(TAG, "Failed to discover"); callback.failure("Failed to discover"); }); }
ServerConnection implements PayloadHandling { public void discover(ConnectCallback callback, EndpointDiscoveryCallback discoveryCallback) { if (connectionsClient == null) { Log.e(TAG, "connectionsClient is null, cannot discover."); return; } resetDiscovery(); DiscoveryOptions discoveryOptions = new DiscoveryOptions.Builder().setStrategy(STRATEGY).build(); connectionsClient.startDiscovery("com.amos.server", discoveryCallback, discoveryOptions) .addOnSuccessListener((Void unused) -> Log.e(TAG, "Success discover")) .addOnFailureListener((Exception e) -> { Log.e(TAG, "Failed to discover"); callback.failure("Failed to discover"); }); } }
ServerConnection implements PayloadHandling { public void discover(ConnectCallback callback, EndpointDiscoveryCallback discoveryCallback) { if (connectionsClient == null) { Log.e(TAG, "connectionsClient is null, cannot discover."); return; } resetDiscovery(); DiscoveryOptions discoveryOptions = new DiscoveryOptions.Builder().setStrategy(STRATEGY).build(); connectionsClient.startDiscovery("com.amos.server", discoveryCallback, discoveryOptions) .addOnSuccessListener((Void unused) -> Log.e(TAG, "Success discover")) .addOnFailureListener((Exception e) -> { Log.e(TAG, "Failed to discover"); callback.failure("Failed to discover"); }); } private  ServerConnection(); }
ServerConnection implements PayloadHandling { public void discover(ConnectCallback callback, EndpointDiscoveryCallback discoveryCallback) { if (connectionsClient == null) { Log.e(TAG, "connectionsClient is null, cannot discover."); return; } resetDiscovery(); DiscoveryOptions discoveryOptions = new DiscoveryOptions.Builder().setStrategy(STRATEGY).build(); connectionsClient.startDiscovery("com.amos.server", discoveryCallback, discoveryOptions) .addOnSuccessListener((Void unused) -> Log.e(TAG, "Success discover")) .addOnFailureListener((Exception e) -> { Log.e(TAG, "Failed to discover"); callback.failure("Failed to discover"); }); } private  ServerConnection(); static ServerConnection getInstance(); void init(Context ctx); @Override void addHandle(int type, HandlePayload handle); @Override HandlePayload getHandle(int type); @Override void handlePayload(Payload payload); @Override void handlePayloadUpdate(PayloadTransferUpdate update); void discover(ConnectCallback callback, EndpointDiscoveryCallback discoveryCallback); List<String> getClients(); String getClientID(); void discoverConnect(String code, ConnectCallback callback); void connectTo(String code, ConnectCallback callback); void abort(); PipedOutputStream sendStream(); EndpointDiscoveryCallback buildEndpointDiscoveryCallback(String name, ConnectCallback callback); boolean isConnected(); }
ServerConnection implements PayloadHandling { public void discover(ConnectCallback callback, EndpointDiscoveryCallback discoveryCallback) { if (connectionsClient == null) { Log.e(TAG, "connectionsClient is null, cannot discover."); return; } resetDiscovery(); DiscoveryOptions discoveryOptions = new DiscoveryOptions.Builder().setStrategy(STRATEGY).build(); connectionsClient.startDiscovery("com.amos.server", discoveryCallback, discoveryOptions) .addOnSuccessListener((Void unused) -> Log.e(TAG, "Success discover")) .addOnFailureListener((Exception e) -> { Log.e(TAG, "Failed to discover"); callback.failure("Failed to discover"); }); } private  ServerConnection(); static ServerConnection getInstance(); void init(Context ctx); @Override void addHandle(int type, HandlePayload handle); @Override HandlePayload getHandle(int type); @Override void handlePayload(Payload payload); @Override void handlePayloadUpdate(PayloadTransferUpdate update); void discover(ConnectCallback callback, EndpointDiscoveryCallback discoveryCallback); List<String> getClients(); String getClientID(); void discoverConnect(String code, ConnectCallback callback); void connectTo(String code, ConnectCallback callback); void abort(); PipedOutputStream sendStream(); EndpointDiscoveryCallback buildEndpointDiscoveryCallback(String name, ConnectCallback callback); boolean isConnected();  }