ConsumerTypeCurator extends AbstractHibernateCurator<ConsumerType> { public ConsumerType getConsumerType(Consumer consumer) { if (consumer == null || consumer.getTypeId() == null) { throw new IllegalArgumentException("consumer is null or does not have a defined type ID"); } ConsumerType type = this.get(consumer.getTypeId()); if (type == null) { throw new IllegalStateException("consumer is not associated with a valid type: " + consumer); } return type; } ConsumerTypeCurator(); ConsumerType getConsumerType(Consumer consumer); ConsumerType getByLabel(String label); ConsumerType getByLabel(String label, boolean createIfAbsent); @SuppressWarnings("unchecked") List<ConsumerType> getByLabels(Collection<String> labels);  }
@Test public void testGetConsumerType() { ConsumerType ctype = this.createConsumerType(); Consumer consumer = new Consumer(); consumer.setTypeId(ctype.getId()); ConsumerType test = this.consumerTypeCurator.getConsumerType(consumer); assertSame(ctype, test); }
@Test public void testGetConsumerTypeRequiresConsumer() { assertThrows(IllegalArgumentException.class, () -> consumerTypeCurator.getConsumerType(null)); }
@Test public void testGetConsumerTypeRequiresConsumerWithType() { ConsumerType ctype = this.createConsumerType(); Consumer consumer = new Consumer(); assertThrows(IllegalArgumentException.class, () -> consumerTypeCurator.getConsumerType(consumer)); }
@Test public void testGetConsumerTypeExpectsValidConsumerTypeId() { ConsumerType ctype = this.createConsumerType(); Consumer consumer = new Consumer(); consumer.setTypeId("bad-type-id"); assertThrows(IllegalStateException.class, () -> consumerTypeCurator.getConsumerType(consumer)); }