org.llorllale.cactoos.matchers.EndsWith Java Examples
The following examples show how to use
org.llorllale.cactoos.matchers.EndsWith.
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: HtHeadTest.java From cactoos-http with MIT License | 6 votes |
@Test public void largeText() throws Exception { //@checkstyle MagicNumberCheck (1 lines) final byte[] bytes = new byte[18000]; new Random().nextBytes(bytes); new Assertion<>( "Header does not have text/plain header", new TextOf( new HtHead( new InputOf( new Joined( "\r\n", "HTTP/1.1 200 OK", "Content-type: text/plain", "", new TextOf(new BytesOf(bytes)).asString() ) ) ) ), new EndsWith("text/plain") ).affirm(); }
Example #2
Source File: RsXsltTest.java From takes with MIT License | 6 votes |
/** * RsXSLT can convert XML to plain text. * @throws IOException If some problem inside */ @Test public void convertsXmlToPlainText() throws IOException { final Text xml = new Joined( " ", "<?xml-stylesheet href='/x.xsl' type='text/xsl'?>", "<p><name>Jeffrey</name></p>" ); final Text xsl = new Joined( " ", "<stylesheet xmlns='http://www.w3.org/1999/XSL/Transform' ", " xmlns:x='http://www.w3.org/1999/xhtml' version='2.0' >", "<output method='text'/><template match='/'>", "Hey, <value-of select='/p/name'/>!</template></stylesheet>" ); MatcherAssert.assertThat( new RsPrint( new RsXslt( new RsText(new InputStreamOf(xml)), (href, base) -> new StreamSource(new InputStreamOf(xsl)) ) ), new EndsWith("Hey, Jeffrey!") ); }
Example #3
Source File: BytesOfTest.java From cactoos with MIT License | 6 votes |
@Test public void readsInputIntoBytesWithSmallBuffer() throws Exception { new Assertion<>( "must read bytes from Input with a small reading buffer", new TextOf( new BytesOf( new InputOf("Hello, товарищ!"), 2 ) ), Matchers.allOf( new StartsWith("Hello,"), new EndsWith("товарищ!") ) ).affirm(); }
Example #4
Source File: StickyTest.java From cactoos with MIT License | 6 votes |
@Test public void readsRealUrl() throws MalformedURLException { new Assertion<>( "Can't fetch text page from the URL", new TextOf( new Sticky( new InputOf( new URL( // @checkstyle LineLength (1 line) "file:src/test/resources/org/cactoos/large-text.txt" ) ) ) ), new EndsWith("est laborum.\n") ).affirm(); }
Example #5
Source File: InputOfTest.java From cactoos with MIT License | 6 votes |
@Test public void readsEncodedArrayOfChars() throws Exception { new Assertion<>( "must read array of encoded chars.", new TextOf( new BytesOf( new InputOf( new char[]{ 'O', ' ', 'q', 'u', 'e', ' ', 's', 'e', 'r', 'a', ' ', 'q', 'u', 'e', ' ', 's', 'e', 'r', 'a', }, StandardCharsets.UTF_8 ) ), StandardCharsets.UTF_8 ), new AllOf<>( new IterableOf<>( new StartsWith("O que sera"), new EndsWith(" que sera") ) ) ).affirm(); }
Example #6
Source File: InputOfTest.java From cactoos with MIT License | 6 votes |
@Test public void readsArrayOfChars() throws Exception { new Assertion<>( "must read array of chars.", new TextOf( new BytesOf( new InputOf( 'H', 'o', 'l', 'd', ' ', 'i', 'n', 'f', 'i', 'n', 'i', 't', 'y' ) ) ), new AllOf<>( new IterableOf<>( new StartsWith("Hold "), new EndsWith("infinity") ) ) ).affirm(); }
Example #7
Source File: InputOfTest.java From cactoos with MIT License | 6 votes |
@Test public void readsStringBuffer() throws Exception { final String starts = "The future "; final String ends = "is now!"; new Assertion<>( "must receive a string buffer", new TextOf( new BytesOf( new InputOf( new StringBuffer(starts) .append(ends) ) ) ), new AllOf<>( new IterableOf<>( new StartsWith(starts), new EndsWith(ends) ) ) ).affirm(); }
Example #8
Source File: InputOfTest.java From cactoos with MIT License | 6 votes |
@Test public void readsStringBuilder() throws Exception { final String starts = "Name it, "; final String ends = "then it exists!"; new Assertion<>( "must receive a string builder", new TextOf( new BytesOf( new InputOf( new StringBuilder(starts) .append(ends) ) ) ), new AllOf<>( new IterableOf<>( new StartsWith(starts), new EndsWith(ends) ) ) ).affirm(); }
Example #9
Source File: InputOfTest.java From cactoos with MIT License | 6 votes |
@Test public void readsStringIntoBytes() throws Exception { new Assertion<>( "must read bytes from Input", new TextOf( new BytesOf( new InputOf("Hello, друг!") ), StandardCharsets.UTF_8 ), new AllOf<>( new IterableOf<>( new StartsWith("Hello, "), new EndsWith("друг!") ) ) ).affirm(); }
Example #10
Source File: InputAsBytesTest.java From cactoos with MIT License | 6 votes |
@Test public void readsInputIntoBytesWithSmallBuffer() throws Exception { new Assertion<>( "must read bytes from Input with a small reading buffer", new TextOf( new InputAsBytes( new InputOf( new BytesOf( new TextOf("Hello, товарищ!") ) ), 2 ), StandardCharsets.UTF_8 ), new AllOf<>( new IterableOf<>( new StartsWith("Hello,"), new EndsWith("товарищ!") ) ) ).affirm(); }
Example #11
Source File: InputAsBytesTest.java From cactoos with MIT License | 6 votes |
@Test public void readsInputIntoBytes() throws Exception { new Assertion<>( "must read bytes from Input", new TextOf( new InputAsBytes( new InputOf( new BytesOf( new TextOf("Hello, друг!") ) ) ), StandardCharsets.UTF_8 ), new AllOf<>( new IterableOf<>( new StartsWith("Hello, "), new EndsWith("друг!") ) ) ).affirm(); }
Example #12
Source File: HtHeadTest.java From cactoos-http with MIT License | 6 votes |
@Test public void takesHeadOutOfHttpResponse() { new Assertion<>( "Header does not have 'text/plain'", new TextOf( new HtHead( new InputOf( new Joined( "\r\n", "HTTP/1.1 200 OK", "Content-type: text/plain", "", "Hello, dude!" ) ) ) ), new EndsWith("text/plain") ).affirm(); }
Example #13
Source File: InputOfTest.java From cactoos with MIT License | 5 votes |
@Test public void readsAlternativeInputForFileCase() { new Assertion<>( "must read alternative source from file not found", new TextOf( new InputWithFallback( new InputOf( new File("/this-file-does-not-exist.txt") ), new InputOf(new TextOf("Alternative text!")) ) ), new EndsWith("text!") ).affirm(); }
Example #14
Source File: InputWithFallbackTest.java From cactoos with MIT License | 5 votes |
@Test public void readsAlternativeInputUri() { new Assertion<>( "Can't read alternative source from URI", new TextOf( new InputWithFallback( () -> { throw new IOException("Always fails!"); }, new InputOf("it works!") ) ), new EndsWith("works!") ).affirm(); }
Example #15
Source File: InputWithFallbackTest.java From cactoos with MIT License | 5 votes |
@Test public void readsAlternativeInput() { new Assertion<>( "Can't read alternative source", new TextOf( new InputWithFallback( new InputOf( new File("/this-file-is-absent-for-sure.txt") ), new InputOf("hello, world!") ) ), new EndsWith("world!") ).affirm(); }
Example #16
Source File: TempFileTest.java From cactoos with MIT License | 5 votes |
@Test public void createFileWithSuffix() throws Exception { final String suffix = new FormattedText( "randomSuffix%s", System.currentTimeMillis() ).asString(); try (TempFile file = new TempFile("", suffix)) { new Assertion<>( "File must be created with the given suffix", new TextOf(file.value().getFileName().toString()), new EndsWith(suffix) ).affirm(); } }
Example #17
Source File: BytesOfTest.java From cactoos with MIT License | 5 votes |
@Test public void readsInputIntoBytes() throws Exception { new Assertion<>( "must read bytes from Input", new TextOf( new BytesOf( new InputOf("Hello, друг!") ) ), Matchers.allOf( new StartsWith("Hello, "), new EndsWith("друг!") ) ).affirm(); }
Example #18
Source File: RsXsltTest.java From takes with MIT License | 5 votes |
/** * RsXSLT closes decorated Response body's InputStream when XML conversion * is done. * @throws Exception If some problem inside */ @Test public void closesDecoratedResponseInputStream() throws Exception { final Text xml = new Joined( " ", "<?xml-stylesheet href='/b.xsl' type='text/xsl'?>", "<subject>World</subject>" ); final Text xsl = new Joined( " ", "<stylesheet xmlns='http://www.w3.org/1999/XSL/Transform' ", " xmlns:x='http://www.w3.org/1999/xhtml' version='2.0' >", "<output method='text'/><template match='/'> ", "Hello, <value-of select='/subject'/>!</template></stylesheet>" ); final StateAwareInputStream stream = new StateAwareInputStream( new InputStreamOf(xml) ); MatcherAssert.assertThat( new RsPrint( new RsXslt( new RsText(stream), (href, base) -> new StreamSource(new InputStreamOf(xsl)) ) ), new EndsWith("Hello, World!") ); MatcherAssert.assertThat( stream.isClosed(), Matchers.is(true) ); }
Example #19
Source File: HtHeadTest.java From cactoos-http with MIT License | 4 votes |
@Test public void edgeOfTheBlockTearing() throws Exception { final int size = 16384; final Text header = new Joined( "\r\n", "HTTP/1.1 200 OK", "Referer: http://en.wikipedia.org/wiki/Main_Page#\0", "Content-type: text/plain", "" ); final Text block = new Replaced( header, "\0", new Repeated( "x", size - header.asString().length() + 1 ).asString() ); new Assertion<>( "make sure the constructed block is exact size", block.asString().length(), new IsEqual<>( size ) ).affirm(); new Assertion<>( String.format("Edge of the block tearing for size: %s", size), new TextOf( new HtHead( new InputOf( new Joined( "\r\n", block.asString(), "", "body here" ) ) ) ), Matchers.allOf( new StartsWith("HTTP"), new TextHasString("OK\r\nReferer"), new EndsWith("text/plain") ) ).affirm(); }
Example #20
Source File: RsXsltTest.java From takes with MIT License | 4 votes |
/** * RsXSLT can resolve in classpath. * @throws IOException If some problem inside */ @Test public void resolvesInClasspath() throws IOException { MatcherAssert.assertThat( new RsPrint( new RsXslt( new RsText( new InputStreamOf( new Joined( " ", "<?xml-stylesheet", " href='/org/takes/rs/simple.xsl?0'", " type='text/xsl'?>", "<p><name>Bobby</name></p>" ) ) ) ) ), new EndsWith("Hello, Bobby!") ); MatcherAssert.assertThat( new RsPrint( new RsXslt( new RsText( new InputStreamOf( new Joined( " ", "<?xml-stylesheet ", " href='/org/takes/rs/simple.xsl'", " type='text/xsl' ?>", "<p><name>Dan</name></p>" ) ) ) ) ), new EndsWith("Hello, Dan!") ); MatcherAssert.assertThat( new RsPrint( new RsXslt( new RsText( new InputStreamOf( new Joined( " ", "<?xml-stylesheet ", " href='/org/takes/rs/includes.xsl'", " type='text/xsl' ?>", "<p><name>Miranda</name></p>" ) ) ) ) ), new EndsWith("Hello, Miranda!") ); }