org.llorllale.cactoos.matchers.ScalarHasValue Java Examples
The following examples show how to use
org.llorllale.cactoos.matchers.ScalarHasValue.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Lcom4Test.java From jpeek with MIT License | 7 votes |
@ParameterizedTest @Disabled @CsvFileSource(resources = "/org/jpeek/calculus/java/lcom4-params.csv") public void calculatesValue(final String file, final String value) throws Exception { final XML result = new Lcom4().node( "", new HashMap<>(0), new Skeleton( new FakeBase(file) ).xml() ); new Assertion<>( "Must create LCOM4 value", new ItemAt<>(0, result.xpath("/metric/app/package/class/@value")), new ScalarHasValue<>(value) ).affirm(); }
Example #2
Source File: SolidTest.java From cactoos with MIT License | 6 votes |
@Test public void worksInThreads() { new Assertion<>( "must work well in multiple threads", scalar -> { new Assertion<>( "must compute value once", scalar, new ScalarHasValue<>(scalar.value()) ).affirm(); return true; }, new RunsInThreads<>( new Unchecked<>( new Solid<>(() -> new ListOf<>(1, 2)) ) ) ).affirm(); }
Example #3
Source File: MaxOfTest.java From cactoos with MIT License | 6 votes |
@Test public void withNegativeIntegerCollection() { new Assertion<>( "must select maximum integer of negative integers", () -> new MaxOf(-1, -2, -3, -4).intValue(), new ScalarHasValue<>(-1) ).affirm(); new Assertion<>( "must select maximum long of negative integers", () -> new MaxOf(-1, -2, -3, -4).longValue(), new ScalarHasValue<>(-1L) ).affirm(); new Assertion<>( "must select maximum double of negative integers", () -> new MaxOf(-1, -2, -3, -4).doubleValue(), new ScalarHasValue<>(-1.0d) ).affirm(); new Assertion<>( "must select maximum float of negative integers", () -> new MaxOf(-1, -2, -3, -4).floatValue(), new ScalarHasValue<>(-1.0f) ).affirm(); }
Example #4
Source File: PropertiesOfTest.java From cactoos with MIT License | 6 votes |
@Test public void readsStringContent() { new Assertion<>( "Must read properties from an input string", new PropertiesOf( "foo=Hello, world!\nbar=works fine?\n" ), new ScalarHasValue<>( new MatcherOf<Properties>( props -> { return "Hello, world!".equals( props.getProperty("foo") ); } ) ) ).affirm(); }
Example #5
Source File: ScalarWithFallbackTest.java From cactoos with MIT License | 6 votes |
@Test public void usesFallback() throws Exception { final String message = "Fallback from IOException"; new Assertion<>( "Must use a single fallback in case of exception", new ScalarWithFallback<>( () -> { throw new IOException("Failure with IOException"); }, new IterableOf<>( new FallbackFrom<>( new IterableOf<>(IOException.class), exp -> message ) ) ), new ScalarHasValue<>(message) ).affirm(); }
Example #6
Source File: MaxOfTest.java From cactoos with MIT License | 6 votes |
@Test public void withNegativeLongCollection() { new Assertion<>( "must select maximum integer of negative longs", () -> new MaxOf(-1L, -2L, -3L, -4L).intValue(), new ScalarHasValue<>(-1) ).affirm(); new Assertion<>( "must select maximum long of negative longs", () -> new MaxOf(-1L, -2L, -3L, -4L).longValue(), new ScalarHasValue<>(-1L) ).affirm(); new Assertion<>( "must select maximum double of negative longs", () -> new MaxOf(-1L, -2L, -3L, -4L).doubleValue(), new ScalarHasValue<>(-1.0d) ).affirm(); new Assertion<>( "must select maximum float of negative longs", () -> new MaxOf(-1L, -2L, -3L, -4L).floatValue(), new ScalarHasValue<>(-1.0f) ).affirm(); }
Example #7
Source File: MaxOfTest.java From cactoos with MIT License | 6 votes |
@Test public void withPositiveAndNegativeDoubleCollection() { new Assertion<>( "must select maximum integer of positive and negative doubles", () -> new MaxOf(-2.0d, -1.0d, 0.0d, 1.0d, 2.0d).intValue(), new ScalarHasValue<>(2) ).affirm(); new Assertion<>( "must select maximum long of positive and negative doubles", () -> new MaxOf(-2.0d, -1.0d, 0.0d, 1.0d, 2.0d).longValue(), new ScalarHasValue<>(2L) ).affirm(); new Assertion<>( "must select maximum double of positive and negative doubles", () -> new MaxOf(-2.0d, -1.0d, 0.0d, 1.0d, 2.0d).doubleValue(), new ScalarHasValue<>(2.0d) ).affirm(); new Assertion<>( "must select maximum float of positive and negative doubles", () -> new MaxOf(-2.0d, -1.0d, 0.0d, 1.0d, 2.0d).floatValue(), new ScalarHasValue<>(2.0f) ).affirm(); }
Example #8
Source File: CycledTest.java From cactoos with MIT License | 6 votes |
@Test public void repeatIterableTest() { final String expected = "two"; new Assertion<>( "Can't repeat iterable", new ItemAt<>( // @checkstyle MagicNumberCheck (1 line)< 7, new Cycled<>( new IterableOf<>( "one", expected, "three" ) ) ), new ScalarHasValue<>( expected ) ).affirm(); }
Example #9
Source File: DateOfTest.java From cactoos with MIT License | 6 votes |
@Test public final void testParsingCustomFormatterStringToDate() { new Assertion<>( "must parse a Date with custom format.", new DateOf( "2017-12-13 14:15:16.000000017", DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.n") ), new ScalarHasValue<>( Date.from( LocalDateTime.of( 2017, 12, 13, 14, 15, 16, 17 ).toInstant(ZoneOffset.UTC) ) ) ).affirm(); }
Example #10
Source File: DateOfTest.java From cactoos with MIT License | 6 votes |
@Test public final void testParsingCustomFormattedStringWithoutTimeToDate() { new Assertion<>( "must parse a Date with custom format.", new DateOf( "2018-01-01", "yyyy-MM-dd" ), new ScalarHasValue<>( Date.from( LocalDateTime.of( 2018, 01, 01, 0, 0, 0, 0 ).toInstant(ZoneOffset.UTC) ) ) ).affirm(); }
Example #11
Source File: DateOfTest.java From cactoos with MIT License | 6 votes |
@Test public final void testParsingCustomFormattedStringToDate() { new Assertion<>( "must parse a Date with custom format.", new DateOf( "2017-12-13 14:15:16.000000017", "yyyy-MM-dd HH:mm:ss.n" ), new ScalarHasValue<>( Date.from( LocalDateTime.of( 2017, 12, 13, 14, 15, 16, 17 ).toInstant(ZoneOffset.UTC) ) ) ).affirm(); }
Example #12
Source File: MaxOfTest.java From cactoos with MIT License | 6 votes |
@Test public void withPositiveAndNegativeLongCollection() { new Assertion<>( "must select maximum integer of positive and negative longs", () -> new MaxOf(-2L, -1L, 0L, 1L, 2L).intValue(), new ScalarHasValue<>(2) ).affirm(); new Assertion<>( "must select maximum long of positive and negative longs", () -> new MaxOf(-2L, -1L, 0L, 1L, 2L).longValue(), new ScalarHasValue<>(2L) ).affirm(); new Assertion<>( "must select maximum double of positive and negative longs", () -> new MaxOf(-2L, -1L, 0L, 1L, 2L).doubleValue(), new ScalarHasValue<>(2.0d) ).affirm(); new Assertion<>( "must select maximum float of positive and negative longs", () -> new MaxOf(-2L, -1L, 0L, 1L, 2L).floatValue(), new ScalarHasValue<>(2.0f) ).affirm(); }
Example #13
Source File: OffsetDateTimeOfTest.java From cactoos with MIT License | 6 votes |
@Test public final void testParsingFormattedStringWithOffsetToOffsetDateTime() { new Assertion<>( "Can't parse a OffsetDateTime with custom format.", new OffsetDateTimeOf( "2017-12-13 14:15:16", "yyyy-MM-dd HH:mm:ss", ZoneOffset.ofHours(1) ), new ScalarHasValue<>( OffsetDateTime.of( LocalDateTime.of(2017, 12, 13, 14, 15, 16), ZoneOffset.ofHours(1) ) ) ).affirm(); }
Example #14
Source File: MaxOfTest.java From cactoos with MIT License | 6 votes |
@Test public void withPositiveIntegerCollection() { new Assertion<>( "must select maximum integer of positive integers", () -> new MaxOf(1, 2, 3, 4).intValue(), new ScalarHasValue<>(4) ).affirm(); new Assertion<>( "must select maximum long of positive integers", () -> new MaxOf(1, 2, 3, 4).longValue(), new ScalarHasValue<>(4L) ).affirm(); new Assertion<>( "must select maximum double of positive integers", () -> new MaxOf(1, 2, 3, 4).doubleValue(), new ScalarHasValue<>(4.0d) ).affirm(); new Assertion<>( "must select maximum float of positive integers", () -> new MaxOf(1, 2, 3, 4).floatValue(), new ScalarHasValue<>(4.0f) ).affirm(); }
Example #15
Source File: CycledTest.java From cactoos with MIT License | 6 votes |
@Test public void repeatIteratorTest() throws Exception { final String expected = "two"; new Assertion<>( "must repeat iterator", new ItemAt<>( // @checkstyle MagicNumberCheck (1 line) 7, new IterableOf<>( new Cycled<>( new NoNulls<>( new IterableOf<>( "one", expected, "three" ) ) ) ) ), new ScalarHasValue<>( expected ) ).affirm(); }
Example #16
Source File: MaxOfTest.java From cactoos with MIT License | 6 votes |
@Test public void withNegativeDoubleCollection() { new Assertion<>( "must select maximum integer of negative doubles", () -> new MaxOf(-1.0d, -2.0d, -3.0d, -4.0d).intValue(), new ScalarHasValue<>(-1) ).affirm(); new Assertion<>( "must select maximum long of negative doubles", () -> new MaxOf(-1.0d, -2.0d, -3.0d, -4.0d).longValue(), new ScalarHasValue<>(-1L) ).affirm(); new Assertion<>( "must select maximum double of negative doubles", () -> new MaxOf(-1.0d, -2.0d, -3.0d, -4.0d).doubleValue(), new ScalarHasValue<>(-1.0d) ).affirm(); new Assertion<>( "must select maximum float of negative doubles", () -> new MaxOf(-1.0d, -2.0d, -3.0d, -4.0d).floatValue(), new ScalarHasValue<>(-1.0f) ).affirm(); }
Example #17
Source File: ScalarWithFallbackTest.java From cactoos with MIT License | 6 votes |
@Test public void usesTheClosestFallback() throws Exception { final String expected = "Fallback from IllegalFormatException"; new Assertion<>( "Must find the closest fallback", new ScalarWithFallback<>( () -> { throw new IllegalFormatWidthException(1); }, new IterableOf<>( new FallbackFrom<>( new IterableOf<>(IllegalArgumentException.class), exp -> "Fallback from IllegalArgumentException" ), new FallbackFrom<>( new IterableOf<>(IllegalFormatException.class), exp -> expected ) ) ), new ScalarHasValue<>(expected) ).affirm(); }
Example #18
Source File: ZonedDateTimeOfTest.java From cactoos with MIT License | 6 votes |
@Test public final void testParsingFormattedStringWithZoneToZonedDateTime() { new Assertion<>( "Can't parse a ZonedDateTime with custom format and zone.", new ZonedDateTimeOf( "2017-12-13 14:15:16", "yyyy-MM-dd HH:mm:ss", ZoneId.of("Europe/Berlin") ), new ScalarHasValue<>( ZonedDateTime.of( LocalDateTime.of(2017, 12, 13, 14, 15, 16), ZoneId.of("Europe/Berlin") ) ) ).affirm(); }
Example #19
Source File: MaxOfTest.java From cactoos with MIT License | 6 votes |
@Test public void withNegativeFloatCollection() { new Assertion<>( "must select maximum integer of negative floats", () -> new MaxOf(-1.0f, -2.0f, -3.0f, -4.0f).intValue(), new ScalarHasValue<>(-1) ).affirm(); new Assertion<>( "must select maximum long of negative floats", () -> new MaxOf(-1.0f, -2.0f, -3.0f, -4.0f).longValue(), new ScalarHasValue<>(-1L) ).affirm(); new Assertion<>( "must select maximum double of negative floats", () -> new MaxOf(-1.0f, -2.0f, -3.0f, -4.0f).doubleValue(), new ScalarHasValue<>(-1.0d) ).affirm(); new Assertion<>( "must select maximum float of negative floats", () -> new MaxOf(-1.0f, -2.0f, -3.0f, -4.0f).floatValue(), new ScalarHasValue<>(-1.0f) ).affirm(); }
Example #20
Source File: BinaryTest.java From cactoos with MIT License | 6 votes |
@Test public void conditionFalse() { final int expected = 0; final AtomicInteger counter = new AtomicInteger(0); final Binary binary = new Binary( new False(), counter::incrementAndGet ); new Assertion<>( "Binary has to return false", binary, new ScalarHasValue<>(false) ).affirm(); new Assertion<>( "Binary must not to invoke increment method", counter.get(), new IsEqual<>(expected) ).affirm(); }
Example #21
Source File: AndInThreadsTest.java From cactoos with MIT License | 6 votes |
@Test public void iteratesEmptyList() { final List<String> list = new Synced<>( new ArrayList<>(2) ); new Assertion<>( "Must iterate an empty list", new AndInThreads( new Mapped<String, Scalar<Boolean>>( new FuncOf<>(list::add, () -> true), new IterableOf<>() ) ), new ScalarHasValue<>( Matchers.allOf( Matchers.equalTo(true), new MatcherOf<>( value -> { return list.isEmpty(); } ) ) ) ).affirm(); }
Example #22
Source File: MaxOfTest.java From cactoos with MIT License | 6 votes |
@Test public void withPositiveFloatCollection() { new Assertion<>( "must select maximum integer of positive floats", () -> new MaxOf(1.0f, 2.0f, 3.0f, 4.0f).intValue(), new ScalarHasValue<>(4) ).affirm(); new Assertion<>( "must select maximum long of positive floats", () -> new MaxOf(1.0f, 2.0f, 3.0f, 4.0f).longValue(), new ScalarHasValue<>(4L) ).affirm(); new Assertion<>( "must select maximum double of positive floats", () -> new MaxOf(1.0f, 2.0f, 3.0f, 4.0f).doubleValue(), new ScalarHasValue<>(4.0d) ).affirm(); new Assertion<>( "must select maximum float of positive floats", () -> new MaxOf(1.0f, 2.0f, 3.0f, 4.0f).floatValue(), new ScalarHasValue<>(4.0f) ).affirm(); }
Example #23
Source File: MaxOfTest.java From cactoos with MIT License | 6 votes |
@Test public void withPositiveAndNegativeFloatCollection() { new Assertion<>( "must select maximum integer of positive and negative floats", () -> new MaxOf(-2.0f, -1.0f, 0.0f, 1.0f, 2.0f).intValue(), new ScalarHasValue<>(2) ).affirm(); new Assertion<>( "must select maximum long of positive and negative floats", () -> new MaxOf(-2.0f, -1.0f, 0.0f, 1.0f, 2.0f).longValue(), new ScalarHasValue<>(2L) ).affirm(); new Assertion<>( "must select maximum double of positive and negative floats", () -> new MaxOf(-2.0f, -1.0f, 0.0f, 1.0f, 2.0f).doubleValue(), new ScalarHasValue<>(2.0d) ).affirm(); new Assertion<>( "must select maximum float of positive and negative floats", () -> new MaxOf(-2.0f, -1.0f, 0.0f, 1.0f, 2.0f).floatValue(), new ScalarHasValue<>(2.0f) ).affirm(); }
Example #24
Source File: RetryTest.java From cactoos with MIT License | 6 votes |
@Test public void runsScalarMultipleTimesIgnoringNegativeDuration() throws Exception { // @checkstyle MagicNumberCheck (2 line) final int times = 2; final AtomicInteger tries = new AtomicInteger(0); new Assertion<>( "Should ignore negative duration", new Retry<>( () -> { if (tries.getAndIncrement() < times) { throw new IllegalArgumentException("Not yet"); } return 0; }, Integer.MAX_VALUE, // @checkstyle MagicNumberCheck (1 line) Duration.of(-5, ChronoUnit.DAYS) ), new ScalarHasValue<>(0) ).affirm(); }
Example #25
Source File: BinaryTest.java From cactoos with MIT License | 6 votes |
@Test public void conditionTrue() { final int expected = 1; final AtomicInteger counter = new AtomicInteger(0); final Binary binary = new Binary( new True(), counter::incrementAndGet ); new Assertion<>( "Binary has to return true", binary, new ScalarHasValue<>(true) ).affirm(); new Assertion<>( "Binary has to invoke increment method", counter.get(), new IsEqual<>(expected) ).affirm(); }
Example #26
Source File: ScalarWithFallbackTest.java From cactoos with MIT License | 6 votes |
@Test public void usesFallbackOfInterruptedException() throws Exception { final String message = "Fallback from InterruptedException"; new Assertion<>( "Must use a fallback from Interrupted in case of exception", new ScalarWithFallback<>( () -> { throw new InterruptedException( "Failure with InterruptedException" ); }, new IterableOf<>( new FallbackFrom<>( new IterableOf<>(InterruptedException.class), exp -> message ) ) ), new ScalarHasValue<>(message) ).affirm(); }
Example #27
Source File: EqualsNullableTest.java From cactoos with MIT License | 5 votes |
@Test public void nullEqualsNull() throws Exception { new Assertion<>( "Must return true for both null objects", new EqualsNullable(() -> null, () -> null), new ScalarHasValue<>(true) ).affirm(); }
Example #28
Source File: SumOfIntTest.java From cactoos with MIT License | 5 votes |
@Test public void withListOfScalarsInt() { new Assertion<>( "must sum scalars", new SumOfInt(() -> 1, () -> 2, () -> 3), new ScalarHasValue<>(6) ).affirm(); }
Example #29
Source File: SumOfIntTest.java From cactoos with MIT License | 5 votes |
@Test public void withListOfOneElement() { new Assertion<>( "must sum singleton list", new SumOfInt(() -> 5), new ScalarHasValue<>(5) ).affirm(); }
Example #30
Source File: InheritanceLevelTest.java From cactoos with MIT License | 5 votes |
@Test public void classesAreNotRelated() { MatcherAssert.assertThat( new InheritanceLevel( FileNotFoundException.class, RuntimeException.class ), new ScalarHasValue<>(Integer.MIN_VALUE) ); }