@Test(dataProvider = "flags") public void setXAndGetConfigurationBehaveAsExpeced(List<Boolean> flags) { // builder with no template XId linkConfigId = XId.newId(); Builder builder = LinkConfiguration.builder(linkConfigId); for (Fragment fragment : Fragment.values()) { setConfigParameter(flags, builder, fragment); } LinkConfiguration linkConfig = builder.newInstance(); assertThat( "", // linkConfig.getId(), isEqualTo(linkConfigId)); for (Fragment fragment : Fragment.values()) { testConfigsParameter(flags, linkConfig, fragment, LinkConfiguration.DEFAULT_CONFIGURATION); } // builder with template linkConfigId = XId.newId(); builder = LinkConfiguration.builder(linkConfigId).setTemplate(TEMPLATE); for (Fragment fragment : Fragment.values()) { setConfigParameter(flags, builder, fragment); } linkConfig = builder.newInstance(); assertThat( "", // linkConfig.getId(), isEqualTo(linkConfigId)); for (Fragment fragment : Fragment.values()) { testConfigsParameter(flags, linkConfig, fragment, TEMPLATE); } }
@SuppressWarnings("unchecked") private void setConfigParameter(List<Boolean> flags, Builder builder, Fragment fragment) { int index = fragment.ordinal(); if (flags.get(index)) { Builder b = null; switch (fragment) { case CAPACITY: b = builder.setCapacity( // (Range<Float>) RANGES[2 * index], // (Range<Float>) RANGES[2 * index + 1]); break; case CAPACITY_ATTACK: b = builder.setCapacityAttack( // (Range<Float>) RANGES[2 * index], // (Range<Float>) RANGES[2 * index + 1]); break; case CAPACITY_DECAY: b = builder.setCapacityDecay( // (Range<Float>) RANGES[2 * index], // (Range<Float>) RANGES[2 * index + 1]); break; case STRENGTH: b = builder.setStrength( // (Range<Float>) RANGES[2 * index], // (Range<Float>) RANGES[2 * index + 1]); break; case STRENGTH_ATTACK: b = builder.setStrengthAttack( // (Range<Float>) RANGES[2 * index], // (Range<Float>) RANGES[2 * index + 1]); break; case STRENGTH_DECAY: b = builder.setStrengthDecay( // (Range<Float>) RANGES[2 * index], // (Range<Float>) RANGES[2 * index + 1]); break; case IS_INHIBITORY: b = builder.setInhibitoryFlag( // (Range<Boolean>) RANGES[2 * index], // (Range<Boolean>) RANGES[2 * index + 1]); break; default: // nothing to set, just assign for post set test b = builder; break; } assertThat( "", // b, isSameAs(builder)); } }