Peer implements Serializable { void setChannel(Channel channel) throws InvalidArgumentException { if (null != this.channel) { throw new InvalidArgumentException(format("Can not add peer %s to channel %s because it already belongs to channel %s.", name, channel.getName(), this.channel.getName())); } this.channel = channel; channelName = channel.getName(); } Peer(String name, String grpcURL, Properties properties); String getName(); Properties getProperties(); String getUrl(); @Override boolean equals(Object otherPeer); @Override int hashCode(); @Override String toString();  }
@Test public void testDuplicateChannel() throws InvalidArgumentException { thrown.expect(InvalidArgumentException.class); thrown.expectMessage("Can not add peer " + PEER_NAME + " to channel duplicate because it already belongs to channel duplicate."); Channel duplicate = hfclient.newChannel("duplicate"); peer.setChannel(duplicate); peer.setChannel(duplicate); }