diff --git a/src/main/java/org/cactoos/io/LengthOfInput.java b/src/main/java/org/cactoos/io/LengthOfInput.java index 46b5260640..33dc108df4 100644 --- a/src/main/java/org/cactoos/io/LengthOfInput.java +++ b/src/main/java/org/cactoos/io/LengthOfInput.java @@ -78,7 +78,7 @@ public Long asValue() throws IOException { if (len > 0) { length += (long) len; } - if (len != buf.length) { + if (len < 0) { break; } } diff --git a/src/test/java/org/cactoos/io/LengthOfInputTest.java b/src/test/java/org/cactoos/io/LengthOfInputTest.java index 1e34a08b31..21e4df09f3 100644 --- a/src/test/java/org/cactoos/io/LengthOfInputTest.java +++ b/src/test/java/org/cactoos/io/LengthOfInputTest.java @@ -23,11 +23,13 @@ */ package org.cactoos.io; +import java.io.IOException; import java.nio.charset.StandardCharsets; import org.cactoos.ScalarHasValue; import org.cactoos.text.StringAsText; import org.cactoos.text.TextAsBytes; import org.hamcrest.MatcherAssert; +import org.hamcrest.Matchers; import org.junit.Test; /** @@ -66,4 +68,19 @@ public void calculatesZeroLength() { ); } + @Test + public void readsRealUrl() throws IOException { + MatcherAssert.assertThat( + "Can't calculate length of a real page at the URL", + new LengthOfInput( + new UrlAsInput( + // @checkstyle LineLength (1 line) + "https://raw.githubusercontent.com/yegor256/cactoos/0.5/pom.xml" + ) + ).asValue(), + // @checkstyle MagicNumber (1 line) + Matchers.equalTo(5960L) + ); + } + } diff --git a/src/test/java/org/cactoos/io/StickyInputTest.java b/src/test/java/org/cactoos/io/StickyInputTest.java index ddfb1cbe0f..29db28038c 100644 --- a/src/test/java/org/cactoos/io/StickyInputTest.java +++ b/src/test/java/org/cactoos/io/StickyInputTest.java @@ -23,9 +23,12 @@ */ package org.cactoos.io; +import org.cactoos.TextHasString; import org.cactoos.func.FuncAsMatcher; import org.cactoos.func.RepeatedFunc; +import org.cactoos.text.BytesAsText; import org.hamcrest.MatcherAssert; +import org.hamcrest.Matchers; import org.junit.Test; /** @@ -34,6 +37,7 @@ * @version $Id$ * @since 0.6 * @checkstyle JavadocMethodCheck (500 lines) + * @checkstyle ClassDataAbstractionCouplingCheck (500 lines) */ public final class StickyInputTest { @@ -58,4 +62,24 @@ public void readsFileContent() { ); } + @Test + public void readsRealUrl() { + MatcherAssert.assertThat( + "Can't fetch text page from the URL", + new BytesAsText( + new InputAsBytes( + new StickyInput( + new UrlAsInput( + // @checkstyle LineLength (1 line) + "https://raw.githubusercontent.com/yegor256/cactoos/0.5/pom.xml" + ) + ) + ) + ), + new TextHasString( + Matchers.endsWith("\n") + ) + ); + } + }