@Test public void parse_empty_values() { Map<Integer, Double> map = KeyValueFormat.parseIntDouble("4=4.2;2=;6=6.68"); assertThat(map.size()).isEqualTo(3); assertThat(map.get(4)).isEqualTo(4.2); // key is present but value is null assertThat(map.containsKey(2)).isTrue(); assertThat(map.get(2)).isNull(); assertThat(map.get(6)).isEqualTo(6.68); }
@Test public void setXBoundWithListParam_shouldSetXBoundParams() { //when TimePlot timePlot = createWidget(); timePlot.setXBound(Arrays.asList(lowerBound, upperBound)); //then assertThat(timePlot.getXLowerBound()).isGreaterThan(0); assertThat(timePlot.getXUpperBound()).isGreaterThan(0); assertThat(timePlot.getXAutoRange()).isFalse(); }
@Test public void toDouble() { assertThat(RubyUtils.toDouble(null)).isNull(); assertThat(RubyUtils.toDouble("")).isNull(); assertThat(RubyUtils.toDouble(" ")).isNull(); assertThat(RubyUtils.toDouble("123")).isEqualTo(123.0); assertThat(RubyUtils.toDouble("3.14")).isEqualTo(3.14); assertThat(RubyUtils.toDouble(3.14)).isEqualTo(3.14); assertThat(RubyUtils.toDouble(123)).isEqualTo(123.0); assertThat(RubyUtils.toDouble(123L)).isEqualTo(123.0); }
@Test public void testTimer() throws IOException, InterruptedException { Timer t = metricRegistry.timer(name("timer").tag("foo", "bar").build()); Timer.Context time = t.time(); Thread.sleep(1L); time.stop(); // We slept for 1Ms so we ensure that all timers are above 1ms: assertThat(registry.getSampleValue("timer_seconds", new String[]{"foo", "quantile"}, new String[]{"bar", "0.99"})).isGreaterThan(1 / 1000); assertThat(registry.getSampleValue("timer_seconds_count", new String[]{"foo"}, new String[]{"bar"})).isEqualTo(1); assertThat(registry.getSampleValue("timer_seconds_sum", new String[]{"foo"}, new String[]{"bar"})).isEqualTo(-1); assertThat(registry.getSampleValue("timer_meter_m1", new String[]{"foo"}, new String[]{"bar"})).isNotNull(); assertThat(registry.getSampleValue("timer_meter_total", new String[]{"foo"}, new String[]{"bar"})).isNotNull(); assertEquals(Double.valueOf(1.0D), registry.getSampleValue("timer_seconds_count", new String[]{"foo"}, new String[]{"bar"})); assertNotNull("Metric timer_seconds_count should exist", registry.getSampleValue("timer_seconds_count", new String[]{"foo"}, new String[]{"bar"})); assertTypeHelpTimer("timer"); }
@Test public void loadProperties() { Properties p1 = PropertiesUtil.loadFromFile("classpath://application.properties"); assertThat(p1.get("springside.min")).isEqualTo("1"); assertThat(p1.get("springside.max")).isEqualTo("10"); Properties p2 = PropertiesUtil.loadFromString("springside.min=1\nspringside.max=10\nisOpen=true"); assertThat(PropertiesUtil.getInt(p2, "springside.min", 0)).isEqualTo(1); assertThat(PropertiesUtil.getInt(p2, "springside.max", 0)).isEqualTo(10); assertThat(PropertiesUtil.getInt(p2, "springside.maxA", 0)).isEqualTo(0); assertThat(PropertiesUtil.getLong(p2, "springside.min", 0L)).isEqualTo(1); assertThat(PropertiesUtil.getLong(p2, "springside.max", 0L)).isEqualTo(10); assertThat(PropertiesUtil.getLong(p2, "springside.maxA", 0L)).isEqualTo(0); assertThat(PropertiesUtil.getDouble(p2, "springside.min", 0d)).isEqualTo(1); assertThat(PropertiesUtil.getDouble(p2, "springside.max", 0d)).isEqualTo(10); assertThat(PropertiesUtil.getDouble(p2, "springside.maxA", 0d)).isEqualTo(0); assertThat(PropertiesUtil.getString(p2, "springside.min", "")).isEqualTo("1"); assertThat(PropertiesUtil.getString(p2, "springside.max", "")).isEqualTo("10"); assertThat(PropertiesUtil.getString(p2, "springside.maxA", "")).isEqualTo(""); assertThat(PropertiesUtil.getBoolean(p2, "isOpen", false)).isTrue(); }
@Test public void get_manual_metric() { db.prepareDbUnit(getClass(), "manual_metric.xml"); MetricDto result = underTest.selectByKey(dbSession, "manual"); assertThat(result.getId()).isEqualTo(1); assertThat(result.getKey()).isEqualTo("manual"); assertThat(result.getShortName()).isEqualTo("Manual metric"); assertThat(result.getDescription()).isEqualTo("Manual metric"); assertThat(result.getDomain()).isNullOrEmpty(); assertThat(result.getValueType()).isEqualTo("INT"); assertThat(result.getDirection()).isEqualTo(0); assertThat(result.isQualitative()).isFalse(); assertThat(result.isUserManaged()).isTrue(); assertThat(result.getWorstValue()).isNull(); assertThat(result.getBestValue()).isNull(); assertThat(result.isOptimizedBestValue()).isFalse(); assertThat(result.isDeleteHistoricalData()).isFalse(); assertThat(result.isHidden()).isFalse(); assertThat(result.isEnabled()).isTrue(); }
@Test public void testMessageOptions() { FooBar option_one = MessageWithOptions.MESSAGE_OPTIONS.my_message_option_one; assertThat(option_one.foo).isEqualTo(new Integer(1234)); assertThat(option_one.bar).isEqualTo("5678"); FooBar.Nested baz1 = option_one.baz; assertThat(baz1.value).isEqualTo(BAZ); assertThat(option_one.daisy).isEqualTo(456.0, Offset.offset(0.0000001)); assertThat(option_two).isEqualTo(91011.0, Offset.offset(0.0000001)); assertThat(option_three.foo).isEqualTo(new Integer(11)); assertThat(baz3.value).isEqualTo(BAR); assertThat(option_three.nested.get(0).foo).isEqualTo(new Integer(33)); assertThat(option_four).isEqualTo(FOO); assertThat(FooBar.FooBarBazEnum.FOO.foreign_enum_value_option).isNull(); assertThat(FooBar.FooBarBazEnum.BAR.enum_value_option).isNull(); assertThat(FooBar.FooBarBazEnum.BAR.foreign_enum_value_option).isTrue(); assertThat(FooBar.FooBarBazEnum.BAZ.enum_value_option).isEqualTo(new Integer(18)); assertThat(FooBar.FooBarBazEnum.BAZ.foreign_enum_value_option).isFalse();
@Test public void shouldCreateMetricWithDefaultValues() { Metric metric = new Metric.Builder("foo", "Foo", Metric.ValueType.INT) .create(); assertThat(metric.getBestValue()).isNull(); assertThat(metric.getDescription()).isNull(); assertThat(metric.getWorstValue()).isNull(); assertThat(metric.getDirection()).isEqualTo(Metric.DIRECTION_NONE); assertThat(metric.getEnabled()).isTrue(); assertThat(metric.getId()).isNull(); assertThat(metric.getUserManaged()).isFalse(); assertThat(metric.isHidden()).isFalse(); assertThat(metric.isOptimizedBestValue()).isFalse(); }
@Test public void insert() { UserDto user = db.users().insertUser(); ComponentDto project = db.components().insertPrivateProject(); MetricDto metric = db.measures().insertMetric(m -> m.setUserManaged(true)); CustomMeasureDto measure = newCustomMeasureDto() .setComponentUuid(project.uuid()) .setMetricId(metric.getId()) .setUserUuid(user.getUuid()); underTest.insert(session, measure); CustomMeasureDto result = underTest.selectById(session, measure.getId()); assertThat(result.getId()).isEqualTo(measure.getId()); assertThat(result.getMetricId()).isEqualTo(metric.getId()); assertThat(result.getComponentUuid()).isEqualTo(project.uuid()); assertThat(result.getUserUuid()).isEqualTo(user.getUuid()); assertThat(result.getDescription()).isEqualTo(measure.getDescription()); assertThat(result.getTextValue()).isEqualTo(measure.getTextValue()); assertThat(result.getValue()).isCloseTo(measure.getValue(), offset(0.001d)); assertThat(result.getCreatedAt()).isEqualTo(measure.getCreatedAt()); assertThat(result.getUpdatedAt()).isEqualTo(measure.getUpdatedAt()); }
private static void verifySetVariationValue(DoubleValue variationValue, double expected) { assertThat(variationValue.isSet()).isTrue(); assertThat(variationValue.getValue()).isEqualTo(expected); } }
@Test public void set_long_value() { underTest.setMeasureValue(customMeasure, "123456789", newMetricDto().setValueType(WORK_DUR.name())); assertThat(customMeasure.getValue()).isCloseTo(123456789d, defaultOffset()); }
operator.addInput(rowPagesBuilder(inputTypes).row(null, null, 7).build().get(0)); assertThat(driverContext.getSystemMemoryUsage()).isGreaterThan(0); assertEquals(driverContext.getMemoryUsage(), 0); assertThat(tableFinishInfo.getStatisticsWallTime().getValue(NANOSECONDS)).isGreaterThan(0); assertThat(tableFinishInfo.getStatisticsCpuTime().getValue(NANOSECONDS)).isGreaterThan(0);
@Test public void toMeasureDto_maps_value_and_data_from_data_field_for_LONG_metric() { MeasureDto trueMeasureDto = underTest.toMeasureDto(Measure.newMeasureBuilder().create((long) 456, SOME_DATA), SOME_LONG_METRIC, SOME_COMPONENT); assertThat(trueMeasureDto.getValue()).isEqualTo(456); assertThat(trueMeasureDto.getData()).isEqualTo(SOME_DATA); }
@Test public void toMeasureDto_maps_to_only_data_for_STRING_metric() { MeasureDto trueMeasureDto = underTest.toMeasureDto(Measure.newMeasureBuilder().create(SOME_STRING), SOME_STRING_METRIC, SOME_COMPONENT); assertThat(trueMeasureDto.getValue()).isNull(); assertThat(trueMeasureDto.getData()).isEqualTo(SOME_STRING); }
@Test public void not_set_gap_to_fix_if_unchanged() { issue.setGap(3.14); boolean updated = underTest.setGap(issue, 3.14, context); assertThat(updated).isFalse(); assertThat(issue.isChanged()).isFalse(); assertThat(issue.gap()).isEqualTo(3.14); assertThat(issue.mustSendNotifications()).isFalse(); }
private void assertVariation(Component component, String metricKey, int variation) { Measure newMeasure = measureRepository.getRawMeasure(component, metricRepository.getByKey(metricKey)).get(); assertThat(newMeasure.getVariation()).isEqualTo(variation); assertThat(newMeasure.getValueType()).isEqualTo(Measure.ValueType.NO_VALUE); }
@Test(dataProvider = "conversions") public void testConvertToMostSuccinctDuration(TimeUnit unit, TimeUnit toTimeUnit, double factor) { Duration duration = new Duration(factor, toTimeUnit); Duration actual = duration.convertToMostSuccinctTimeUnit(); assertThat(actual.getValue(toTimeUnit)).isCloseTo(factor, withPercentage(0.1)); assertThat(actual.getValue(unit)).isCloseTo(1.0, offset(0.001)); assertThat(actual.getUnit()).isEqualTo(unit); }
private void assertDroppableTombstoneRatioPositive(String sstableMetadata) { Pattern pattern = Pattern.compile("Estimated droppable tombstones: ([0-9]*\\.[0-9]*)"); Matcher droppableTombstoneRatioMatcher = pattern.matcher(sstableMetadata); assertThat(droppableTombstoneRatioMatcher.find()) .as("SSTableMetadata output contains the droppable tombstone ratio") .isTrue(); assertThat(Double.parseDouble(droppableTombstoneRatioMatcher.group(1))).isGreaterThan(0); } }
@Test public void test_nullable_fields() { issue.setGap(null).setSeverity(null).setLine(null); assertThat(issue.gap()).isNull(); assertThat(issue.severity()).isNull(); assertThat(issue.line()).isNull(); }
@Test public void test_getter_and_setter() { underTest .setValue(2d) .setData("text value") .setVariation(1d); assertThat(underTest.getValue()).isEqualTo(2d); assertThat(underTest.getData()).isNotNull(); assertThat(underTest.getVariation()).isEqualTo(1d); }