MetadataAggregatorFactory { public static MetadataAggregator create(String name) { if (NAME.equalsIgnoreCase(name)) { return new ProductNameMetaAggregator(); } else if (FIRST_HISTORY.equalsIgnoreCase(name)) { return new FirstHistoryMetaAggregator(); } else if (ALL_HISTORIES.equalsIgnoreCase(name)) { return new AllHistoriesMetaAggregator(); } throw new IllegalArgumentException("Unknown metadata aggregator name: " + name); }  static MetadataAggregator create(String name);  }
@Test public void testCreate() { MetadataAggregator aggregator = MetadataAggregatorFactory.create("NAME"); assertNotNull(aggregator); assertTrue(aggregator instanceof ProductNameMetaAggregator); aggregator = MetadataAggregatorFactory.create("FIRST_HISTORY"); assertNotNull(aggregator); assertTrue(aggregator instanceof FirstHistoryMetaAggregator); aggregator = MetadataAggregatorFactory.create("ALL_HISTORIES"); assertNotNull(aggregator); assertTrue(aggregator instanceof AllHistoriesMetaAggregator); }
@SuppressWarnings("EmptyCatchBlock") @Test public void testCreate_invalidName() { try { MetadataAggregatorFactory.create("blanker Unsinn"); fail("IllegalArgumentException expected"); } catch(IllegalArgumentException expected) { } }