org.llorllale.cactoos.matchers.Assertion Java Examples
The following examples show how to use
org.llorllale.cactoos.matchers.Assertion.
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: TeeOutputTest.java From cactoos with MIT License | 6 votes |
@Test public void copiesWithWriter() { final ByteArrayOutputStream baos = new ByteArrayOutputStream(); new Assertion<>( "Can't copy Output with writer", new TeeInput( new InputOf("Hello, товарищ! writer"), new TeeOutput( new OutputTo(baos), new WriterTo(new ByteArrayOutputStream()) ) ), new InputHasContent( new TextOf(baos::toByteArray, StandardCharsets.UTF_8) ) ).affirm(); }
Example #2
Source File: ScalarWithFallbackTest.java From cactoos with MIT License | 6 votes |
@Test public void usesMainFunc() throws Exception { final String message = "Main function's result #1"; new Assertion<>( "Must use the main function if no exception", new ScalarWithFallback<>( () -> message, new IterableOf<>( new FallbackFrom<>( new IterableOf<>(IOException.class), Throwable::getMessage ) ) ), new ScalarHasValue<>(message) ).affirm(); }
Example #3
Source File: ReplacedTest.java From cactoos with MIT License | 6 votes |
@Test public void invalidRegex() { final String regex = "invalid_regex{0,"; new Assertion<>( "Doesn't throw proper exception", new Replaced( new TextOf("text"), regex, "error" )::asString, new Throws<>( new PatternSyntaxException( "Unclosed counted closure", regex, // @checkstyle MagicNumberCheck (1 line) 16 ).getMessage(), PatternSyntaxException.class ) ).affirm(); }
Example #4
Source File: LoggingInputTest.java From cactoos with MIT License | 6 votes |
@Test public void logReadFromLargeTextFile() throws IOException { final Logger logger = new FakeLogger(); new LengthOf( new LoggingInput( new ResourceOf("org/cactoos/large-text.txt"), "text file", logger ) ).intValue(); new Assertion<>( "Can't log 74536 bytes read from text file", logger.toString(), Matchers.allOf( Matchers.not( Matchers.containsString("Read 16384 byte(s) from text file") ), Matchers.containsString("Read 74536 byte(s) from text file in"), Matchers.containsString("Closed input stream from text file") ) ).affirm(); }
Example #5
Source File: TeeInputFromUriTest.java From cactoos with MIT License | 6 votes |
@Test public void copiesFromUriToFile() throws IOException { final String message = "Hello, товарищ file #1 äÄ üÜ öÖ and ß"; final File input = this.folder.newFile(); Files.write( input.toPath(), message.getBytes(StandardCharsets.UTF_8) ); final File output = this.folder.newFile(); new Assertion<>( "Must copy from URI to file.", new TeeInput( input.toURI(), output ), new InputHasContent(message) ).affirm(); }
Example #6
Source File: LoggingInputTest.java From cactoos with MIT License | 6 votes |
@Test public void logMarkSupportedFromLargeTextFile() throws Exception { final Logger logger = new FakeLogger(); new LoggingInput( new ResourceOf("org/cactoos/large-text.txt"), "text file", logger ).stream().markSupported(); new Assertion<>( "Can't log mark and reset are not supported from text file", logger.toString(), Matchers.containsString( "Mark and reset are supported from text file" ) ).affirm(); }
Example #7
Source File: RsWithStatusTest.java From takes with MIT License | 6 votes |
/** * RsWithStatus can add status multiple times. */ @SuppressWarnings( { "PMD.JUnitTestContainsTooManyAsserts", "PMD.ProhibitPlainJunitAssertionsRule" } ) @Test public void addsStatusMultipleTimes() { final Response response = new RsWithStatus( new RsWithStatus( new RsEmpty(), HttpURLConnection.HTTP_NOT_FOUND ), HttpURLConnection.HTTP_SEE_OTHER ); final Assertion<Scalar<Iterable<?>>> assertion = new Assertion<>( "Head with one line", response::head, new ScalarHasValue<>(new HasSize(1)) ); assertion.affirm(); assertion.affirm(); }
Example #8
Source File: MaxOfTest.java From cactoos with MIT License | 6 votes |
@Test public void withPositiveDoubleCollection() { new Assertion<>( "must select maximum integer of positive doubles", () -> new MaxOf(1.0d, 2.0d, 3.0d, 4.0d).intValue(), new ScalarHasValue<>(4) ).affirm(); new Assertion<>( "must select maximum long of positive doubles", () -> new MaxOf(1.0d, 2.0d, 3.0d, 4.0d).longValue(), new ScalarHasValue<>(4L) ).affirm(); new Assertion<>( "must select maximum double of positive doubles", () -> new MaxOf(1.0d, 2.0d, 3.0d, 4.0d).doubleValue(), new ScalarHasValue<>(4.0d) ).affirm(); new Assertion<>( "must select maximum float of positive doubles", () -> new MaxOf(1.0d, 2.0d, 3.0d, 4.0d).floatValue(), new ScalarHasValue<>(4.0f) ).affirm(); }
Example #9
Source File: TeeOutputTest.java From cactoos with MIT License | 6 votes |
@Test public void copiesWithPath() throws Exception { final ByteArrayOutputStream baos = new ByteArrayOutputStream(); final File file = this.folder.newFile(); new Assertion<>( "Must copy Output with path", new TextOf( new TeeInput( new InputOf("Hello, товарищ! with path"), new TeeOutput( new OutputTo(baos), file.toPath() ) ) ), new TextIs( new TextOf(file.toPath()) ) ).affirm(); }
Example #10
Source File: JoinedTest.java From cactoos with MIT License | 6 votes |
@Test public void removeAll() { final List<String> joined = new Joined<String>( new ListOf<>( JoinedTest.LITERAL_ONE, JoinedTest.LITERAL_TWO ), new ListOf<>(JoinedTest.LITERAL_THREE) ); joined.removeAll( new ListOf<>( JoinedTest.LITERAL_TWO, JoinedTest.LITERAL_THREE ) ); new Assertion<>( "must be able to removeAll elements specified", joined, new IsEqual<>( new ListOf<>( JoinedTest.LITERAL_ONE ) ) ).affirm(); }
Example #11
Source File: TeeOutputTest.java From cactoos with MIT License | 6 votes |
@Test public void copiesWithWriterAndCharset() { final ByteArrayOutputStream baos = new ByteArrayOutputStream(); new Assertion<>( "Can't copy Output with writer and charset", new TeeInput( new InputOf( "Hello, товарищ! writer and charset" ), new TeeOutput( new OutputTo(baos), new WriterTo(new ByteArrayOutputStream()), StandardCharsets.UTF_8 ) ), new InputHasContent( new TextOf(baos::toByteArray, StandardCharsets.UTF_8) ) ).affirm(); }
Example #12
Source File: CheckedInputTest.java From cactoos with MIT License | 6 votes |
@Test public void extraWrappingIgnored() { try { new CheckedInput<>( () -> { throw new IOException("runtime3"); }, IOException::new ).stream(); } catch (final IOException exp) { new Assertion<>( "must not add extra wrapping of IOException", exp.getCause(), new IsNull<>() ).affirm(); } }
Example #13
Source File: SkeletonTest.java From jpeek with MIT License | 6 votes |
@Test public void createsXml() { new Assertion<>( "Must overload bar's methods", XhtmlMatchers.xhtml( new Skeleton( new FakeBase("OverloadMethods", "Bar") ).xml().toString() ), XhtmlMatchers.hasXPaths( // @checkstyle LineLength (10 lines) "/skeleton/app/package[count(class)=2]", "//class[@id='Bar']/methods[count(method)=5]", "//class[@id='OverloadMethods']/methods[count(method)=5]", "//method[@name='<init>' and @ctor='true']", "//class[@id='Bar']//method[@name='getKey']/ops[count(op)=3]", "//class[@id='Bar']//method[@name='getKey']/ops/op[@code='put_static' and .='Bar.singleton']", "//class[@id='Bar']//method[@name='getKey']/ops/op[@code='call']/name[text() ='java.lang.String.length']", "//class[@id='Bar']//method[@name='getKey']/ops/op[@code='get' and .='key']", "//class[@id='Bar']//method[@name='<init>']/ops[count(op)=4]" ) ).affirm(); }
Example #14
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 #15
Source File: TeeInputFromInputTest.java From cactoos with MIT License | 6 votes |
@Test public void copiesFromInputWithCharsetByNameAndSizeToWriter() throws Exception { final String input = "Hello, товарищ writer #6 äÄ üÜ öÖ and ß"; final File output = this.folder.newFile(); new Assertion<>( "Must copy from input with charset by name and size to output", new TeeInput( new InputOf(input), new WriterTo(output), StandardCharsets.UTF_8.name(), input.length() ), new InputHasContent(input) ).affirm(); }
Example #16
Source File: CollectionOfTest.java From cactoos with MIT License | 5 votes |
@Test public void testToStringEmpty() { new Assertion<>( "Wrong toString output. Expected \"[]\".", new CollectionOf<>(new ListOf<>()).toString(), new IsEqual<>("[]") ).affirm(); }
Example #17
Source File: LengthOfTest.java From cactoos with MIT License | 5 votes |
@Test public void lengthOfInputWithFloatValue() { new Assertion<>( "Must calculate length of input with float value", new LengthOf( new InputOf("Hello3") ).floatValue(), new IsEqual<>(6.0f) ).affirm(); }
Example #18
Source File: TeeInputFromCharSequenceTest.java From cactoos with MIT License | 5 votes |
@Test public void copiesFromCharSequenceToFile() throws IOException { final String input = "Hello, товарищ file #1 äÄ üÜ öÖ and ß"; final File output = this.folder.newFile(); new LengthOf( new TeeInput(input, output) ).intValue(); new Assertion<>( "char sequence must be copied to the file", new InputOf(output), new InputHasContent(input) ).affirm(); }
Example #19
Source File: AvgOfTest.java From cactoos with MIT License | 5 votes |
@Test public void withFloatCollectionFloatValue() { new Assertion<>( "Average of values in float collection must be float value", new AvgOf( 1.0f, 2.0f, 3.0f, 4.0f ).floatValue(), Matchers.equalTo(2.5f) ).affirm(); }
Example #20
Source File: TextOfTest.java From cactoos with MIT License | 5 votes |
@Test public void readsLocalDateFormattedWithFormatString() { final LocalDate date = LocalDate.of(2017, 12, 13); new Assertion<>( "Can't format a LocalDate with format.", new TextOf(date, "yyyy-MM-dd HH:mm:ss"), new TextIs("2017-12-13 00:00:00") ).affirm(); }
Example #21
Source File: LengthOfTest.java From cactoos with MIT License | 5 votes |
@Test public void lengthOfWithFloatValue() { new Assertion<>( "Must calculate length of iterable for float", new LengthOf( new IterableOf<>(1, 2, 3, 4) ).floatValue(), new IsEqual<>(4.0f) ).affirm(); }
Example #22
Source File: DivisionOfTest.java From cactoos with MIT License | 5 votes |
/** * Ensures that division of int numbers return proper value. */ @Test public void dividesIntNumbers() { new Assertion<>( "Must divide int numbers", new DivisionOf(4, 2).intValue(), new IsEqual<>(2) ).affirm(); }
Example #23
Source File: TeeInputFromInputTest.java From cactoos with MIT License | 5 votes |
@Test public void copiesFromInputToFile() throws IOException { final String input = "Hello, товарищ file #1 äÄ üÜ öÖ and ß"; final File output = this.folder.newFile(); new Assertion<>( "Must copy from input to the output file", new TeeInput( new InputOf(input), output ), new InputHasContent(input) ).affirm(); }
Example #24
Source File: InputStreamOfTest.java From cactoos with MIT License | 5 votes |
@Test public void readsFromReader() { final String content = "Hello, дорогой товарищ!"; new Assertion<>( "Can't read from reader", new InputOf(new InputStreamOf(new StringReader(content))), new InputHasContent(content) ); }
Example #25
Source File: SortedTest.java From cactoos with MIT License | 5 votes |
@Test public void returnsTailset() { new Assertion<>( "Must return sorted tailset", new Sorted<>(Integer::compareTo, 3, 6, 1, 9, 3).tailSet(6), new IsIterableContainingInOrder<>( new ListOf<Matcher<? super Integer>>( new IsEqual<>(6), new IsEqual<>(9) ) ) ).affirm(); }
Example #26
Source File: BiProcNoNullsTest.java From cactoos with MIT License | 5 votes |
@Test public void okForNoNulls() throws Exception { final AtomicInteger counter = new AtomicInteger(); new BiProcNoNulls<>( (AtomicInteger ctr, Object second) -> { ctr.incrementAndGet(); } ).exec(counter, new Object()); new Assertion<>( "Can't invoke the \"BiProc.exec\" method", counter.get(), new IsEqual<>(1) ).affirm(); }
Example #27
Source File: ReportDataTest.java From jpeek with MIT License | 5 votes |
@Test public void reportsMean() throws Exception { final String name = "whats"; final double mean = 0; final double sigma = 1; final ReportData data = new ReportData(name, ReportDataTest.args(), mean, sigma); new Assertion<>( "Must returns mean", data.mean(), new IsEqual<>(mean) ).affirm(); }
Example #28
Source File: ContainsTest.java From cactoos with MIT License | 5 votes |
@Test public void textDoesNotContainString() { new Assertion<>( "Text does not contain other String", new Contains( new TextOf("Stack Overflow"), "nope" ), new ScalarHasValue<>(Boolean.FALSE) ).affirm(); }
Example #29
Source File: DyNumTest.java From jpeek with MIT License | 5 votes |
@Test public void testConstructDyNumFromString() { final double number = 2.0d; new Assertion<>( "Double values should be equal", new DyNum( String.valueOf(number) ).doubleValue(), new IsEqual<>(number) ).affirm(); }
Example #30
Source File: ReaderOfTest.java From cactoos with MIT License | 5 votes |
@Test public void readsInputStream() throws Exception { final String input = "InputStream on äÄ üÜ öÖ ß жш"; new Assertion<>( "Must read from stream", new TextOf(new ReaderOf(new InputStreamOf(input))), new TextIs(input) ).affirm(); }