org.assertj.core.api.Assertions.within()方法的使用及代码示例

x33g5p2x  于2022-01-15 转载在 其他  
字(12.3k)|赞(0)|评价(0)|浏览(132)

本文整理了Java中org.assertj.core.api.Assertions.within()方法的一些代码示例,展示了Assertions.within()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Assertions.within()方法的具体详情如下:
包路径:org.assertj.core.api.Assertions
类名称:Assertions
方法名:within

Assertions.within介绍

[英]Assertions entry point for TemporalUnitOffset with with less than or equal condition to use with isCloseTo temporal assertions.

Typical usage :

LocalTime _07_10 = LocalTime.of(7, 10); 
LocalTime _07_12 = LocalTime.of(7, 12); 
assertThat(_07_10).isCloseTo(_07_12, within(5, ChronoUnit.MINUTES));

[中]具有小于或等于条件的TemporalUnitOffset的断言入口点与isCloseTo时态断言一起使用。
典型用法:

LocalTime _07_10 = LocalTime.of(7, 10); 
LocalTime _07_12 = LocalTime.of(7, 12); 
assertThat(_07_10).isCloseTo(_07_12, within(5, ChronoUnit.MINUTES));

代码示例

代码示例来源:origin: org.assertj/assertj-core

/**
 * Assertions entry point for BigDecimal {@link Offset} to use with isCloseTo assertions.
 * <p>
 * Typical usage :
 * <pre><code class='java'> assertThat(BigDecimal.TEN).isCloseTo(new BigDecimal("10.5"), within(BigDecimal.ONE));</code></pre>
 *
 * @param value the value of the offset.
 * @return the created {@code Offset}.
 * @throws NullPointerException if the given value is {@code null}.
 * @throws IllegalArgumentException if the given value is negative.
 */
default Offset<BigDecimal> within(final BigDecimal value) {
 return Assertions.within(value);
}

代码示例来源:origin: org.assertj/assertj-core

/**
 * Assertions entry point for Byte {@link Offset} to use with isCloseTo assertions.
 * <p>
 * Typical usage :
 * <pre><code class='java'> assertThat((byte) 10).isCloseTo((byte) 11, within((byte) 1));</code></pre>
 *
 * @param value the value of the offset.
 * @return the created {@code Offset}.
 * @throws NullPointerException if the given value is {@code null}.
 * @throws IllegalArgumentException if the given value is negative.
 * @since 3.9.0
 */
default Offset<Byte> within(Byte value) {
 return Assertions.within(value);
}

代码示例来源:origin: org.assertj/assertj-core

/**
 * Alias for {@link #offset(Float)} to use with isCloseTo assertions.
 * <p>
 * Typical usage :
 * <pre><code class='java'> assertThat(8.2f).isCloseTo(8.0f, within(0.2f));</code></pre>
 *
 * @param value the value of the offset.
 * @return the created {@code Offset}.
 * @throws NullPointerException if the given value is {@code null}.
 * @throws IllegalArgumentException if the given value is negative.
 */
default Offset<Float> within(final Float value) {
 return Assertions.within(value);
}

代码示例来源:origin: org.assertj/assertj-core

/**
 * Alias for {@link #offset(Double)} to use with isCloseTo assertions.
 * <p>
 * Typical usage :
 * <pre><code class='java'> assertThat(8.1).isCloseTo(8.0, within(0.1));</code></pre>
 *
 * @param value the value of the offset.
 * @return the created {@code Offset}.
 * @throws NullPointerException if the given value is {@code null}.
 * @throws IllegalArgumentException if the given value is negative.
 */
default Offset<Double> within(final Double value) {
 return Assertions.within(value);
}

代码示例来源:origin: org.assertj/assertj-core

/**
 * Assertions entry point for Short {@link Offset} to use with isCloseTo assertions.
 * <p>
 * Typical usage :
 * <pre><code class='java'> assertThat(10).isCloseTo(11, within(1));</code></pre>
 *
 * @param value the value of the offset.
 * @return the created {@code Offset}.
 * @throws NullPointerException if the given value is {@code null}.
 * @throws IllegalArgumentException if the given value is negative.
 * @since 3.9.0
 */
default Offset<Short> within(Short value) {
 return Assertions.within(value);
}

代码示例来源:origin: org.assertj/assertj-core

/**
 * Assertions entry point for Long {@link Offset} to use with isCloseTo assertions.
 * <p>
 * Typical usage :
 * <pre><code class='java'> assertThat(5l).isCloseTo(7l, within(2l));</code></pre>
 *
 * @param value the value of the offset.
 * @return the created {@code Offset}.
 * @throws NullPointerException if the given value is {@code null}.
 * @throws IllegalArgumentException if the given value is negative.
 * @since 3.9.0
 */
default Offset<Long> within(Long value) {
 return Assertions.within(value);
}

代码示例来源:origin: org.assertj/assertj-core

/**
 * Assertions entry point for BigInteger {@link Offset} to use with isCloseTo assertions.
 * <p>
 * Typical usage :
 * <pre><code class='java'> assertThat(BigInteger.TEN).isCloseTo(new BigInteger("11"), within(new BigInteger("2")));</code></pre>
 *
 * @param value the value of the offset.
 * @return the created {@code Offset}.
 * @throws NullPointerException if the given value is {@code null}.
 * @throws IllegalArgumentException if the given value is negative.
 * @since 3.9.0
 */
default Offset<BigInteger> within(BigInteger value) {
 return Assertions.within(value);
}

代码示例来源:origin: org.assertj/assertj-core

/**
 * Assertions entry point for Integer {@link Offset} to use with isCloseTo assertions.
 * <p>
 * Typical usage :
 * <pre><code class='java'> assertThat(10).isCloseTo(11, within(1));</code></pre>
 *
 * @param value the value of the offset.
 * @return the created {@code Offset}.
 * @throws NullPointerException if the given value is {@code null}.
 * @throws IllegalArgumentException if the given value is negative.
 * @since 3.9.0
 */
default Offset<Integer> within(Integer value) {
 return Assertions.within(value);
}

代码示例来源:origin: org.assertj/assertj-core

/**
 * Assertions entry point for {@link TemporalUnitOffset} with  with less than or equal condition
 * to use with isCloseTo temporal assertions.
 * <p>
 * Typical usage :
 * <pre><code class='java'> LocalTime _07_10 = LocalTime.of(7, 10);
 * LocalTime _07_12 = LocalTime.of(7, 12);
 * assertThat(_07_10).isCloseTo(_07_12, within(5, ChronoUnit.MINUTES));</code></pre>
 *
 * @param value the allowed offset
 * @param unit the {@link TemporalUnit} of the offset
 * @return the created {@code Offset}.
 * @since 3.9.0
 */
default TemporalUnitOffset within(long value, TemporalUnit unit) {
 return Assertions.within(value, unit);
}

代码示例来源:origin: joel-costigliola/assertj-core

/**
 * Assertions entry point for BigDecimal {@link Offset} to use with isCloseTo assertions.
 * <p>
 * Typical usage :
 * <pre><code class='java'> assertThat(BigDecimal.TEN).isCloseTo(new BigDecimal("10.5"), within(BigDecimal.ONE));</code></pre>
 *
 * @param value the value of the offset.
 * @return the created {@code Offset}.
 * @throws NullPointerException if the given value is {@code null}.
 * @throws IllegalArgumentException if the given value is negative.
 */
default Offset<BigDecimal> within(final BigDecimal value) {
 return Assertions.within(value);
}

代码示例来源:origin: joel-costigliola/assertj-core

/**
 * Alias for {@link #offset(Float)} to use with isCloseTo assertions.
 * <p>
 * Typical usage :
 * <pre><code class='java'> assertThat(8.2f).isCloseTo(8.0f, within(0.2f));</code></pre>
 *
 * @param value the value of the offset.
 * @return the created {@code Offset}.
 * @throws NullPointerException if the given value is {@code null}.
 * @throws IllegalArgumentException if the given value is negative.
 */
default Offset<Float> within(final Float value) {
 return Assertions.within(value);
}

代码示例来源:origin: joel-costigliola/assertj-core

/**
 * Alias for {@link #offset(Double)} to use with isCloseTo assertions.
 * <p>
 * Typical usage :
 * <pre><code class='java'> assertThat(8.1).isCloseTo(8.0, within(0.1));</code></pre>
 *
 * @param value the value of the offset.
 * @return the created {@code Offset}.
 * @throws NullPointerException if the given value is {@code null}.
 * @throws IllegalArgumentException if the given value is negative.
 */
default Offset<Double> within(final Double value) {
 return Assertions.within(value);
}

代码示例来源:origin: joel-costigliola/assertj-core

/**
 * Assertions entry point for Long {@link Offset} to use with isCloseTo assertions.
 * <p>
 * Typical usage :
 * <pre><code class='java'> assertThat(5l).isCloseTo(7l, within(2l));</code></pre>
 *
 * @param value the value of the offset.
 * @return the created {@code Offset}.
 * @throws NullPointerException if the given value is {@code null}.
 * @throws IllegalArgumentException if the given value is negative.
 * @since 3.9.0
 */
default Offset<Long> within(Long value) {
 return Assertions.within(value);
}

代码示例来源:origin: joel-costigliola/assertj-core

/**
 * Assertions entry point for Byte {@link Offset} to use with isCloseTo assertions.
 * <p>
 * Typical usage :
 * <pre><code class='java'> assertThat((byte) 10).isCloseTo((byte) 11, within((byte) 1));</code></pre>
 *
 * @param value the value of the offset.
 * @return the created {@code Offset}.
 * @throws NullPointerException if the given value is {@code null}.
 * @throws IllegalArgumentException if the given value is negative.
 * @since 3.9.0
 */
default Offset<Byte> within(Byte value) {
 return Assertions.within(value);
}

代码示例来源:origin: joel-costigliola/assertj-core

/**
 * Assertions entry point for BigInteger {@link Offset} to use with isCloseTo assertions.
 * <p>
 * Typical usage :
 * <pre><code class='java'> assertThat(BigInteger.TEN).isCloseTo(new BigInteger("11"), within(new BigInteger("2")));</code></pre>
 *
 * @param value the value of the offset.
 * @return the created {@code Offset}.
 * @throws NullPointerException if the given value is {@code null}.
 * @throws IllegalArgumentException if the given value is negative.
 * @since 3.9.0
 */
default Offset<BigInteger> within(BigInteger value) {
 return Assertions.within(value);
}

代码示例来源:origin: joel-costigliola/assertj-core

/**
 * Assertions entry point for Short {@link Offset} to use with isCloseTo assertions.
 * <p>
 * Typical usage :
 * <pre><code class='java'> assertThat(10).isCloseTo(11, within(1));</code></pre>
 *
 * @param value the value of the offset.
 * @return the created {@code Offset}.
 * @throws NullPointerException if the given value is {@code null}.
 * @throws IllegalArgumentException if the given value is negative.
 * @since 3.9.0
 */
default Offset<Short> within(Short value) {
 return Assertions.within(value);
}

代码示例来源:origin: joel-costigliola/assertj-core

/**
 * Assertions entry point for Integer {@link Offset} to use with isCloseTo assertions.
 * <p>
 * Typical usage :
 * <pre><code class='java'> assertThat(10).isCloseTo(11, within(1));</code></pre>
 *
 * @param value the value of the offset.
 * @return the created {@code Offset}.
 * @throws NullPointerException if the given value is {@code null}.
 * @throws IllegalArgumentException if the given value is negative.
 * @since 3.9.0
 */
default Offset<Integer> within(Integer value) {
 return Assertions.within(value);
}

代码示例来源:origin: joel-costigliola/assertj-core

/**
 * Assertions entry point for {@link TemporalUnitOffset} with  with less than or equal condition
 * to use with isCloseTo temporal assertions.
 * <p>
 * Typical usage :
 * <pre><code class='java'> LocalTime _07_10 = LocalTime.of(7, 10);
 * LocalTime _07_12 = LocalTime.of(7, 12);
 * assertThat(_07_10).isCloseTo(_07_12, within(5, ChronoUnit.MINUTES));</code></pre>
 *
 * @param value the allowed offset
 * @param unit the {@link TemporalUnit} of the offset
 * @return the created {@code Offset}.
 * @since 3.9.0
 */
default TemporalUnitOffset within(long value, TemporalUnit unit) {
 return Assertions.within(value, unit);
}

代码示例来源:origin: apache/geode

@Test
public void calculateCpuUsageShouldCorrectlyCalculateTheCpuUsed() {
 Instant now = Instant.now();
 long halfSecondAsNanoseconds = 500000000L;
 long quarterSecondAsNanoseconds = 250000000L;
 long threeQuarterSecondAsNanoseconds = 750000000L;
 vmStatsMonitor = spy(new VMStatsMonitor(testName.getMethodName()));
 when(vmStatsMonitor.getLastSystemTime()).thenReturn(now.toEpochMilli());
 // 50% used
 when(vmStatsMonitor.getLastProcessCpuTime()).thenReturn(0L);
 float initialCpuUsage = vmStatsMonitor
   .calculateCpuUsage(now.plus(1, ChronoUnit.SECONDS).toEpochMilli(), halfSecondAsNanoseconds);
 assertThat(initialCpuUsage).isNotEqualTo(Float.NaN);
 assertThat(initialCpuUsage).isCloseTo(50F, within(1F));
 // 25% decrease
 when(vmStatsMonitor.getLastProcessCpuTime()).thenReturn(50L);
 float decreasedCpuUsage = vmStatsMonitor.calculateCpuUsage(
   now.plus(1, ChronoUnit.SECONDS).toEpochMilli(), quarterSecondAsNanoseconds);
 assertThat(decreasedCpuUsage).isNotEqualTo(Float.NaN);
 assertThat(decreasedCpuUsage).isLessThan(initialCpuUsage);
 assertThat(decreasedCpuUsage).isCloseTo(25F, within(1F));
 // 50% increase
 when(vmStatsMonitor.getLastProcessCpuTime()).thenReturn(25L);
 float increasedCpuUsage = vmStatsMonitor.calculateCpuUsage(
   now.plus(1, ChronoUnit.SECONDS).toEpochMilli(), threeQuarterSecondAsNanoseconds);
 assertThat(increasedCpuUsage).isNotEqualTo(Float.NaN);
 assertThat(increasedCpuUsage).isGreaterThan(decreasedCpuUsage);
 assertThat(increasedCpuUsage).isCloseTo(75F, within(1F));
}

代码示例来源:origin: org.apache.commons/commons-text

@Test
public void testCosineSimilarityWithNonEmptyMap() {
  final CosineSimilarity cosineSimilarity = new CosineSimilarity();
  final Map<CharSequence, Integer> hashMap = new HashMap<>();
  final Integer integer = -397;
  hashMap.put("3J/$3.L", integer);
  final Map<CharSequence, Integer> hashMapTwo = new HashMap<>();
  assertThat(cosineSimilarity.cosineSimilarity(hashMap, hashMapTwo)).isEqualTo(0.0, within(0.01));
}

相关文章