本文整理汇总了Java中org.assertj.core.data.Percentage类的典型用法代码示例。如果您正苦于以下问题:Java Percentage类的具体用法?Java Percentage怎么用?Java Percentage使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Percentage类属于org.assertj.core.data包,在下文中一共展示了Percentage类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: extractFieldsTest
import org.assertj.core.data.Percentage; //导入依赖的package包/类
@Test
public void extractFieldsTest() {
String event = "{\"meta\":{\"name\":\"OneVehicleDynamicData\",\"timestamp\":" +
"\"2017-02-14T10:20:37.629Z\",\"grouping\":\"OneVehicleFinderData\"," +
"\"distribution_key\":\"665292e8-6a3b-4702-9666-b5624d6c8320\"},\"position\":{" +
"\"latitude\":48.042999267578125,\"longitude\":11.510173797607422,\"foo\":7}," +
"\"vehicle_id\":\"abcd\",\"fuel_level\":999," +
"\"charge_level\":50.0,\"odometer\":12345}";
JsonObject json = (JsonObject) new JsonParser().parse(event);
assertThat(jsonUtil.extractInteger(json, "odometer", -1)).isEqualTo(12345);
assertThat(jsonUtil.extractDouble(json, "charge_level", -1))
.isCloseTo(50, Percentage.withPercentage(1));
assertThat(jsonUtil.extractString(json, "vehicle_id")).isEqualTo("abcd");
//check dot-notation paths
assertThat(jsonUtil.extractInteger(json, "position.foo", -1)).isEqualTo(7);
assertThat(jsonUtil.extractDouble(json, "position.latitude", 0))
.isCloseTo(48.043, Percentage.withPercentage(1));
assertThat(jsonUtil.extractString(json, "meta.name")).isEqualTo("OneVehicleDynamicData");
}
示例2: testProxy
import org.assertj.core.data.Percentage; //导入依赖的package包/类
@Test
public void testProxy() {
System.setProperty("test1", "prop1");
assertThat(System2.INSTANCE.envVariables()).isEqualTo(System.getenv());
assertThat(System2.INSTANCE.property("test1")).isEqualTo("prop1");
assertThat(System2.INSTANCE.getProperty("test1")).isEqualTo("prop1");
assertThat(System2.INSTANCE.properties()).isEqualTo(System.getProperties());
Entry<String, String> envVar = System.getenv().entrySet().iterator().next();
assertThat(System2.INSTANCE.envVariable(envVar.getKey())).isEqualTo(envVar.getValue());
assertThat(System2.INSTANCE.getenv(envVar.getKey())).isEqualTo(envVar.getValue());
assertThat(System2.INSTANCE.now()).isCloseTo(System.currentTimeMillis(), Percentage.withPercentage(0.01));
}
示例3: testWrapCodeBlockWithNoExceptionCaught
import org.assertj.core.data.Percentage; //导入依赖的package包/类
/**
* Testing that our meter is not marked when we call {@code wrapException()}
* and no exception was thrown.
*/
@Test
public void testWrapCodeBlockWithNoExceptionCaught() {
final Meter meter = this.circuitBreaker.getMeter(METER_NAME);
// It's a brand new Meter, everything should be zero.
assertThat(meter).isNotNull();
assertThat(meter.getCount()).isEqualTo(0L);
assertThat(meter.getMeanRate()).isCloseTo(0.0, Percentage.withPercentage(0.00001));
try {
this.circuitBreaker.wrapCodeBlock(METER_NAME, (currentMeter) -> {
});
} catch (final Exception e) {
}
// At this point our meter count should be 0 as we didn't have any
// exception under it and the rate should still be close to zero.
assertThat(meter.getCount()).isEqualTo(0L);
assertThat(meter.getMeanRate()).isCloseTo(0.0, Percentage.withPercentage(0.00001));
assertThat(this.circuitBreaker.isCircuitOpen(METER_NAME)).isFalse();
}
示例4: testWrapCodeBlockWithExceptionCaught
import org.assertj.core.data.Percentage; //导入依赖的package包/类
/**
* Testing that when an exception is thrown within {@code wrapException()}
* our meter is increased.
*/
@Test
public void testWrapCodeBlockWithExceptionCaught() {
final Meter meter = this.circuitBreaker.getMeter(METER_NAME);
assertThat(meter.getCount()).isEqualTo(0L);
assertThat(meter.getMeanRate()).isCloseTo(0.0, Percentage.withPercentage(0.00001));
try {
this.circuitBreaker.wrapCodeBlock(METER_NAME, (currentMeter) -> {
throw new OperationException();
});
} catch (final Exception e) {
}
assertThat(meter.getCount()).isEqualTo(1L);
assertThat(meter.getMeanRate()).isGreaterThan(0.0);
assertThat(this.circuitBreaker.isCircuitOpen("test.name")).isFalse();
}
示例5: testWrapCodeBlockWithExceptionCaughtCauseOpenCircuit
import org.assertj.core.data.Percentage; //导入依赖的package包/类
/**
* Testing that after several exceptions our circuit gets opened.
*/
@Test
public void testWrapCodeBlockWithExceptionCaughtCauseOpenCircuit() {
final Meter meter = this.circuitBreaker.getMeter(METER_NAME);
assertThat(meter.getCount()).isEqualTo(0L);
assertThat(meter.getMeanRate()).isCloseTo(0.0, Percentage.withPercentage(0.00001));
for (int i = 0; i < 10; i++) {
try {
this.circuitBreaker.wrapCodeBlock(METER_NAME, (currentMeter) -> {
throw new OperationException();
});
} catch (final Exception e) {
}
}
assertThat(meter.getCount()).isEqualTo(10L);
assertThat(meter.getMeanRate()).isGreaterThan(DEFAULT_THRESHOLD);
assertThat(this.circuitBreaker.isCircuitOpen(METER_NAME)).isTrue();
}
示例6: testWrapCodeBlockWithCircuitBreakerWithoutExceptions
import org.assertj.core.data.Percentage; //导入依赖的package包/类
/**
* Testing that when we call {@code wrapCodeBlockWithCircuitBreaker()} it
* gets executed.
*
* @throws Exception
*/
@Test
public void testWrapCodeBlockWithCircuitBreakerWithoutExceptions() throws Exception {
final Meter meter = this.circuitBreaker.getMeter(METER_NAME);
assertThat(meter.getCount()).isEqualTo(0L);
assertThat(meter.getMeanRate()).isCloseTo(0.0, Percentage.withPercentage(0.00001));
final AtomicBoolean executed = new AtomicBoolean(false);
this.circuitBreaker.wrapCodeBlockWithCircuitBreaker(METER_NAME, (currentMeter) -> {
executed.set(true);
});
assertThat(meter.getCount()).isEqualTo(0L);
assertThat(meter.getMeanRate()).isLessThan(DEFAULT_THRESHOLD);
assertThat(this.circuitBreaker.isCircuitOpen(METER_NAME)).isFalse();
assertThat(executed.get()).isTrue();
}
示例7: testWrapCodeBlockWithCircuitBreakerWithExceptions
import org.assertj.core.data.Percentage; //导入依赖的package包/类
/**
* Testing that after our circuit breaker gets opened, if we try call
* {@code wrapCodeBlockWithCircuitBreaker()} it will throw a
* {@link CircuitBreakerOpenedException}.
*
* @throws CircuitBreakerOpenedException
* @throws Exception
*/
@Test
public void testWrapCodeBlockWithCircuitBreakerWithExceptions()
throws CircuitBreakerOpenedException, Exception {
final Meter meter = this.circuitBreaker.getMeter(METER_NAME);
assertThat(meter.getCount()).isEqualTo(0L);
assertThat(meter.getMeanRate()).isCloseTo(0.0, Percentage.withPercentage(0.00001));
for (int i = 0; i < 2; i++) {
try {
this.circuitBreaker.wrapCodeBlockWithCircuitBreaker(METER_NAME, (currentMeter) -> {
throw new OperationException();
});
} catch (final Exception e) {
}
}
assertThat(meter.getCount()).isBetween(1L, 2L);
assertThat(meter.getMeanRate()).isGreaterThan(DEFAULT_THRESHOLD);
assertThat(this.circuitBreaker.isCircuitOpen(METER_NAME)).isTrue();
this.expectedException.expect(CircuitBreakerOpenedException.class);
this.expectedException.expectMessage("Circuit breaker is currently opened: " + METER_NAME);
this.circuitBreaker.wrapCodeBlockWithCircuitBreaker(METER_NAME, (currentMeter) -> {
});
}
示例8: testTimeWindow
import org.assertj.core.data.Percentage; //导入依赖的package包/类
@Test
public void testTimeWindow() {
TimeWindowAverage avg = new TimeWindowAverage(Duration.ofDays(999), MIN_COUNT_0);
avg.addData(1);
avg.addData(10);
avg.addData(0);
avg.addData(0);
assertThat(avg.getAverage()).isCloseTo(11.0 / 4.0, Percentage.withPercentage(0.00001));
}
示例9: ppmt
import org.assertj.core.data.Percentage; //导入依赖的package包/类
@Test
public void ppmt() {
final BigDecimal rate = new BigDecimal("0.1");
final BigDecimal principal = BigDecimal.valueOf(100);
final int maxTerm = 10;
final BigDecimal result = IntStream.range(0, maxTerm)
.mapToObj(term -> FinancialUtil.ppmt(rate, term + 1, maxTerm, principal))
.reduce(BigDecimal.ZERO, BigDecimalCalculator::plus);
Assertions.assertThat(result).isCloseTo(principal.negate(), Percentage.withPercentage(0.01));
}
示例10: pmt
import org.assertj.core.data.Percentage; //导入依赖的package包/类
@Test
public void pmt() {
final BigDecimal rate = new BigDecimal("0.1");
final BigDecimal principal = BigDecimal.valueOf(100);
final int maxTerm = 10;
final BigDecimal result = IntStream.range(0, maxTerm)
.mapToObj(term -> FinancialUtil.pmt(rate, maxTerm, principal))
.reduce(BigDecimal.ZERO, BigDecimalCalculator::plus);
Assertions.assertThat(result).isCloseTo(BigDecimal.valueOf(-162), Percentage.withPercentage(0.5));
}
示例11: measureAndAssert
import org.assertj.core.data.Percentage; //导入依赖的package包/类
public static void measureAndAssert(int nRuns, float expectedFactor, float allowedVariation) {
long duration = System.currentTimeMillis() - currentMark;
// System.out.println(duration);
float perRun = (duration / (float) nRuns);
log.info("Average time per run: {" + perRun + "} ms");
// System.out.println(perRun);
float factor = perRun / computeBaseline();
assertThat(expectedFactor).isCloseTo(factor, Percentage.withPercentage(allowedVariation));
// System.out.println(factor);
}
示例12: testWrapCodeBlockWithExceptionCaughtCauseOpenCircuitAndClosesAfterSomeTime
import org.assertj.core.data.Percentage; //导入依赖的package包/类
/**
* Testing that after getting our circuit open, if we wait 1 second we
* should get our circuit closed again.
*
* @throws InterruptedException
*/
@Test
public void testWrapCodeBlockWithExceptionCaughtCauseOpenCircuitAndClosesAfterSomeTime()
throws InterruptedException {
final Meter meter = this.circuitBreaker.getMeter(METER_NAME);
assertThat(meter.getCount()).isEqualTo(0L);
assertThat(meter.getMeanRate()).isCloseTo(0.0, Percentage.withPercentage(0.00001));
for (int i = 0; i < 2; i++) {
try {
this.circuitBreaker.wrapCodeBlock(METER_NAME, (currentMeter) -> {
throw new OperationException();
});
} catch (final Exception e) {
}
}
assertThat(meter.getCount()).isEqualTo(2L);
assertThat(meter.getMeanRate()).isGreaterThan(DEFAULT_THRESHOLD);
assertThat(this.circuitBreaker.isCircuitOpen(METER_NAME)).isTrue();
// Unfortunately we need to wait 1 seconds until the threshold gets
// decreased below the threshold.
Thread.sleep(1000L);
assertThat(meter.getCount()).isEqualTo(2L);
assertThat(meter.getMeanRate()).isLessThan(DEFAULT_THRESHOLD);
assertThat(this.circuitBreaker.isCircuitOpen(METER_NAME)).isFalse();
}
示例13: ShouldNotBeEqualWithinPercentage
import org.assertj.core.data.Percentage; //导入依赖的package包/类
private <T extends Number> ShouldNotBeEqualWithinPercentage(Number actual, Number expected, Percentage percentage,
double expectedPercentage) {
super("%nExpecting:%n" +
" <%s>%n" +
"not to be close to:%n" +
" <%s>%n" +
"by more than %s but difference was %s%%.%n" +
"(a difference of exactly %s being considered incorrect)",
actual, expected, percentage, expectedPercentage, percentage);
}
示例14: ShouldBeEqualWithinPercentage
import org.assertj.core.data.Percentage; //导入依赖的package包/类
private <T extends Number> ShouldBeEqualWithinPercentage(Number actual, Number expected, Percentage percentage,
double expectedPercentage) {
super("%nExpecting:%n" +
" <%s>%n" +
"to be close to:%n" +
" <%s>%n" +
"by less than %s but difference was %s%%.%n" +
"(a difference of exactly %s being considered valid)",
actual, expected, percentage, expectedPercentage, percentage);
}
示例15: assertIsCloseToPercentage
import org.assertj.core.data.Percentage; //导入依赖的package包/类
/**
* Asserts that the actual value is close to the an offset expressed as an percentage value.
*
* @param info contains information about the assertion.
* @param actual the actual value.
* @param other the expected value.
* @param percentage the given positive percentage.
*/
public void assertIsCloseToPercentage(final AssertionInfo info, final NUMBER actual, final NUMBER other,
final Percentage percentage) {
assertNotNull(info, actual);
checkPercentageIsNotNull(percentage);
checkNumberIsNotNull(other);
if (areEqual(actual, other)) return;
double acceptableDiff = abs(percentage.value * other.doubleValue() / 100d);
double actualDiff = absDiff(actual, other).doubleValue();
if (actualDiff > acceptableDiff || Double.isNaN(actualDiff) || Double.isInfinite(actualDiff))
throw failures.failure(info, shouldBeEqualWithinPercentage(actual, other, percentage, absDiff(actual, other)));
}