Orderer implements Serializable { void setChannel(Channel channel) throws InvalidArgumentException { if (channel == null) { throw new InvalidArgumentException("setChannel Channel can not be null"); } if (null != this.channel && this.channel != channel) { throw new InvalidArgumentException(format("Can not add orderer %s to channel %s because it already belongs to channel %s.", name, channel.getName(), this.channel.getName())); } this.channel = channel; } Orderer(String name, String url, Properties properties); Properties getProperties(); String getName(); String getUrl();  }
@Test public void testSetDuplicateChannnel() throws InvalidArgumentException { thrown.expect(InvalidArgumentException.class); thrown.expectMessage("Can not add orderer " + ORDERER_NAME + " to channel channel2 because it already belongs to channel " + DEFAULT_CHANNEL_NAME + "."); Channel channel2 = hfclient.newChannel("channel2"); orderer.setChannel(channel2); orderer.setChannel(channel2); }
@Test public void testSetNullChannel() throws InvalidArgumentException { thrown.expect(InvalidArgumentException.class); thrown.expectMessage("setChannel Channel can not be null"); orderer.setChannel(null); }
@Test public void testSetChannel() { try { Channel channel = hfclient.newChannel(DEFAULT_CHANNEL_NAME); orderer.setChannel(channel); Assert.assertTrue(channel == orderer.getChannel()); } catch (Exception e) { Assert.fail("Unexpected Exception " + e.getMessage()); } }