/** * Creates a matcher of {@link Comparable} object that matches when the examined object is * less than the specified value, as reported by the <code>compareTo</code> method of the * <b>examined</b> object. * <p/> * For example: * <pre>assertThat(1, lessThan(2))</pre> * * @param value * the value which, when passed to the compareTo method of the examined object, should return less * than zero */ public static <T extends java.lang.Comparable<T>> org.hamcrest.Matcher<T> lessThan(T value) { return org.hamcrest.number.OrderingComparison.<T>lessThan(value); }
public void testDescription() { assertDescription("a value greater than <1>", greaterThan(1)); assertDescription("a value equal to or greater than <1>", greaterThanOrEqualTo(1)); assertDescription("a value equal to <1>", comparesEqualTo(1)); assertDescription("a value less than or equal to <1>", lessThanOrEqualTo(1)); assertDescription("a value less than <1>", lessThan(1)); }
/** * Creates a matcher of {@link Comparable} object that matches when the examined object is * less than the specified value, as reported by the <code>compareTo</code> method of the * <b>examined</b> object. * For example: * <pre>assertThat(1, lessThan(2))</pre> * * @param value the value which, when passed to the compareTo method of the examined object, should return less * than zero */ public static <T extends java.lang.Comparable<T>> org.hamcrest.Matcher<T> lessThan(T value) { return org.hamcrest.number.OrderingComparison.lessThan(value); }
public void testDescription() { assertDescription("a value greater than <1>", greaterThan(1)); assertDescription("a value equal to or greater than <1>", greaterThanOrEqualTo(1)); assertDescription("a value equal to <1>", comparesEqualTo(1)); assertDescription("a value less than or equal to <1>", lessThanOrEqualTo(1)); assertDescription("a value less than <1>", lessThan(1)); }
<T> void await(int count, final Publisher<T> s, Matcher<T> expected) throws InterruptedException { final CountDownLatch latch = new CountDownLatch(count); final AtomicReference<T> ref = new AtomicReference<>(); Flux.from(s).subscribe(t -> { ref.set(t); latch.countDown(); }, t -> { t.printStackTrace(); latch.countDown(); }); long startTime = System.currentTimeMillis(); T result = null; try { latch.await(10, TimeUnit.SECONDS); result = ref.get(); } catch (Exception e) { e.printStackTrace(); } long duration = System.currentTimeMillis() - startTime; assertThat(result, expected); assertThat(duration, is(lessThan(2000L))); }
@Test public void testThresholdComparisons() { assertThat(MemoryUnit.KB.compareTo(1, 1024L - 1, MemoryUnit.B), greaterThan(0)); assertThat(MemoryUnit.KB.compareTo(1, 1024L, MemoryUnit.B), is(0)); assertThat(MemoryUnit.KB.compareTo(1, 1024L + 1, MemoryUnit.B), lessThan(0)); assertThat(MemoryUnit.KB.compareTo(2, 2048L - 1, MemoryUnit.B), greaterThan(0)); assertThat(MemoryUnit.KB.compareTo(2, 2048L, MemoryUnit.B), is(0)); assertThat(MemoryUnit.KB.compareTo(2, 2048L + 1, MemoryUnit.B), lessThan(0)); } }
public void testComparesCustomTypesWhoseCompareToReturnsValuesGreaterThatOne() { assertThat(new CustomInt(5), lessThan(new CustomInt(10))); }
public void testComparesCustomTypesWhoseCompareToReturnsValuesGreaterThatOne() { assertThat(new CustomInt(5), lessThan(new CustomInt(10))); }
public void testMismatchDescriptions() { assertMismatchDescription("<0> was less than <1>", greaterThan(1), 0); assertMismatchDescription("<1> was equal to <1>", greaterThan(1), 1); assertMismatchDescription("<1> was greater than <0>", lessThan(0), 1); assertMismatchDescription("<2> was equal to <2>", lessThan(2), 2); }
public void testMismatchDescriptions() { assertMismatchDescription("<0> was less than <1>", greaterThan(1), 0); assertMismatchDescription("<1> was equal to <1>", greaterThan(1), 1); assertMismatchDescription("<1> was greater than <0>", lessThan(0), 1); assertMismatchDescription("<2> was equal to <2>", lessThan(2), 2); }
@Test public void shouldCompactCollection() { final int totalItems = 50; for (int i = 0; i < totalItems; i++) { objectToIntMap.put(Integer.toString(i), i); } for (int i = 0, limit = totalItems - 4; i < limit; i++) { objectToIntMap.remove(Integer.toString(i)); } final int capacityBeforeCompaction = objectToIntMap.capacity(); objectToIntMap.compact(); assertThat(objectToIntMap.capacity(), lessThan(capacityBeforeCompaction)); }
public void test_matchesRelativeLengthOf_CharSequence() { final Matcher<CharSequence> matcher = hasLength(lessThan(4)); assertMatches(matcher, "aaa"); assertMatches(matcher, "a b"); assertMismatchDescription("length <4> was equal to <4>", matcher, "aaaa"); assertMismatchDescription("length <5> was greater than <4>", matcher, "aaaaa"); }
@Test public void shouldCompactCollection() { final int totalItems = 50; for (int i = 0; i < totalItems; i++) { intToObjectMap.put(i, Integer.toString(i)); } for (int i = 0, limit = totalItems - 4; i < limit; i++) { intToObjectMap.remove(i); } final int capacityBeforeCompaction = intToObjectMap.capacity(); intToObjectMap.compact(); assertThat(intToObjectMap.capacity(), lessThan(capacityBeforeCompaction)); }
@Test public void tableTypeCompare3() throws Exception { final TableType tableType1 = new TableType("view"); final TableType tableType2 = new TableType("materialized view"); assertThat(tableType1, lessThan(tableType2)); assertThat(tableType2, greaterThan(tableType1)); }
@Test public void compareTo_shouldCompareBasedOnPatientId() { Date date = new Date(); CohortMembership firstMembership = new CohortMembership(4, date); CohortMembership secondMembership = new CohortMembership(7, date); assertThat(firstMembership.compareTo(secondMembership), lessThan(0)); assertThat(secondMembership.compareTo(firstMembership), greaterThan(0)); }
@Property public void shouldHold(float f) { assertThat(f, greaterThanOrEqualTo(RangeAttributes.minFloat())); assertThat(f, lessThan(RangeAttributes.maxFloat())); } }
@Property public void shouldHold(@InRange(min = "-2.71") Double d) { assertThat(d, greaterThanOrEqualTo(-2.71)); assertThat(d, lessThan(RangeAttributes.maxDouble())); } }
@Property public void shouldHold(@InRange(min = "-2.71") Float f) { assertThat(f, greaterThanOrEqualTo(-2.71F)); assertThat(f, lessThan(RangeAttributes.maxFloat())); } }