ThingHelper { public static void addChannelsToThing(Thing thing, Collection<Channel> channels) { Collection<Channel> mutableChannels = thing.getChannels(); ensureUniqueChannels(mutableChannels, channels); for (Channel channel : channels) { ((ThingImpl) thing).addChannel(channel); } }  static boolean equals(Thing a, Thing b); static void addChannelsToThing(Thing thing, Collection<Channel> channels); static void ensureUniqueChannels(final Channel[] channels); static void ensureUniqueChannels(final Collection<Channel> channels); static void ensureUniqueChannels(final Collection<Channel> channels, final Channel channel); static Thing merge(Thing thing, ThingDTO updatedContents);  }
@Test public void assertThatNoDuplicateChannelsCanBeAdded() { ThingTypeUID thingTypeUID = new ThingTypeUID("test", "test"); ThingUID thingUID = new ThingUID(thingTypeUID, "test"); Thing thing = ThingBuilder.create(thingTypeUID, thingUID) .withChannels(ChannelBuilder.create(new ChannelUID(thingUID, "channel1"), "").build(), ChannelBuilder.create(new ChannelUID(thingUID, "channel2"), "").build()) .build(); assertThrows(IllegalArgumentException.class, () -> ThingHelper.addChannelsToThing(thing, Stream.of(ChannelBuilder.create(new ChannelUID(thingUID, "channel2"), "").build(), ChannelBuilder.create(new ChannelUID(thingUID, "channel3"), "").build()) .collect(toList()))); }