@Test(expectedExceptions = { IllegalArgumentException.class }) public void testIllegalInitParameterMinimum() { final ModifierProperties modifierProperties = new ModifierProperties(); modifierProperties.put("minimum", -1); modifierProperties.put("maximum", 3000); modifierProperties.put("minimumStep", 1); modifierProperties.put("maximumStep", 10); final Gauge32Modifier modifier = new Gauge32Modifier(); modifier.init(modifierProperties); }
@Override public void init(final ModifierProperties properties) { this.minimum = Optional.ofNullable(properties.getLong("minimum")).orElse(0L); this.maximum = Optional.ofNullable(properties.getLong("maximum")).orElse(UnsignedInteger.MAX_VALUE.longValue()); this.minimumStep = Optional.ofNullable(properties.getLong("minimumStep")).orElse(0L); this.maximumStep = Optional.ofNullable(properties.getLong("maximumStep")).orElse(1L); Preconditions.checkArgument(minimum >= 0, "minimum should not be negative"); Preconditions.checkArgument(maximum >= 0, "maximum should not be negative"); Preconditions.checkArgument(minimum <= UnsignedInteger.MAX_VALUE.longValue(), "minimum should not exceed 2^32-1 (4294967295 decimal)"); Preconditions.checkArgument(maximum <= UnsignedInteger.MAX_VALUE.longValue(), "maximum should not exceed 2^32-1 (4294967295 decimal)"); }
AbstractIntegerModifier implements VariableModifier<T> { @Override public void init(final ModifierProperties properties) { this.minimum = Optional.ofNullable(properties.getLong("minimum")).orElse(0L); this.maximum = Optional.ofNullable(properties.getLong("maximum")).orElse(UnsignedInteger.MAX_VALUE.longValue()); this.minimumStep = Optional.ofNullable(properties.getLong("minimumStep")).orElse(0L); this.maximumStep = Optional.ofNullable(properties.getLong("maximumStep")).orElse(1L); Preconditions.checkArgument(minimum >= 0, "minimum should not be negative"); Preconditions.checkArgument(maximum >= 0, "maximum should not be negative"); Preconditions.checkArgument(minimum <= UnsignedInteger.MAX_VALUE.longValue(), "minimum should not exceed 2^32-1 (4294967295 decimal)"); Preconditions.checkArgument(maximum <= UnsignedInteger.MAX_VALUE.longValue(), "maximum should not exceed 2^32-1 (4294967295 decimal)"); } }
AbstractIntegerModifier implements VariableModifier<T> { @Override public void init(final ModifierProperties properties) { this.minimum = Optional.ofNullable(properties.getLong("minimum")).orElse(0L); this.maximum = Optional.ofNullable(properties.getLong("maximum")).orElse(UnsignedInteger.MAX_VALUE.longValue()); this.minimumStep = Optional.ofNullable(properties.getLong("minimumStep")).orElse(0L); this.maximumStep = Optional.ofNullable(properties.getLong("maximumStep")).orElse(1L); Preconditions.checkArgument(minimum >= 0, "minimum should not be negative"); Preconditions.checkArgument(maximum >= 0, "maximum should not be negative"); Preconditions.checkArgument(minimum <= UnsignedInteger.MAX_VALUE.longValue(), "minimum should not exceed 2^32-1 (4294967295 decimal)"); Preconditions.checkArgument(maximum <= UnsignedInteger.MAX_VALUE.longValue(), "maximum should not exceed 2^32-1 (4294967295 decimal)"); }  }
AbstractIntegerModifier implements VariableModifier<T> { @Override public void init(final ModifierProperties properties) { this.minimum = Optional.ofNullable(properties.getLong("minimum")).orElse(0L); this.maximum = Optional.ofNullable(properties.getLong("maximum")).orElse(UnsignedInteger.MAX_VALUE.longValue()); this.minimumStep = Optional.ofNullable(properties.getLong("minimumStep")).orElse(0L); this.maximumStep = Optional.ofNullable(properties.getLong("maximumStep")).orElse(1L); Preconditions.checkArgument(minimum >= 0, "minimum should not be negative"); Preconditions.checkArgument(maximum >= 0, "maximum should not be negative"); Preconditions.checkArgument(minimum <= UnsignedInteger.MAX_VALUE.longValue(), "minimum should not exceed 2^32-1 (4294967295 decimal)"); Preconditions.checkArgument(maximum <= UnsignedInteger.MAX_VALUE.longValue(), "maximum should not exceed 2^32-1 (4294967295 decimal)"); }  @Override void init(final ModifierProperties properties); @Override final T modify(final T variable); }
AbstractIntegerModifier implements VariableModifier<T> { @Override public void init(final ModifierProperties properties) { this.minimum = Optional.ofNullable(properties.getLong("minimum")).orElse(0L); this.maximum = Optional.ofNullable(properties.getLong("maximum")).orElse(UnsignedInteger.MAX_VALUE.longValue()); this.minimumStep = Optional.ofNullable(properties.getLong("minimumStep")).orElse(0L); this.maximumStep = Optional.ofNullable(properties.getLong("maximumStep")).orElse(1L); Preconditions.checkArgument(minimum >= 0, "minimum should not be negative"); Preconditions.checkArgument(maximum >= 0, "maximum should not be negative"); Preconditions.checkArgument(minimum <= UnsignedInteger.MAX_VALUE.longValue(), "minimum should not exceed 2^32-1 (4294967295 decimal)"); Preconditions.checkArgument(maximum <= UnsignedInteger.MAX_VALUE.longValue(), "maximum should not exceed 2^32-1 (4294967295 decimal)"); }  @Override void init(final ModifierProperties properties); @Override final T modify(final T variable);  }