From 1a3841bcbec498e84ef31aa502940b60d13b3e47 Mon Sep 17 00:00:00 2001 From: Yegor Bugayenko Date: Fri, 15 Jul 2022 20:12:39 +0300 Subject: [PATCH] #1644 IoCheckedBytes --- .../org/cactoos/bytes/IoCheckedBytes.java | 83 ++++++++++++++++++ .../org/cactoos/bytes/UncheckedBytes.java | 10 +-- .../java/org/cactoos/collection/NoNulls.java | 2 +- .../java/org/cactoos/iterable/Cycled.java | 2 +- .../java/org/cactoos/iterable/IterableOf.java | 2 +- .../java/org/cactoos/iterable/Sticky.java | 2 +- .../java/org/cactoos/iterator/RangeOf.java | 2 +- src/main/java/org/cactoos/number/MaxOf.java | 8 +- src/main/java/org/cactoos/number/MinOf.java | 8 +- src/main/java/org/cactoos/scalar/ItemAt.java | 2 +- .../org/cactoos/bytes/IoCheckedBytesTest.java | 86 +++++++++++++++++++ .../cactoos/func/FuncWithFallbackTest.java | 6 +- .../java/org/cactoos/io/LoggingInputTest.java | 3 +- .../org/cactoos/io/LoggingOutputTest.java | 2 +- .../org/cactoos/io/TeeInputStreamTest.java | 4 +- .../org/cactoos/io/TeeOutputStreamTest.java | 6 +- .../org/cactoos/iterable/FilteredTest.java | 4 +- .../java/org/cactoos/iterable/PagedTest.java | 20 ++--- .../java/org/cactoos/iterable/SolidTest.java | 4 +- .../cactoos/iterator/IteratorOfBytesTest.java | 4 +- .../java/org/cactoos/iterator/PagedTest.java | 8 +- .../java/org/cactoos/list/BehavesAsList.java | 2 +- .../java/org/cactoos/list/ImmutableTest.java | 2 +- .../java/org/cactoos/list/ListOfTest.java | 2 +- src/test/java/org/cactoos/map/MapOfTest.java | 58 ++++++------- .../org/cactoos/map/PutUpdatesValues.java | 2 +- .../org/cactoos/scalar/AndInThreadsTest.java | 16 ++-- .../java/org/cactoos/scalar/FirstOfTest.java | 4 +- .../java/org/cactoos/scalar/ItemAtTest.java | 4 +- .../java/org/cactoos/scalar/ReducedTest.java | 2 +- .../scalar/ScalarWithFallbackTest.java | 8 +- src/test/java/org/cactoos/set/SetOfTest.java | 14 +-- 32 files changed, 274 insertions(+), 108 deletions(-) create mode 100644 src/main/java/org/cactoos/bytes/IoCheckedBytes.java create mode 100644 src/test/java/org/cactoos/bytes/IoCheckedBytesTest.java diff --git a/src/main/java/org/cactoos/bytes/IoCheckedBytes.java b/src/main/java/org/cactoos/bytes/IoCheckedBytes.java new file mode 100644 index 000000000..38f45b0e0 --- /dev/null +++ b/src/main/java/org/cactoos/bytes/IoCheckedBytes.java @@ -0,0 +1,83 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2017-2022 Yegor Bugayenko + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package org.cactoos.bytes; + +import java.io.IOException; +import org.cactoos.Bytes; +import org.cactoos.Fallback; +import org.cactoos.scalar.IoChecked; + +/** + * Bytes that doesn't throw checked {@link Exception}, + * but only throws {@link java.io.IOException}. + * + *

There is no thread-safety guarantee. + * + * @since 0.52 + */ +public final class IoCheckedBytes implements Bytes { + + /** + * Scalar with fallback. + */ + private final IoChecked scalar; + + /** + * Ctor. + * @param bts Encapsulated bytes + */ + public IoCheckedBytes(final Bytes bts) { + this(bts, new Fallback.None<>()); + } + + /** + * Ctor. + * @param bts Encapsulated bytes + * @param fbk Fallback + * @since 0.5 + */ + @SuppressWarnings({"unchecked", "PMD.AvoidRethrowingException", "PMD.AvoidCatchingThrowable"}) + public IoCheckedBytes(final Bytes bts, final Fallback fbk) { + this.scalar = new IoChecked<>( + () -> { + byte[] ret; + try { + ret = bts.asBytes(); + } catch (final IOException ex) { + throw ex; + // @checkstyle IllegalCatchCheck (1 line) + } catch (final Throwable ex) { + ret = fbk.apply(ex); + } + return ret; + } + ); + } + + @Override + public byte[] asBytes() throws IOException { + return this.scalar.value(); + } + +} diff --git a/src/main/java/org/cactoos/bytes/UncheckedBytes.java b/src/main/java/org/cactoos/bytes/UncheckedBytes.java index 4c71af1d3..b1f4144e7 100644 --- a/src/main/java/org/cactoos/bytes/UncheckedBytes.java +++ b/src/main/java/org/cactoos/bytes/UncheckedBytes.java @@ -60,12 +60,10 @@ public UncheckedBytes(final Bytes bts) { * @param fbk Fallback * @since 0.5 */ - public UncheckedBytes( - final Bytes bts, - final Fallback fbk - ) { - this.scalar = new Unchecked( - new ScalarWithFallback(bts::asBytes, fbk) + @SuppressWarnings("unchecked") + public UncheckedBytes(final Bytes bts, final Fallback fbk) { + this.scalar = new Unchecked<>( + new ScalarWithFallback<>(bts::asBytes, fbk) ); } diff --git a/src/main/java/org/cactoos/collection/NoNulls.java b/src/main/java/org/cactoos/collection/NoNulls.java index ba85b8fb9..346546860 100644 --- a/src/main/java/org/cactoos/collection/NoNulls.java +++ b/src/main/java/org/cactoos/collection/NoNulls.java @@ -70,7 +70,7 @@ public boolean isEmpty() { @Override public Iterator iterator() { - return new org.cactoos.iterator.NoNulls(this.col.iterator()); + return new org.cactoos.iterator.NoNulls<>(this.col.iterator()); } @Override diff --git a/src/main/java/org/cactoos/iterable/Cycled.java b/src/main/java/org/cactoos/iterable/Cycled.java index d5cc4eb49..f41aa71d9 100644 --- a/src/main/java/org/cactoos/iterable/Cycled.java +++ b/src/main/java/org/cactoos/iterable/Cycled.java @@ -41,7 +41,7 @@ public final class Cycled extends IterableEnvelope { */ @SafeVarargs public Cycled(final T... itr) { - this(new IterableOf(itr)); + this(new IterableOf<>(itr)); } /** diff --git a/src/main/java/org/cactoos/iterable/IterableOf.java b/src/main/java/org/cactoos/iterable/IterableOf.java index 7cf47da73..411ec75f5 100644 --- a/src/main/java/org/cactoos/iterable/IterableOf.java +++ b/src/main/java/org/cactoos/iterable/IterableOf.java @@ -95,7 +95,7 @@ public boolean equals(final Object other) { () -> Iterable.class.isAssignableFrom(other.getClass()), () -> { final Iterable compared = (Iterable) other; - return new ScalarWithFallback( + return new ScalarWithFallback<>( new And( (X value) -> true, new Matched<>( diff --git a/src/main/java/org/cactoos/iterable/Sticky.java b/src/main/java/org/cactoos/iterable/Sticky.java index 345e9c6e6..320a147e9 100644 --- a/src/main/java/org/cactoos/iterable/Sticky.java +++ b/src/main/java/org/cactoos/iterable/Sticky.java @@ -51,7 +51,7 @@ public Sticky(final X... src) { */ public Sticky(final Iterable iterable) { super( - new IterableOf( + new IterableOf<>( new Mapped<>( Iterable::iterator, new org.cactoos.scalar.Sticky<>( diff --git a/src/main/java/org/cactoos/iterator/RangeOf.java b/src/main/java/org/cactoos/iterator/RangeOf.java index 6ff55e644..1920291d1 100644 --- a/src/main/java/org/cactoos/iterator/RangeOf.java +++ b/src/main/java/org/cactoos/iterator/RangeOf.java @@ -61,7 +61,7 @@ public RangeOf(final T min, final T max, final Func incrementor) { this.inc = new UncheckedFunc<>(incrementor); - this.value = new AtomicReference(min); + this.value = new AtomicReference<>(min); this.max = max; } diff --git a/src/main/java/org/cactoos/number/MaxOf.java b/src/main/java/org/cactoos/number/MaxOf.java index d7bc3b9d8..dab391a9a 100644 --- a/src/main/java/org/cactoos/number/MaxOf.java +++ b/src/main/java/org/cactoos/number/MaxOf.java @@ -66,19 +66,19 @@ public MaxOf(final Number... src) { public MaxOf(final Iterable src) { super( new NumberOfScalars( - new Reduced( + new Reduced<>( Math::max, new Mapped<>((Number n) -> n::longValue, src) ), - new Reduced( + new Reduced<>( Math::max, new Mapped<>((Number n) -> n::intValue, src) ), - new Reduced( + new Reduced<>( Math::max, new Mapped<>((Number n) -> n::floatValue, src) ), - new Reduced( + new Reduced<>( Math::max, new Mapped<>((Number n) -> n::doubleValue, src) ) diff --git a/src/main/java/org/cactoos/number/MinOf.java b/src/main/java/org/cactoos/number/MinOf.java index ae9fe0aef..d3acc9c8f 100644 --- a/src/main/java/org/cactoos/number/MinOf.java +++ b/src/main/java/org/cactoos/number/MinOf.java @@ -66,19 +66,19 @@ public MinOf(final Number... src) { public MinOf(final Iterable src) { super( new NumberOfScalars( - new Reduced( + new Reduced<>( Math::min, new Mapped<>((Number n) -> n::longValue, src) ), - new Reduced( + new Reduced<>( Math::min, new Mapped<>((Number n) -> n::intValue, src) ), - new Reduced( + new Reduced<>( Math::min, new Mapped<>((Number n) -> n::floatValue, src) ), - new Reduced( + new Reduced<>( Math::min, new Mapped<>((Number n) -> n::doubleValue, src) ) diff --git a/src/main/java/org/cactoos/scalar/ItemAt.java b/src/main/java/org/cactoos/scalar/ItemAt.java index 86eb460c4..d1bad0213 100644 --- a/src/main/java/org/cactoos/scalar/ItemAt.java +++ b/src/main/java/org/cactoos/scalar/ItemAt.java @@ -96,7 +96,7 @@ public ItemAt( final Func, ? extends T> fallback, final Iterable iterable ) { - this.saved = new Sticky( + this.saved = new Sticky<>( () -> { final T ret; if (position < 0) { diff --git a/src/test/java/org/cactoos/bytes/IoCheckedBytesTest.java b/src/test/java/org/cactoos/bytes/IoCheckedBytesTest.java new file mode 100644 index 000000000..e45df0a7c --- /dev/null +++ b/src/test/java/org/cactoos/bytes/IoCheckedBytesTest.java @@ -0,0 +1,86 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2017-2022 Yegor Bugayenko + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package org.cactoos.bytes; + +import java.io.IOException; +import org.cactoos.Fallback; +import org.cactoos.Text; +import org.cactoos.text.TextOf; +import org.hamcrest.core.IsEqual; +import org.junit.jupiter.api.Test; +import org.llorllale.cactoos.matchers.Assertion; +import org.llorllale.cactoos.matchers.Throws; + +/** + * Test case for {@link IoCheckedBytes}. + * + * @since 0.52 + * @checkstyle JavadocMethodCheck (500 lines) + * @checkstyle ClassDataAbstractionCouplingCheck (500 lines) + */ +final class IoCheckedBytesTest { + + @Test + void rethrowsCheckedToUncheckedException() { + new Assertion<>( + "Must rethrow checked to io-checked exception", + () -> new IoCheckedBytes( + () -> { + throw new IOException("intended"); + } + ).asBytes(), + new Throws<>(IOException.class) + ).affirm(); + } + + @Test + void worksNormallyWhenNoExceptionIsThrown() throws Exception { + final Text source = new TextOf("hello, cactoos!"); + new Assertion<>( + "Must work normally when no exception is thrown", + new IoCheckedBytes( + new BytesOf(source) + ).asBytes(), + new IsEqual<>(new BytesOf(source).asBytes()) + ).affirm(); + } + + @Test + void worksWithFallback() throws IOException { + final byte[] empty = {}; + new Assertion<>( + "Must work with fallback", + new IoCheckedBytes( + () -> { + throw new IllegalArgumentException("OK"); + }, + new Fallback.From<>( + IllegalArgumentException.class, + ex -> empty + ) + ).asBytes(), + new IsEqual<>(empty) + ).affirm(); + } +} diff --git a/src/test/java/org/cactoos/func/FuncWithFallbackTest.java b/src/test/java/org/cactoos/func/FuncWithFallbackTest.java index 624b5ffc0..4c2873664 100644 --- a/src/test/java/org/cactoos/func/FuncWithFallbackTest.java +++ b/src/test/java/org/cactoos/func/FuncWithFallbackTest.java @@ -47,7 +47,7 @@ public void usesMainFunc() { final String expected = "It's success"; new Assertion<>( "Can't use the main function if no exception", - new FuncWithFallback( + new FuncWithFallback<>( input -> expected, new Fallback.From<>( Exception.class, @@ -63,7 +63,7 @@ public void usesFallback() { final String expected = "Never mind"; new Assertion<>( "Can't use the callback in case of exception", - new FuncWithFallback( + new FuncWithFallback<>( input -> { throw new IOException("Failure"); }, @@ -78,7 +78,7 @@ public void usesFallbackOfInterruptedException() { final String expected = "Fallback from InterruptedException"; new Assertion<>( "Can't use a fallback from Interrupted in case of exception", - new FuncWithFallback( + new FuncWithFallback<>( input -> { throw new InterruptedException( "Failure with InterruptedException" diff --git a/src/test/java/org/cactoos/io/LoggingInputTest.java b/src/test/java/org/cactoos/io/LoggingInputTest.java index 901b0b6b2..ae250fecc 100644 --- a/src/test/java/org/cactoos/io/LoggingInputTest.java +++ b/src/test/java/org/cactoos/io/LoggingInputTest.java @@ -26,7 +26,6 @@ import java.io.InputStream; import java.util.logging.Level; import java.util.logging.Logger; -import org.cactoos.Text; import org.cactoos.scalar.LengthOf; import org.cactoos.text.TextOf; import org.hamcrest.core.AllOf; @@ -116,7 +115,7 @@ void logReadFromLargeTextFile() throws Exception { "Must log 74536 bytes read from text file", new TextOf(logger.toString()), new AllOf<>( - new IsNot( + new IsNot<>( new HasString("Read 16384 byte(s) from text file") ), new HasString("Read 74536 byte(s) from text file in"), diff --git a/src/test/java/org/cactoos/io/LoggingOutputTest.java b/src/test/java/org/cactoos/io/LoggingOutputTest.java index 9383233fd..6f3e60c9a 100644 --- a/src/test/java/org/cactoos/io/LoggingOutputTest.java +++ b/src/test/java/org/cactoos/io/LoggingOutputTest.java @@ -139,7 +139,7 @@ public void logWriteToLargeTextFile() throws Exception { "Must log write and close operations to text file", logger.toString(), new AllOf<>( - new IsNot( + new IsNot<>( new StringContains( "Written 16384 byte(s) to text file" ) diff --git a/src/test/java/org/cactoos/io/TeeInputStreamTest.java b/src/test/java/org/cactoos/io/TeeInputStreamTest.java index d493e66a1..6ff6bec3e 100644 --- a/src/test/java/org/cactoos/io/TeeInputStreamTest.java +++ b/src/test/java/org/cactoos/io/TeeInputStreamTest.java @@ -60,8 +60,8 @@ void copiesContentByteByByte() throws Exception { ) ).asString(), new AllOf<>( - new IsEqual(content), - new IsEqual( + new IsEqual<>(content), + new IsEqual<>( new String(baos.toByteArray(), StandardCharsets.UTF_8) ) ) diff --git a/src/test/java/org/cactoos/io/TeeOutputStreamTest.java b/src/test/java/org/cactoos/io/TeeOutputStreamTest.java index 4c3aabe92..81115c851 100644 --- a/src/test/java/org/cactoos/io/TeeOutputStreamTest.java +++ b/src/test/java/org/cactoos/io/TeeOutputStreamTest.java @@ -59,11 +59,11 @@ void copiesContentByteByByte() throws Exception { ) ).asString(), new AllOf<>( - new IsEqual(content), - new IsEqual( + new IsEqual<>(content), + new IsEqual<>( new String(baos.toByteArray(), StandardCharsets.UTF_8) ), - new IsEqual( + new IsEqual<>( new String(copy.toByteArray(), StandardCharsets.UTF_8) ) ) diff --git a/src/test/java/org/cactoos/iterable/FilteredTest.java b/src/test/java/org/cactoos/iterable/FilteredTest.java index ca00f8a90..7eb6346ab 100644 --- a/src/test/java/org/cactoos/iterable/FilteredTest.java +++ b/src/test/java/org/cactoos/iterable/FilteredTest.java @@ -156,9 +156,9 @@ void filtersWithFuncToScalar() { void filterWithNumberFilter() { new Assertion<>( "Must be filtered with super type filter", - new Filtered( + new Filtered<>( (Number d) -> d.doubleValue() > 0, - new IterableOf(1d, -2d, 3d) + new IterableOf<>(1d, -2d, 3d) ), new HasValues<>(1d, 3d) ).affirm(); diff --git a/src/test/java/org/cactoos/iterable/PagedTest.java b/src/test/java/org/cactoos/iterable/PagedTest.java index 563943e98..74b147eb3 100644 --- a/src/test/java/org/cactoos/iterable/PagedTest.java +++ b/src/test/java/org/cactoos/iterable/PagedTest.java @@ -57,9 +57,9 @@ void containAllPagedContentInOrder() { new Paged<>( pages.next(), page -> new Ternary<>( - () -> pages.hasNext(), - () -> pages.next(), - () -> new IterableOf() + pages::hasNext, + pages::next, + (Scalar>) IterableOf::new ).value() ), new IsEqual<>(new Joined<>(first, second, third)) @@ -81,9 +81,9 @@ void reportTotalPagedLength() throws AssertionError, Exception { new Paged<>( pages.next(), page -> new Ternary<>( - () -> pages.hasNext(), - () -> pages.next(), - () -> new IterableOf() + pages::hasNext, + pages::next, + (Scalar>) IterableOf::new ).value() ), new IsIterableWithSize<>( @@ -103,13 +103,13 @@ void throwsNoSuchElement() { final Iterator> pages = service.iterator(); new Assertion>( "must throw an exception when first iterator is empty", - new ScalarOf( + new ScalarOf<>( () -> new Paged<>( pages.next(), page -> new Ternary<>( - () -> pages.hasNext(), - () -> pages.next(), - () -> new IterableOf() + pages::hasNext, + pages::next, + (Scalar>) IterableOf::new ).value() ).iterator().next() ), diff --git a/src/test/java/org/cactoos/iterable/SolidTest.java b/src/test/java/org/cactoos/iterable/SolidTest.java index 755a6dd1b..2f73f4707 100644 --- a/src/test/java/org/cactoos/iterable/SolidTest.java +++ b/src/test/java/org/cactoos/iterable/SolidTest.java @@ -40,7 +40,7 @@ final class SolidTest { @Test void makesListFromMappedIterable() { final Iterable list = new Solid<>( - new Mapped( + new Mapped<>( i -> i + 1, new IterableOf<>(1, -1, 0, 1) ) @@ -58,7 +58,7 @@ void makesListFromMappedIterable() { @Test void mapsToSameObjects() { final Iterable> list = new Solid<>( - new Mapped>( + new Mapped<>( i -> () -> i, new IterableOf<>(1, -1, 0, 1) ) diff --git a/src/test/java/org/cactoos/iterator/IteratorOfBytesTest.java b/src/test/java/org/cactoos/iterator/IteratorOfBytesTest.java index 05ede976b..6e095a7cc 100644 --- a/src/test/java/org/cactoos/iterator/IteratorOfBytesTest.java +++ b/src/test/java/org/cactoos/iterator/IteratorOfBytesTest.java @@ -53,7 +53,7 @@ public void canBeConstructedFromString() throws Exception { itr.next(), itr.hasNext() ), - new HasValues( + new HasValues<>( (byte) 'F', false ) ).affirm(); @@ -72,7 +72,7 @@ public void canBeConstructedFromText() throws Exception { itr.next(), itr.hasNext() ), - new HasValues( + new HasValues<>( (byte) 'A', (byte) 'B', (byte) 'C', false ) ).affirm(); diff --git a/src/test/java/org/cactoos/iterator/PagedTest.java b/src/test/java/org/cactoos/iterator/PagedTest.java index c0fab0550..22d894bef 100644 --- a/src/test/java/org/cactoos/iterator/PagedTest.java +++ b/src/test/java/org/cactoos/iterator/PagedTest.java @@ -59,14 +59,14 @@ void containAllPagedContentInOrder() throws Exception { final Paged paged = new Paged<>( pages.next(), page -> new Ternary<>( - () -> pages.hasNext(), - () -> pages.next(), + pages::hasNext, + pages::next, () -> new IteratorOf() ).value() ); new Assertion<>( "must have all page values in order", - new ScalarWithFallback( + new ScalarWithFallback<>( new And( value -> { value.forEachRemaining(m -> { }); @@ -124,7 +124,7 @@ void throwsNoSuchElement() { final Iterator> pages = new IteratorOf<>(); new Assertion>( "must throw an exception when first iterator is empty", - new ScalarOf( + new ScalarOf<>( () -> new Paged<>( pages.next(), page -> new Ternary<>( diff --git a/src/test/java/org/cactoos/list/BehavesAsList.java b/src/test/java/org/cactoos/list/BehavesAsList.java index 850ba91c7..6a7719edc 100644 --- a/src/test/java/org/cactoos/list/BehavesAsList.java +++ b/src/test/java/org/cactoos/list/BehavesAsList.java @@ -81,7 +81,7 @@ public boolean matchesSafely(final List list) { list.subList(0, 1).iterator().hasNext(), new IsTrue() ).affirm(); - return new BehavesAsCollection(this.sample).matchesSafely(list); + return new BehavesAsCollection<>(this.sample).matchesSafely(list); } @Override diff --git a/src/test/java/org/cactoos/list/ImmutableTest.java b/src/test/java/org/cactoos/list/ImmutableTest.java index 2be94aba2..f1150c8a5 100644 --- a/src/test/java/org/cactoos/list/ImmutableTest.java +++ b/src/test/java/org/cactoos/list/ImmutableTest.java @@ -544,7 +544,7 @@ void subListReturnsListIteratorWithSupportedSet() { "subList's iterator must be immutable", () -> { final ListIterator iterator = new Immutable<>( - new ListOf("one", "two", "three") + new ListOf<>("one", "two", "three") ) .subList(0, 2) .listIterator(0); diff --git a/src/test/java/org/cactoos/list/ListOfTest.java b/src/test/java/org/cactoos/list/ListOfTest.java index f752c1d25..11f9e1a84 100644 --- a/src/test/java/org/cactoos/list/ListOfTest.java +++ b/src/test/java/org/cactoos/list/ListOfTest.java @@ -104,7 +104,7 @@ public void highBoundTest() throws Exception { @Test public void makesListFromMappedIterable() throws Exception { final List list = new ListOf<>( - new Mapped( + new Mapped<>( i -> i + 1, new IterableOf<>(1, -1, 0, 1) ) diff --git a/src/test/java/org/cactoos/map/MapOfTest.java b/src/test/java/org/cactoos/map/MapOfTest.java index 6035bd25d..e282de275 100644 --- a/src/test/java/org/cactoos/map/MapOfTest.java +++ b/src/test/java/org/cactoos/map/MapOfTest.java @@ -52,7 +52,7 @@ final class MapOfTest { void createsMapFromSingleKeyAndValue() { new Assertion<>( "Must create a map from single key and value", - new MapOf(-1, 1), + new MapOf<>(-1, 1), new HasEntry<>(-1, 1) ).affirm(); } @@ -138,15 +138,15 @@ void mapsToString() { new MapEntry>( -1, new MapOf( - new MapEntry("first", "second"), - new MapEntry("4", "7") + new MapEntry<>("first", "second"), + new MapEntry<>("4", "7") ) ), new MapEntry>( 1, new MapOf( - new MapEntry("green", "red"), - new MapEntry("2.7", "3.1") + new MapEntry<>("green", "red"), + new MapEntry<>("2.7", "3.1") ) ) ).toString(), @@ -166,17 +166,17 @@ void emptyToString() { @Test @SuppressWarnings("unchecked") void createsMapFromMapAndSingleKeyAndValue() { - new Assertion>( + new Assertion<>( "Must create a map from map and single key and value", - new MapOf( - new MapOf( - new MapEntry(0, 0) + new MapOf<>( + new MapOf<>( + new MapEntry<>(0, 0) ), -1, 1 ), new AllOf<>( - new HasEntry<>(0, 0), - new HasEntry<>(-1, 1) + new HasEntry<>(0, 0), + new HasEntry<>(-1, 1) ) ).affirm(); } @@ -184,17 +184,17 @@ void createsMapFromMapAndSingleKeyAndValue() { @Test @SuppressWarnings("unchecked") void createsMapFromMapAndMapEntries() { - new Assertion>( + new Assertion<>( "Must create a map from map and map entries", new MapOf( - new MapOf( - new MapEntry(0, 0) + new MapOf<>( + new MapEntry<>(0, 0) ), - new MapEntry(1, 1) + new MapEntry<>(1, 1) ), new AllOf<>( - new HasEntry<>(0, 0), - new HasEntry<>(1, 1) + new HasEntry<>(0, 0), + new HasEntry<>(1, 1) ) ).affirm(); } @@ -203,10 +203,10 @@ void createsMapFromMapAndMapEntries() { void createsMapFromFunctionsAndIterable() { new Assertion<>( "Must create a map from functions and iterable.", - new MapOf( - new FuncOf(new Constant<>(0)), - new FuncOf(new Constant<>(0)), - new IterableOf(0) + new MapOf<>( + new FuncOf<>(new Constant<>(0)), + new FuncOf<>(new Constant<>(0)), + new IterableOf<>(0) ), new HasEntry<>(0, 0) ).affirm(); @@ -215,19 +215,19 @@ void createsMapFromFunctionsAndIterable() { @Test @SuppressWarnings("unchecked") void createsMapFromMapFunctionsAndIterable() { - new Assertion>( + new Assertion<>( "Must create a map from map, functions and iterable.", - new MapOf( - new FuncOf(new Constant<>(0)), - new FuncOf(new Constant<>(0)), - new MapOf( - new MapEntry(1, 1) + new MapOf<>( + new FuncOf<>(new Constant<>(0)), + new FuncOf<>(new Constant<>(0)), + new MapOf<>( + new MapEntry<>(1, 1) ), new IterableOf<>(0) ), new AllOf<>( - new HasEntry<>(0, 0), - new HasEntry<>(1, 1) + new HasEntry<>(0, 0), + new HasEntry<>(1, 1) ) ).affirm(); } diff --git a/src/test/java/org/cactoos/map/PutUpdatesValues.java b/src/test/java/org/cactoos/map/PutUpdatesValues.java index 1bae4f0fa..6ab0654d7 100644 --- a/src/test/java/org/cactoos/map/PutUpdatesValues.java +++ b/src/test/java/org/cactoos/map/PutUpdatesValues.java @@ -65,7 +65,7 @@ public boolean matchesSafely(final Map map) { MatcherAssert.assertThat( "Can't behave as a map after put", map, - new BehavesAsMap(this.key, this.value) + new BehavesAsMap<>(this.key, this.value) ); return true; } diff --git a/src/test/java/org/cactoos/scalar/AndInThreadsTest.java b/src/test/java/org/cactoos/scalar/AndInThreadsTest.java index f81ac0fc4..a9a303e8e 100644 --- a/src/test/java/org/cactoos/scalar/AndInThreadsTest.java +++ b/src/test/java/org/cactoos/scalar/AndInThreadsTest.java @@ -94,7 +94,7 @@ void allFalse() throws Exception { void emptyIterable() throws Exception { new Assertion<>( "Must iterate over empty iterable", - new AndInThreads(new IterableOf>()), + new AndInThreads(new IterableOf<>()), new HasValue<>(true) ).affirm(); } @@ -140,8 +140,8 @@ void worksWithIterableScalarBoolean() throws Exception { MatcherAssert.assertThat( new AndInThreads( new ListOf>( - new Constant(true), - new Constant(true) + new Constant<>(true), + new Constant<>(true) ) ).value(), Matchers.equalTo(true) @@ -193,8 +193,8 @@ void worksWithExecServiceScalarBooleans() throws Exception { MatcherAssert.assertThat( new AndInThreads( Executors.newSingleThreadExecutor(), - new Constant(false), - new Constant(false) + new Constant<>(false), + new Constant<>(false) ).value(), Matchers.equalTo(false) ); @@ -206,8 +206,8 @@ void worksWithExecServiceIterableScalarBoolean() throws Exception { new AndInThreads( Executors.newSingleThreadExecutor(), new ListOf>( - new Constant(true), - new Constant(false) + new Constant<>(true), + new Constant<>(false) ) ).value(), Matchers.equalTo(false) @@ -218,7 +218,7 @@ void worksWithExecServiceIterableScalarBoolean() throws Exception { void worksWithEmptyIterableScalarBoolean() throws Exception { MatcherAssert.assertThat( new AndInThreads( - new ListOf>() + new ListOf<>() ).value(), Matchers.equalTo(true) ); diff --git a/src/test/java/org/cactoos/scalar/FirstOfTest.java b/src/test/java/org/cactoos/scalar/FirstOfTest.java index 6b9b253fd..8de081b62 100644 --- a/src/test/java/org/cactoos/scalar/FirstOfTest.java +++ b/src/test/java/org/cactoos/scalar/FirstOfTest.java @@ -122,7 +122,7 @@ void throwsFallbackIfNothingMatches() { void returnsFirstValueWithScalarFallback() { new Assertion<>( "Returns first value with scalar fallback", - new FirstOf( + new FirstOf<>( new IterableOfInts(2, 1, 0), () -> -1 ), @@ -146,7 +146,7 @@ void returnsFirstValueWithIntegerFallback() { void returnsFallbackWhenIterableEmpty() { new Assertion<>( "Returns fallback when iterable empty", - new FirstOf( + new FirstOf<>( new IterableOf<>(), () -> -1 ), diff --git a/src/test/java/org/cactoos/scalar/ItemAtTest.java b/src/test/java/org/cactoos/scalar/ItemAtTest.java index 6c8c51f3d..0faaf9e34 100644 --- a/src/test/java/org/cactoos/scalar/ItemAtTest.java +++ b/src/test/java/org/cactoos/scalar/ItemAtTest.java @@ -57,7 +57,7 @@ void elementByPosFallbackIterableTest() { new Assertion<>( "must fallback to default one", new ItemAt<>( - 1, fallback, new IterableOf() + 1, fallback, new IterableOf<>() ), new HasValue<>(fallback) ).affirm(); @@ -69,7 +69,7 @@ void elementByPosNoFallbackIterableTest() { "must take the item by position from the iterable", new ItemAt<>( // @checkstyle MagicNumber (1 line) - 1, 5, new IterableOf(0, 1) + 1, 5, new IterableOf<>(0, 1) ), new HasValue<>(1) ).affirm(); diff --git a/src/test/java/org/cactoos/scalar/ReducedTest.java b/src/test/java/org/cactoos/scalar/ReducedTest.java index 25b790d4a..487d69366 100644 --- a/src/test/java/org/cactoos/scalar/ReducedTest.java +++ b/src/test/java/org/cactoos/scalar/ReducedTest.java @@ -104,7 +104,7 @@ public void constructedFromVarargs() { final String three = "Three"; new Assertion<>( "Must concatenate the strings in vararg array", - new Reduced( + new Reduced<>( (first, last) -> first + last, one, two, diff --git a/src/test/java/org/cactoos/scalar/ScalarWithFallbackTest.java b/src/test/java/org/cactoos/scalar/ScalarWithFallbackTest.java index 65aaffa9c..751e96564 100644 --- a/src/test/java/org/cactoos/scalar/ScalarWithFallbackTest.java +++ b/src/test/java/org/cactoos/scalar/ScalarWithFallbackTest.java @@ -65,7 +65,7 @@ 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( + new ScalarWithFallback<>( () -> message, new Fallback.From<>( IOException.class, @@ -81,7 +81,7 @@ 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( + new ScalarWithFallback<>( () -> message, new Fallback.From<>( new IterableOf<>(IOException.class), @@ -120,7 +120,7 @@ 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( + new ScalarWithFallback<>( () -> { throw new IOException("Failure with IOException (exp & flbck)"); }, @@ -138,7 +138,7 @@ 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( + new ScalarWithFallback<>( () -> { throw new IOException("Failure with IOException (exp iterable & flbck)"); }, diff --git a/src/test/java/org/cactoos/set/SetOfTest.java b/src/test/java/org/cactoos/set/SetOfTest.java index 22a902578..937eb6f41 100644 --- a/src/test/java/org/cactoos/set/SetOfTest.java +++ b/src/test/java/org/cactoos/set/SetOfTest.java @@ -45,7 +45,7 @@ final class SetOfTest { @Test @SuppressWarnings("unchecked") void behaveAsSetWithOriginalDuplicationsInTheTail() { - new Assertion>( + new Assertion<>( "Must keep unique integer numbers", new SetOf<>(1, 2, 2), new AllOf<>( @@ -58,7 +58,7 @@ void behaveAsSetWithOriginalDuplicationsInTheTail() { @Test @SuppressWarnings("unchecked") void behaveAsSetWithOriginalDuplicationsInTheHead() { - new Assertion>( + new Assertion<>( "Must keep unique integer numbers", new SetOf<>(1, 1, 2, 3), new AllOf<>( @@ -71,7 +71,7 @@ void behaveAsSetWithOriginalDuplicationsInTheHead() { @Test @SuppressWarnings("unchecked") void behaveAsSetWithOriginalDuplicationsInTheMiddle() { - new Assertion>( + new Assertion<>( "Must keep unique integer numbers", new SetOf<>(1, 2, 2, 3), new AllOf<>( @@ -84,9 +84,9 @@ void behaveAsSetWithOriginalDuplicationsInTheMiddle() { @Test @SuppressWarnings("unchecked") void behaveAsSetMergedCollectionsOfLiteralsWithDuplicates() { - new Assertion>( + new Assertion<>( "Must keep unique string literals", - new SetOf( + new SetOf<>( new Joined( new IterableOf<>("cc", "ff"), new IterableOf<>("aa", "bb", "cc", "dd") @@ -102,7 +102,7 @@ void behaveAsSetMergedCollectionsOfLiteralsWithDuplicates() { @Test @SuppressWarnings("unchecked") void behaveAsSetWithOriginalDuplicationsOfCharsInTheMiddle() { - new Assertion>( + new Assertion<>( "Must keep unique characters", new SetOf<>('a', 'b', 'b', 'c', 'a', 'b', 'd'), new AllOf<>( @@ -115,7 +115,7 @@ void behaveAsSetWithOriginalDuplicationsOfCharsInTheMiddle() { @Test @SuppressWarnings("unchecked") void behaveAsSetWithOriginalDuplicationsOfDoublesInTheMiddle() { - new Assertion>( + new Assertion<>( "Must keep unique double numbers", new SetOf<>(1.5d, 2.4d, 1.5d, 2.4d, 2.4d, 1.5d), new AllOf<>(