UcteExporter implements Exporter { static NamingStrategy findNamingStrategy(String name, List<NamingStrategy> namingStrategies) { Objects.requireNonNull(namingStrategies); if (namingStrategies.size() == 1 && name == null) { return namingStrategies.get(0); } else { if (namingStrategies.size() > 1 && name == null) { List<String> namingStrategyNames = namingStrategies.stream().map(NamingStrategy::getName).collect(Collectors.toList()); throw new PowsyblException("Several naming strategy implementations found (" + namingStrategyNames + "), you must add properties to select the implementation"); } return namingStrategies.stream() .filter(ns -> ns.getName().equals(name)) .findFirst() .orElseThrow(() -> new PowsyblException("NamingStrategy '" + name + "' not found")); } } UcteExporter();  UcteExporter(PlatformConfig platformConfig); @Override String getFormat(); @Override String getComment(); @Override void export(Network network, Properties parameters, DataSource dataSource); static final String NAMING_STRATEGY; }
@Test public void testDefaultOneNamingStrategy() { NamingStrategy defaultNamingStrategy = UcteExporter.findNamingStrategy(null, ImmutableList.of(new DefaultNamingStrategy())); assertEquals("Default", defaultNamingStrategy.getName()); }
@Test public void testDefaultTwoNamingStrategies() { try { UcteExporter.findNamingStrategy(null, ImmutableList.of(new DefaultNamingStrategy(), new OtherNamingStrategy())); fail(); } catch (PowsyblException ignored) { } }
@Test public void testDefaultNoNamingStrategy() { try { UcteExporter.findNamingStrategy(null, ImmutableList.of()); fail(); } catch (PowsyblException ignored) { } }
@Test public void testChosenTwoNamingStrategies() { NamingStrategy namingStrategy = UcteExporter.findNamingStrategy("Default", ImmutableList.of(new DefaultNamingStrategy(), new OtherNamingStrategy())); assertEquals("Default", namingStrategy.getName()); namingStrategy = UcteExporter.findNamingStrategy("OtherNamingStrategy", ImmutableList.of(new DefaultNamingStrategy(), new OtherNamingStrategy())); assertEquals("OtherNamingStrategy", namingStrategy.getName()); }