@Test(dataProvider = "flags") public void setXAndGetConfigurationBehaveAsExpeced(List<Boolean> flags) { // builder with no template XId nodeConfigId = XId.newId(); Builder builder = NodeConfiguration.builder(nodeConfigId); for (Fragment fragment : Fragment.values()) { setConfigParameter(flags, builder, fragment); } NodeConfiguration nodeConfig = builder.newInstance(); assertThat( "", // nodeConfig.getId(), isEqualTo(nodeConfigId)); for (Fragment fragment : Fragment.values()) { testConfigsParameter(flags, nodeConfig, fragment, NodeConfiguration.DEFAULT_CONFIGURATION); } // builder with template nodeConfigId = XId.newId(); builder = NodeConfiguration.builder(nodeConfigId).setTemplate(TEMPLATE); for (Fragment fragment : Fragment.values()) { setConfigParameter(flags, builder, fragment); } nodeConfig = builder.newInstance(); assertThat( "", // nodeConfig.getId(), isEqualTo(nodeConfigId)); for (Fragment fragment : Fragment.values()) { testConfigsParameter(flags, nodeConfig, 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 DELAY: b = builder.setDelay( // (Range<Integer>) RANGES[2 * index], // (Range<Integer>) RANGES[2 * index + 1]); break; case ENERGY_DECAY: b = builder.setEnergyDecay( // (Range<Float>) RANGES[2 * index], // (Range<Float>) RANGES[2 * index + 1]); break; case ENERGY: b = builder.setEnergy( // (Range<Float>) RANGES[2 * index], // (Range<Float>) RANGES[2 * index + 1]); break; case EXCITATORY_SCALE: b = builder.setExcitatoryScale( // (Range<Float>) RANGES[2 * index], // (Range<Float>) RANGES[2 * index + 1]); break; case INHIBITORY_SCALE: b = builder.setInhibitoryScale( // (Range<Float>) RANGES[2 * index], // (Range<Float>) RANGES[2 * index + 1]); break; case DOES_INVERT: b = builder.setInvertFlag( // (Range<Boolean>) RANGES[2 * index], // (Range<Boolean>) RANGES[2 * index + 1]); break; case OSCILLATION_MAXIMUM: b = builder.setOscillationMaximum( // (Range<Float>) RANGES[2 * index], // (Range<Float>) RANGES[2 * index + 1]); break; case OSCILLATION_MINIMUM: b = builder.setOscillationMinimum( // (Range<Float>) RANGES[2 * index], // (Range<Float>) RANGES[2 * index + 1]); break; case OSCILLATION_OFFSET: b = builder.setOscillationOffset( // (Range<Integer>) RANGES[2 * index], // (Range<Integer>) RANGES[2 * index + 1]); break; case OSCILLATION_PERIOD: b = builder.setOscillationPeriod( // (Range<Integer>) RANGES[2 * index], // (Range<Integer>) RANGES[2 * index + 1]); break; case SCALE: b = builder.setScale( // (Range<Float>) RANGES[2 * index], // (Range<Float>) RANGES[2 * index + 1]); break; case SHIFT: b = builder.setShift( // (Range<Float>) RANGES[2 * index], // (Range<Float>) RANGES[2 * index + 1]); break; case TWITCH_MAXIMUM: b = builder.setTwitchMaximum( // (Range<Float>) RANGES[2 * index], // (Range<Float>) RANGES[2 * index + 1]); break; case TWITCH_MINIMUM: b = builder.setTwitchMinimum( // (Range<Float>) RANGES[2 * index], // (Range<Float>) RANGES[2 * index + 1]); break; case TWITCH_PROBABILITY: b = builder.setTwitchProbability( // (Range<Float>) RANGES[2 * index], // (Range<Float>) RANGES[2 * index + 1]); break; default: // nothing to set, just assign for post set test b = builder; break; } assertThat( "", // b, isSameAs(builder)); } }