From 306368523adf98e6d07cd09dccd9bcaecce62c8e Mon Sep 17 00:00:00 2001 From: iiylll Date: Tue, 28 Apr 2020 03:39:46 +0200 Subject: [PATCH 01/10] fixed IterableOf.equals and add required tests --- .../java/org/cactoos/iterable/IterableOf.java | 15 ++++++++------- .../org/cactoos/iterable/IterableOfTest.java | 19 +++++++++++++++++++ 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/cactoos/iterable/IterableOf.java b/src/main/java/org/cactoos/iterable/IterableOf.java index a42329ea5a..784b86d95f 100644 --- a/src/main/java/org/cactoos/iterable/IterableOf.java +++ b/src/main/java/org/cactoos/iterable/IterableOf.java @@ -31,6 +31,7 @@ import org.cactoos.func.UncheckedFunc; import org.cactoos.iterator.IteratorOf; import org.cactoos.scalar.And; +import org.cactoos.scalar.False; import org.cactoos.scalar.Folded; import org.cactoos.scalar.Or; import org.cactoos.scalar.Sticky; @@ -155,13 +156,13 @@ public boolean equals(final Object other) { () -> Iterable.class.isAssignableFrom(other.getClass()), () -> { final Iterable compared = (Iterable) other; - final Iterator iterator = compared.iterator(); - return new Unchecked<>( - new And( - (X input) -> input.equals(iterator.next()), - this - ) - ).value(); + final Iterator ftr = this.iterator(); + final Iterator str = compared.iterator(); + boolean failed = false; + while (ftr.hasNext() && str.hasNext() && (!failed)) { + failed = !ftr.next().equals(str.next()); + } + return !failed && !ftr.hasNext() && !str.hasNext(); } ) ) diff --git a/src/test/java/org/cactoos/iterable/IterableOfTest.java b/src/test/java/org/cactoos/iterable/IterableOfTest.java index 2df0be5e9e..1d838fde66 100644 --- a/src/test/java/org/cactoos/iterable/IterableOfTest.java +++ b/src/test/java/org/cactoos/iterable/IterableOfTest.java @@ -35,6 +35,7 @@ import org.hamcrest.core.IsNot; import org.junit.Test; import org.llorllale.cactoos.matchers.Assertion; +import org.llorllale.cactoos.matchers.IsTrue; /** * Test case for {@link IterableOf}. @@ -105,6 +106,24 @@ public void containAllPagedContentInOrder() throws Exception { ); } + @Test + public void isNotEqualsToIterableWithMoreElements() { + new Assertion<>( + "Must compare iterables and second one is bigger", + new IterableOf<>("a", "b").equals(new IterableOf<>("a")), + new IsNot<>(new IsTrue()) + ).affirm(); + } + + @Test + public void isNotEqualsToIterableWithLessElements() { + new Assertion<>( + "Must compare iterables and first one is bigger", + new IterableOf<>("a").equals(new IterableOf<>("a", "b")), + new IsNot<>(new IsTrue()) + ).affirm(); + } + @Test @SuppressWarnings("unchecked") public void reportTotalPagedLength() throws Exception { From 91784509897858626f6ab11a7f0ba949de245599 Mon Sep 17 00:00:00 2001 From: iiylll Date: Tue, 28 Apr 2020 03:40:47 +0200 Subject: [PATCH 02/10] remove unused import --- src/main/java/org/cactoos/iterable/IterableOf.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/org/cactoos/iterable/IterableOf.java b/src/main/java/org/cactoos/iterable/IterableOf.java index 784b86d95f..dc422ffd63 100644 --- a/src/main/java/org/cactoos/iterable/IterableOf.java +++ b/src/main/java/org/cactoos/iterable/IterableOf.java @@ -31,7 +31,6 @@ import org.cactoos.func.UncheckedFunc; import org.cactoos.iterator.IteratorOf; import org.cactoos.scalar.And; -import org.cactoos.scalar.False; import org.cactoos.scalar.Folded; import org.cactoos.scalar.Or; import org.cactoos.scalar.Sticky; From 570009949e156d040061d2c498ef8512e16a93ea Mon Sep 17 00:00:00 2001 From: iiylll Date: Tue, 28 Apr 2020 13:19:52 +0200 Subject: [PATCH 03/10] - Fixed Matched class - Changed IterableOf.equals style for more declarative. --- .../java/org/cactoos/iterable/IterableOf.java | 26 ++++++++++++----- .../java/org/cactoos/iterable/Matched.java | 4 +-- .../org/cactoos/iterable/MatchedTest.java | 28 +++++++++++++++++++ 3 files changed, 49 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/cactoos/iterable/IterableOf.java b/src/main/java/org/cactoos/iterable/IterableOf.java index dc422ffd63..d6bea89d6f 100644 --- a/src/main/java/org/cactoos/iterable/IterableOf.java +++ b/src/main/java/org/cactoos/iterable/IterableOf.java @@ -31,10 +31,13 @@ import org.cactoos.func.UncheckedFunc; import org.cactoos.iterator.IteratorOf; import org.cactoos.scalar.And; +import org.cactoos.scalar.Checked; +import org.cactoos.scalar.False; import org.cactoos.scalar.Folded; import org.cactoos.scalar.Or; import org.cactoos.scalar.Sticky; import org.cactoos.scalar.SumOfInt; +import org.cactoos.scalar.True; import org.cactoos.scalar.Unchecked; import org.cactoos.text.TextOf; import org.cactoos.text.UncheckedText; @@ -146,6 +149,7 @@ public Iterator iterator() { @Override @edu.umd.cs.findbugs.annotations.SuppressFBWarnings("EQ_UNUSUAL") + @SuppressWarnings (value = "unchecked") public boolean equals(final Object other) { return new Unchecked<>( new Or( @@ -154,14 +158,22 @@ public boolean equals(final Object other) { () -> other != null, () -> Iterable.class.isAssignableFrom(other.getClass()), () -> { - final Iterable compared = (Iterable) other; - final Iterator ftr = this.iterator(); - final Iterator str = compared.iterator(); - boolean failed = false; - while (ftr.hasNext() && str.hasNext() && (!failed)) { - failed = !ftr.next().equals(str.next()); + final Iterable compared = (Iterable) other; + boolean equals; + try { + equals = new Checked<>( + new And( + (X value) -> new True().value(), + new Matched<>( + this, + compared + ) + ), e -> new IllegalStateException() + ).value(); + } catch (final IllegalStateException exception) { + equals = new False().value(); } - return !failed && !ftr.hasNext() && !str.hasNext(); + return equals; } ) ) diff --git a/src/main/java/org/cactoos/iterable/Matched.java b/src/main/java/org/cactoos/iterable/Matched.java index 88edd13856..5ec85904d4 100644 --- a/src/main/java/org/cactoos/iterable/Matched.java +++ b/src/main/java/org/cactoos/iterable/Matched.java @@ -73,8 +73,8 @@ public Matched( final Iterator ftr = fst.iterator(); final Iterator str = snd.iterator(); final List rslt = new LinkedList<>(); - while (ftr.hasNext()) { - if (!str.hasNext()) { + while (ftr.hasNext() || str.hasNext()) { + if (!str.hasNext() || !ftr.hasNext()) { throw new IllegalStateException( "Size mismatch of iterators" ); diff --git a/src/test/java/org/cactoos/iterable/MatchedTest.java b/src/test/java/org/cactoos/iterable/MatchedTest.java index 9d7afda673..f4bb8c7701 100644 --- a/src/test/java/org/cactoos/iterable/MatchedTest.java +++ b/src/test/java/org/cactoos/iterable/MatchedTest.java @@ -28,6 +28,8 @@ import org.hamcrest.Matchers; import org.junit.Assert; import org.junit.Test; +import org.llorllale.cactoos.matchers.Assertion; +import org.llorllale.cactoos.matchers.Throws; /** * Test case for {@link Matched}. @@ -51,6 +53,32 @@ public void iterator() { ); } + @Test + public void noCorrelationWithBiggerSecondIterable() throws IllegalStateException { + new Assertion<>( + "All elements have correlation function as `endsWith`", + () -> new Matched<>( + (fst, snd) -> fst.endsWith("elem") && snd.endsWith("elem"), + new IterableOf<>("1st elem", "2nd elem"), + new IterableOf<>("`A` elem", "`B` elem", "'C' elem") + ).iterator(), + new Throws<>(IllegalStateException.class) + ).affirm(); + } + + @Test + public void noCorrelationWithSmallerSecondIterable() throws IllegalStateException { + new Assertion<>( + "All elements have correlation function as `endsWith`", + () -> new Matched<>( + (fst, snd) -> fst.endsWith("elem") && snd.endsWith("elem"), + new IterableOf<>("1st elem", "2nd elem", "3rd elem"), + new IterableOf<>("`A` elem", "`B` elem") + ).iterator(), + new Throws<>(IllegalStateException.class) + ).affirm(); + } + @Test public void endsWith() { MatcherAssert.assertThat( From 7584ff817093dee60d1a8cb19eb9707c623577d5 Mon Sep 17 00:00:00 2001 From: iiylll Date: Tue, 28 Apr 2020 23:40:02 +0200 Subject: [PATCH 04/10] Use ScalarWithFallback object instead of try-catch operations --- .../java/org/cactoos/iterable/IterableOf.java | 33 ++++++++++--------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/src/main/java/org/cactoos/iterable/IterableOf.java b/src/main/java/org/cactoos/iterable/IterableOf.java index d6bea89d6f..cecacb800c 100644 --- a/src/main/java/org/cactoos/iterable/IterableOf.java +++ b/src/main/java/org/cactoos/iterable/IterableOf.java @@ -31,10 +31,11 @@ import org.cactoos.func.UncheckedFunc; import org.cactoos.iterator.IteratorOf; import org.cactoos.scalar.And; -import org.cactoos.scalar.Checked; +import org.cactoos.scalar.FallbackFrom; import org.cactoos.scalar.False; import org.cactoos.scalar.Folded; import org.cactoos.scalar.Or; +import org.cactoos.scalar.ScalarWithFallback; import org.cactoos.scalar.Sticky; import org.cactoos.scalar.SumOfInt; import org.cactoos.scalar.True; @@ -159,21 +160,21 @@ public boolean equals(final Object other) { () -> Iterable.class.isAssignableFrom(other.getClass()), () -> { final Iterable compared = (Iterable) other; - boolean equals; - try { - equals = new Checked<>( - new And( - (X value) -> new True().value(), - new Matched<>( - this, - compared - ) - ), e -> new IllegalStateException() - ).value(); - } catch (final IllegalStateException exception) { - equals = new False().value(); - } - return equals; + return new ScalarWithFallback<>( + new And( + (X value) -> new True().value(), + new Matched<>( + this, + compared + ) + ), + new IterableOf<>( + new FallbackFrom<>( + IllegalStateException.class, + ex -> new False().value() + ) + ) + ).value(); } ) ) From 0603544522c762faf5b42faf2fb1930314500749 Mon Sep 17 00:00:00 2001 From: iiylll Date: Sat, 2 May 2020 00:09:25 +0200 Subject: [PATCH 05/10] simplify the code --- src/main/java/org/cactoos/iterable/IterableOf.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/cactoos/iterable/IterableOf.java b/src/main/java/org/cactoos/iterable/IterableOf.java index cecacb800c..99c4ae3c87 100644 --- a/src/main/java/org/cactoos/iterable/IterableOf.java +++ b/src/main/java/org/cactoos/iterable/IterableOf.java @@ -162,7 +162,7 @@ public boolean equals(final Object other) { final Iterable compared = (Iterable) other; return new ScalarWithFallback<>( new And( - (X value) -> new True().value(), + (X value) -> true, new Matched<>( this, compared @@ -171,7 +171,7 @@ public boolean equals(final Object other) { new IterableOf<>( new FallbackFrom<>( IllegalStateException.class, - ex -> new False().value() + ex -> false ) ) ).value(); From 780b224cb7f8e2a3c23ecac8db93fedf8933d14b Mon Sep 17 00:00:00 2001 From: iakunin Date: Sat, 2 May 2020 13:57:12 +0300 Subject: [PATCH 06/10] ScalarWithFallback: extra ctors were added --- .../cactoos/scalar/ScalarWithFallback.java | 37 +++++++++++ .../scalar/ScalarWithFallbackTest.java | 62 +++++++++++++++++++ 2 files changed, 99 insertions(+) diff --git a/src/main/java/org/cactoos/scalar/ScalarWithFallback.java b/src/main/java/org/cactoos/scalar/ScalarWithFallback.java index 8747e9356a..52b63b354a 100644 --- a/src/main/java/org/cactoos/scalar/ScalarWithFallback.java +++ b/src/main/java/org/cactoos/scalar/ScalarWithFallback.java @@ -25,8 +25,10 @@ import java.util.Comparator; import java.util.Map; +import org.cactoos.Func; import org.cactoos.Scalar; import org.cactoos.func.FuncWithFallback; +import org.cactoos.iterable.IterableOf; import org.cactoos.iterator.Filtered; import org.cactoos.iterator.Sorted; import org.cactoos.map.MapOf; @@ -52,6 +54,41 @@ public final class ScalarWithFallback implements Scalar { */ private final Iterable> fallbacks; + /** + * Ctor. + * @param origin Original scalar + * @param exception Supported exception type + * @param fallback Function that converts the given exception into fallback value + */ + public ScalarWithFallback( + final Scalar origin, + final Class exception, + final Func fallback + ) { + this(origin, new IterableOf>(exception), fallback); + } + + /** + * Ctor. + * @param origin Original scalar + * @param exceptions Supported exceptions types + * @param fallback Function that converts the given exception into fallback value + */ + public ScalarWithFallback( + final Scalar origin, + final Iterable> exceptions, + final Func fallback + ) { + this( + origin, + new IterableOf>( + new FallbackFrom<>( + exceptions, fallback + ) + ) + ); + } + /** * Ctor. * @param origin Original scalar diff --git a/src/test/java/org/cactoos/scalar/ScalarWithFallbackTest.java b/src/test/java/org/cactoos/scalar/ScalarWithFallbackTest.java index 9511692de2..67efbed940 100644 --- a/src/test/java/org/cactoos/scalar/ScalarWithFallbackTest.java +++ b/src/test/java/org/cactoos/scalar/ScalarWithFallbackTest.java @@ -29,6 +29,7 @@ import org.cactoos.iterable.IterableOf; import org.hamcrest.MatcherAssert; import org.junit.Test; +import org.llorllale.cactoos.matchers.Assertion; import org.llorllale.cactoos.matchers.ScalarHasValue; /** @@ -36,6 +37,7 @@ * * @since 0.31 * @checkstyle JavadocMethodCheck (500 lines) + * @checkstyle ClassDataAbstractionCouplingCheck (500 lines) */ @SuppressWarnings("unchecked") public final class ScalarWithFallbackTest { @@ -58,6 +60,34 @@ public void usesMainFunc() throws Exception { ); } + @Test + public void usesMainFuncFromExceptionAndFallback() throws Exception { + final String message = "Main function's result #1 (exp & flbck)"; + new Assertion<>( + "Using the main function if no exception (exp & flbck)", + new ScalarWithFallback<>( + () -> message, + IOException.class, + Throwable::getMessage + ), + new ScalarHasValue<>(message) + ).affirm(); + } + + @Test + public void usesMainFuncFromIterableExceptionAndFallback() throws Exception { + final String message = "Main function's result #1 (exp iterable & flbck)"; + new Assertion<>( + "Using the main function if no exception (exp iterable & flbck)", + new ScalarWithFallback<>( + () -> message, + new IterableOf<>(IOException.class), + Throwable::getMessage + ), + new ScalarHasValue<>(message) + ).affirm(); + } + @Test public void usesFallback() throws Exception { final String message = "Fallback from IOException"; @@ -78,6 +108,38 @@ public void usesFallback() throws Exception { ); } + @Test + public void usesFallbackFromExceptionAndFallback() throws Exception { + final String message = "Fallback from IOException (exp & flbck)"; + new Assertion<>( + "Using a single fallback in case of exception (exp & flbck)", + new ScalarWithFallback<>( + () -> { + throw new IOException("Failure with IOException (exp & flbck)"); + }, + IOException.class, + exp -> message + ), + new ScalarHasValue<>(message) + ).affirm(); + } + + @Test + public void usesFallbackFromIterableExceptionAndFallback() throws Exception { + final String message = "Fallback from IOException (exp iterable & flbck)"; + new Assertion<>( + "Using a single fallback in case of exception (exp iterable & flbck)", + new ScalarWithFallback<>( + () -> { + throw new IOException("Failure with IOException (exp iterable & flbck)"); + }, + new IterableOf<>(IOException.class), + exp -> message + ), + new ScalarHasValue<>(message) + ).affirm(); + } + @Test public void usesFallbackOfInterruptedException() throws Exception { final String message = "Fallback from InterruptedException"; From 4c45c3eff872e622fb28307114cb8464a1344afc Mon Sep 17 00:00:00 2001 From: Andrew Korzhov Date: Sat, 2 May 2020 16:33:11 +0200 Subject: [PATCH 07/10] Test content of file, not the content of TeeInput --- .../org/cactoos/io/TeeInputFromBytesTest.java | 4 - .../cactoos/io/TeeInputFromCharArrayTest.java | 80 +++++++++---------- .../io/TeeInputFromCharSequenceTest.java | 4 + 3 files changed, 42 insertions(+), 46 deletions(-) diff --git a/src/test/java/org/cactoos/io/TeeInputFromBytesTest.java b/src/test/java/org/cactoos/io/TeeInputFromBytesTest.java index a3b5631d5b..1bba70d069 100644 --- a/src/test/java/org/cactoos/io/TeeInputFromBytesTest.java +++ b/src/test/java/org/cactoos/io/TeeInputFromBytesTest.java @@ -36,10 +36,6 @@ * Test case for {@link TeeInput}. Cases for ctors which use * {@link org.cactoos.Bytes} as an input. * @since 1.0 - * @todo #1341:30min Correct any TeeInput tests that are not testing if the - * path actually contains the content, just that TeeInput, as an Input,has - * the content. Solution: test the content of the file, not the content of - * teeinput (e.g. #1331). * @checkstyle JavadocMethodCheck (100 lines) * @checkstyle ClassDataAbstractionCouplingCheck (100 lines) */ diff --git a/src/test/java/org/cactoos/io/TeeInputFromCharArrayTest.java b/src/test/java/org/cactoos/io/TeeInputFromCharArrayTest.java index 81b790a7c4..7bfcba153d 100644 --- a/src/test/java/org/cactoos/io/TeeInputFromCharArrayTest.java +++ b/src/test/java/org/cactoos/io/TeeInputFromCharArrayTest.java @@ -26,6 +26,8 @@ import java.io.File; import java.io.IOException; import java.nio.charset.StandardCharsets; + +import org.cactoos.scalar.LengthOf; import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; @@ -52,13 +54,12 @@ public void copiesFromCharArrayWithCharsetToFile() throws IOException { final String input = "Hello, товарищ file #1 äÄ üÜ öÖ and ß"; final File output = this.folder.newFile(); + new LengthOf( + new TeeInput(input.toCharArray(), new OutputTo(output)) + ).intValue(); new Assertion<>( "char array must be copied to the file with charset UTF_8", - new TeeInput( - input.toCharArray(), - output, - StandardCharsets.UTF_8 - ), + new InputOf(output), new InputHasContent(input) ).affirm(); } @@ -69,13 +70,12 @@ public void copiesFromCharArrayWithCharsetByNameToFile() final String input = "Hello, товарищ file #2 äÄ üÜ öÖ and ß"; final File output = this.folder.newFile(); + new LengthOf( + new TeeInput(input.toCharArray(), new OutputTo(output), StandardCharsets.UTF_8.name()) + ).intValue(); new Assertion<>( "char array must be copied to the file with UTF_8 charset's name", - new TeeInput( - input.toCharArray(), - output, - StandardCharsets.UTF_8.name() - ), + new InputOf(output), new InputHasContent(input) ).affirm(); } @@ -85,12 +85,12 @@ public void copiesFromCharArrayToOutput() throws IOException { final String input = "Hello, товарищ output #1 äÄ üÜ öÖ and ß"; final File output = this.folder.newFile(); + new LengthOf( + new TeeInput(input.toCharArray(), new OutputTo(output), StandardCharsets.UTF_8.name()) + ).intValue(); new Assertion<>( "char array must be copied to the output", - new TeeInput( - input.toCharArray(), - new OutputTo(output) - ), + new InputOf(output), new InputHasContent(input) ).affirm(); } @@ -100,13 +100,12 @@ public void copiesFromCharArrayWithCharsetToOutput() throws IOException { final String input = "Hello, товарищ output #2 äÄ üÜ öÖ and ß"; final File output = this.folder.newFile(); + new LengthOf( + new TeeInput(input.toCharArray(), new OutputTo(output), StandardCharsets.UTF_8.name()) + ).intValue(); new Assertion<>( "char array must be copied to the output with UTF_8 charset", - new TeeInput( - input.toCharArray(), - new OutputTo(output), - StandardCharsets.UTF_8 - ), + new InputOf(output), new InputHasContent(input) ).affirm(); } @@ -117,13 +116,12 @@ public void copiesFromCharArrayWithCharsetByNameToOutput() final String input = "Hello, товарищ output #3 äÄ üÜ öÖ and ß"; final File output = this.folder.newFile(); + new LengthOf( + new TeeInput(input.toCharArray(), new OutputTo(output), StandardCharsets.UTF_8.name()) + ).intValue(); new Assertion<>( "char array must be copied to the output with UTF_8 charset's name", - new TeeInput( - input.toCharArray(), - new OutputTo(output), - StandardCharsets.UTF_8.name() - ), + new InputOf(output), new InputHasContent(input) ).affirm(); } @@ -133,12 +131,12 @@ public void copiesFromCharArrayToPath() throws IOException { final String input = "Hello, товарищ path #1 äÄ üÜ öÖ and ß"; final File output = this.folder.newFile(); + new LengthOf( + new TeeInput(input.toCharArray(), new OutputTo(output), StandardCharsets.UTF_8.name()) + ).intValue(); new Assertion<>( "char array must be copied to the path", - new TeeInput( - input.toCharArray(), - output.toPath() - ), + new InputOf(output), new InputHasContent(input) ).affirm(); } @@ -148,13 +146,12 @@ public void copiesFromCharArrayWithCharsetToPath() throws IOException { final String input = "Hello, товарищ path #2 äÄ üÜ öÖ and ß"; final File output = this.folder.newFile(); + new LengthOf( + new TeeInput(input.toCharArray(), new OutputTo(output), StandardCharsets.UTF_8.name()) + ).intValue(); new Assertion<>( "char array must be copied to the path with UTF_8 charset", - new TeeInput( - input.toCharArray(), - output.toPath(), - StandardCharsets.UTF_8 - ), + new InputOf(output), new InputHasContent(input) ).affirm(); } @@ -165,13 +162,12 @@ public void copiesFromCharArrayWithCharsetByNameToPath() final String input = "Hello, товарищ path #3 äÄ üÜ öÖ and ß"; final File output = this.folder.newFile(); + new LengthOf( + new TeeInput(input.toCharArray(), new OutputTo(output), StandardCharsets.UTF_8.name()) + ).intValue(); new Assertion<>( "char array must be copied to the path with UTF_8 charset's name", - new TeeInput( - input.toCharArray(), - output.toPath(), - StandardCharsets.UTF_8.name() - ), + new InputOf(output), new InputHasContent(input) ).affirm(); } @@ -181,12 +177,12 @@ public void copiesFromCharArrayToFile() throws IOException { final File output = this.folder.newFile(); final String input = "Hello, товарищ file äÄ üÜ öÖ and ß"; + new LengthOf( + new TeeInput(input.toCharArray(), new OutputTo(output), StandardCharsets.UTF_8.name()) + ).intValue(); new Assertion<>( "char array must be copied to the file", - new TeeInput( - input.toCharArray(), - output - ), + new InputOf(output), new InputHasContent(input) ).affirm(); } diff --git a/src/test/java/org/cactoos/io/TeeInputFromCharSequenceTest.java b/src/test/java/org/cactoos/io/TeeInputFromCharSequenceTest.java index 7dd882eed6..27f9c9479a 100644 --- a/src/test/java/org/cactoos/io/TeeInputFromCharSequenceTest.java +++ b/src/test/java/org/cactoos/io/TeeInputFromCharSequenceTest.java @@ -36,6 +36,10 @@ * Test case for {@link TeeInput}. Cases for ctors which use char sequence as * an input. * @since 1.0 + * @todo #1360:30min Correct any TeeInput tests that are not testing if the + * path actually contains the content, just that TeeInput, as an Input,has + * the content. Solution: test the content of the file, not the content of + * teeinput (e.g. #1331). * @checkstyle JavadocMethodCheck (215 lines) * @checkstyle ClassDataAbstractionCouplingCheck (215 lines) */ From 8865ff51183cb79ab340395fdb810ae77ec576f4 Mon Sep 17 00:00:00 2001 From: Andrew Korzhov Date: Sat, 2 May 2020 16:34:47 +0200 Subject: [PATCH 08/10] Remote empty line --- src/test/java/org/cactoos/io/TeeInputFromCharArrayTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/test/java/org/cactoos/io/TeeInputFromCharArrayTest.java b/src/test/java/org/cactoos/io/TeeInputFromCharArrayTest.java index 7bfcba153d..3d2cf329d5 100644 --- a/src/test/java/org/cactoos/io/TeeInputFromCharArrayTest.java +++ b/src/test/java/org/cactoos/io/TeeInputFromCharArrayTest.java @@ -26,7 +26,6 @@ import java.io.File; import java.io.IOException; import java.nio.charset.StandardCharsets; - import org.cactoos.scalar.LengthOf; import org.junit.Rule; import org.junit.Test; From 1b25ea538f4715b52b414676fe7c3460eb0e0a93 Mon Sep 17 00:00:00 2001 From: Andrew Korzhov Date: Sat, 2 May 2020 16:45:27 +0200 Subject: [PATCH 09/10] Add spaces --- src/test/java/org/cactoos/io/TeeInputFromCharArrayTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/org/cactoos/io/TeeInputFromCharArrayTest.java b/src/test/java/org/cactoos/io/TeeInputFromCharArrayTest.java index 3d2cf329d5..156f2493f6 100644 --- a/src/test/java/org/cactoos/io/TeeInputFromCharArrayTest.java +++ b/src/test/java/org/cactoos/io/TeeInputFromCharArrayTest.java @@ -54,7 +54,7 @@ public void copiesFromCharArrayWithCharsetToFile() throws IOException { "Hello, товарищ file #1 äÄ üÜ öÖ and ß"; final File output = this.folder.newFile(); new LengthOf( - new TeeInput(input.toCharArray(), new OutputTo(output)) + new TeeInput(input.toCharArray(), new OutputTo(output)) ).intValue(); new Assertion<>( "char array must be copied to the file with charset UTF_8", From ab8107d15565774b6f0ac31ad53ea994dbb1b8ba Mon Sep 17 00:00:00 2001 From: Andrew Korzhov Date: Sat, 2 May 2020 18:54:32 +0200 Subject: [PATCH 10/10] Fix TeeInput arguments --- .../cactoos/io/TeeInputFromCharArrayTest.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/test/java/org/cactoos/io/TeeInputFromCharArrayTest.java b/src/test/java/org/cactoos/io/TeeInputFromCharArrayTest.java index 156f2493f6..6e1ef335cc 100644 --- a/src/test/java/org/cactoos/io/TeeInputFromCharArrayTest.java +++ b/src/test/java/org/cactoos/io/TeeInputFromCharArrayTest.java @@ -54,7 +54,7 @@ public void copiesFromCharArrayWithCharsetToFile() throws IOException { "Hello, товарищ file #1 äÄ üÜ öÖ and ß"; final File output = this.folder.newFile(); new LengthOf( - new TeeInput(input.toCharArray(), new OutputTo(output)) + new TeeInput(input.toCharArray(), output, StandardCharsets.UTF_8) ).intValue(); new Assertion<>( "char array must be copied to the file with charset UTF_8", @@ -70,7 +70,7 @@ public void copiesFromCharArrayWithCharsetByNameToFile() "Hello, товарищ file #2 äÄ üÜ öÖ and ß"; final File output = this.folder.newFile(); new LengthOf( - new TeeInput(input.toCharArray(), new OutputTo(output), StandardCharsets.UTF_8.name()) + new TeeInput(input.toCharArray(), output, StandardCharsets.UTF_8.name()) ).intValue(); new Assertion<>( "char array must be copied to the file with UTF_8 charset's name", @@ -85,7 +85,7 @@ public void copiesFromCharArrayToOutput() throws IOException { "Hello, товарищ output #1 äÄ üÜ öÖ and ß"; final File output = this.folder.newFile(); new LengthOf( - new TeeInput(input.toCharArray(), new OutputTo(output), StandardCharsets.UTF_8.name()) + new TeeInput(input.toCharArray(), new OutputTo(output)) ).intValue(); new Assertion<>( "char array must be copied to the output", @@ -100,7 +100,7 @@ public void copiesFromCharArrayWithCharsetToOutput() throws IOException { "Hello, товарищ output #2 äÄ üÜ öÖ and ß"; final File output = this.folder.newFile(); new LengthOf( - new TeeInput(input.toCharArray(), new OutputTo(output), StandardCharsets.UTF_8.name()) + new TeeInput(input.toCharArray(), new OutputTo(output), StandardCharsets.UTF_8) ).intValue(); new Assertion<>( "char array must be copied to the output with UTF_8 charset", @@ -131,7 +131,7 @@ public void copiesFromCharArrayToPath() throws IOException { "Hello, товарищ path #1 äÄ üÜ öÖ and ß"; final File output = this.folder.newFile(); new LengthOf( - new TeeInput(input.toCharArray(), new OutputTo(output), StandardCharsets.UTF_8.name()) + new TeeInput(input.toCharArray(), output.toPath()) ).intValue(); new Assertion<>( "char array must be copied to the path", @@ -146,7 +146,7 @@ public void copiesFromCharArrayWithCharsetToPath() throws IOException { "Hello, товарищ path #2 äÄ üÜ öÖ and ß"; final File output = this.folder.newFile(); new LengthOf( - new TeeInput(input.toCharArray(), new OutputTo(output), StandardCharsets.UTF_8.name()) + new TeeInput(input.toCharArray(), output.toPath(), StandardCharsets.UTF_8) ).intValue(); new Assertion<>( "char array must be copied to the path with UTF_8 charset", @@ -162,7 +162,7 @@ public void copiesFromCharArrayWithCharsetByNameToPath() "Hello, товарищ path #3 äÄ üÜ öÖ and ß"; final File output = this.folder.newFile(); new LengthOf( - new TeeInput(input.toCharArray(), new OutputTo(output), StandardCharsets.UTF_8.name()) + new TeeInput(input.toCharArray(), output.toPath(), StandardCharsets.UTF_8.name()) ).intValue(); new Assertion<>( "char array must be copied to the path with UTF_8 charset's name", @@ -177,7 +177,7 @@ public void copiesFromCharArrayToFile() throws IOException { final String input = "Hello, товарищ file äÄ üÜ öÖ and ß"; new LengthOf( - new TeeInput(input.toCharArray(), new OutputTo(output), StandardCharsets.UTF_8.name()) + new TeeInput(input.toCharArray(), output) ).intValue(); new Assertion<>( "char array must be copied to the file",