Skip to content

Commit

Permalink
Merge branch '__rultor'
Browse files Browse the repository at this point in the history
  • Loading branch information
rultor committed Mar 14, 2021
2 parents 62345fc + a19013c commit f8d61e1
Show file tree
Hide file tree
Showing 17 changed files with 113 additions and 36 deletions.
4 changes: 2 additions & 2 deletions src/main/java/org/cactoos/bytes/CheckedBytes.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ public final class CheckedBytes<E extends Exception> implements Bytes {
/**
* Function that wraps exception of {@link #origin} to the required type.
*/
private final Func<Exception, E> func;
private final Func<? super Exception, ? extends E> func;

/**
* Ctor.
* @param orig Origin bytes.
* @param fnc Function that wraps exceptions.
*/
public CheckedBytes(final Bytes orig, final Func<Exception, E> fnc) {
public CheckedBytes(final Bytes orig, final Func<? super Exception, ? extends E> fnc) {
this.origin = orig;
this.func = fnc;
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/cactoos/bytes/UncheckedBytes.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public final class UncheckedBytes implements Bytes {
/**
* Fallback.
*/
private final Func<Exception, byte[]> fallback;
private final Func<? super Exception, byte[]> fallback;

/**
* Ctor.
Expand All @@ -67,7 +67,7 @@ public UncheckedBytes(final Bytes bts) {
* @since 0.5
*/
public UncheckedBytes(final Bytes bts,
final Func<Exception, byte[]> fbk) {
final Func<? super Exception, byte[]> fbk) {
this.bytes = bts;
this.fallback = fbk;
}
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/org/cactoos/collection/package-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,8 @@
* Collections, tests.
*
* @since 0.14
* @todo #1533:30min Continue to exploit generic variance for package
* org.cactoos.collection to ensure typing works as best as
* possible as it is explained in #1533 issue.
*/
package org.cactoos.collection;
2 changes: 2 additions & 0 deletions src/main/java/org/cactoos/experimental/package-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,7 @@
* whatsoever.
*
* @since 1.0.0
* @todo #1533:30min Exploit generic variance for package org.cactoos.experimental
* to ensure typing works as best as possible as it is explained in #1533 issue.
*/
package org.cactoos.experimental;
3 changes: 3 additions & 0 deletions src/main/java/org/cactoos/func/package-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,8 @@
* Functions.
*
* @since 0.1
* @todo #1533:30min Exploit generic variance for package org.cactoos.func
* to ensure typing works as best as possible as it is explained in
* #1533 issue.
*/
package org.cactoos.func;
3 changes: 3 additions & 0 deletions src/main/java/org/cactoos/io/package-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,8 @@
* Input/Output.
*
* @since 0.1
* @todo #1533:30min Exploit generic variance for package org.cactoos.io
* to ensure typing works as best as possible as it is explained in
* #1533 issue.
*/
package org.cactoos.io;
3 changes: 3 additions & 0 deletions src/main/java/org/cactoos/iterable/package-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,8 @@
* Iterables.
*
* @since 0.12
* @todo #1533:30min Exploit generic variance for package org.cactoos.iterable
* to ensure typing works as best as possible as it is explained in
* #1533 issue.
*/
package org.cactoos.iterable;
3 changes: 3 additions & 0 deletions src/main/java/org/cactoos/iterator/package-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,8 @@
* Iterators.
*
* @since 0.12
* @todo #1533:30min Exploit generic variance for package org.cactoos.iterator
* to ensure typing works as best as possible as it is explained in
* #1533 issue.
*/
package org.cactoos.iterator;
3 changes: 3 additions & 0 deletions src/main/java/org/cactoos/list/package-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,8 @@
* Lists, tests.
*
* @since 0.14
* @todo #1533:30min Exploit generic variance for package org.cactoos.list
* to ensure typing works as best as possible as it is explained in
* #1533 issue.
*/
package org.cactoos.list;
3 changes: 3 additions & 0 deletions src/main/java/org/cactoos/map/package-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,8 @@
* Maps.
*
* @since 0.14
* @todo #1533:30min Exploit generic variance for package org.cactoos.map
* to ensure typing works as best as possible as it is explained in
* #1533 issue.
*/
package org.cactoos.map;
3 changes: 3 additions & 0 deletions src/main/java/org/cactoos/proc/package-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,8 @@
* Procedures.
*
* @since 0.47
* @todo #1533:30min Exploit generic variance for package org.cactoos.proc
* to ensure typing works as best as possible as it is explained in
* #1533 issue.
*/
package org.cactoos.proc;
8 changes: 4 additions & 4 deletions src/main/java/org/cactoos/scalar/Checked.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,20 @@ public final class Checked<T, E extends Exception> implements Scalar<T> {
/**
* Function that wraps exception.
*/
private final Func<Exception, E> func;
private final Func<? super Exception, ? extends E> func;

/**
* Original scalar.
*/
private final Scalar<T> origin;
private final Scalar<? extends T> origin;

/**
* Ctor.
* @param scalar Encapsulated scalar
* @param fnc Func that wraps exception
*/
public Checked(final Scalar<T> scalar,
final Func<Exception, E> fnc) {
public Checked(final Scalar<? extends T> scalar,
final Func<? super Exception, ? extends E> fnc) {
this.func = fnc;
this.origin = scalar;
}
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/org/cactoos/scalar/package-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,8 @@
* Scalars.
*
* @since 0.12
* @todo #1533:30min Exploit generic variance for package org.cactoos.scalar
* to ensure typing works as best as possible as it is explained in
* #1533 issue.
*/
package org.cactoos.scalar;
3 changes: 3 additions & 0 deletions src/main/java/org/cactoos/set/package-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,8 @@
* Sets.
*
* @since 0.49.2
* @todo #1533:30min Exploit generic variance for package org.cactoos.set
* to ensure typing works as best as possible as it is explained in
* #1533 issue.
*/
package org.cactoos.set;
3 changes: 3 additions & 0 deletions src/main/java/org/cactoos/text/package-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,8 @@
* Text.
*
* @since 0.1
* @todo #1533:30min Exploit generic variance for package org.cactoos.text
* to ensure typing works as best as possible as it is explained in
* #1533 issue.
*/
package org.cactoos.text;
3 changes: 3 additions & 0 deletions src/main/java/org/cactoos/time/package-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,8 @@
* Time.
*
* @since 1.0
* @todo #1533:30min Exploit generic variance for package org.cactoos.time
* to ensure typing works as best as possible as it is explained in
* #1533 issue.
*/
package org.cactoos.time;
95 changes: 67 additions & 28 deletions src/test/java/org/cactoos/scalar/CheckedTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,35 +25,75 @@

import java.io.FileNotFoundException;
import java.io.IOException;
import org.hamcrest.MatcherAssert;
import java.nio.channels.AcceptPendingException;
import org.hamcrest.Matchers;
import org.hamcrest.core.IsEqual;
import org.junit.Test;
import org.llorllale.cactoos.matchers.Assertion;
import org.llorllale.cactoos.matchers.Throws;

/**
* Test case for {@link Checked}.
* @since 0.30
* @checkstyle JavadocMethodCheck (500 lines)
* @checkstyle ClassDataAbstractionCouplingCheck (500 lines)
*/
public final class CheckedTest {

@Test(expected = IllegalStateException.class)
@Test
public void runtimeExceptionGoesOut() throws Exception {
new Checked<>(
() -> {
throw new IllegalStateException("runtime");
},
IOException::new
).value();
new Assertion<>(
"Must throw runtime exception",
() -> new Checked<>(
() -> {
throw new IllegalStateException("runtime");
},
IOException::new
).value(),
new Throws<>(IllegalStateException.class)
).affirm();
}

@Test(expected = IOException.class)
@Test
public void usesGenericVarianceOnExceptionTypes() throws Exception {
new Assertion<>(
"Must use generic variance on exception types",
() -> new Checked<String, IllegalStateException>(
() -> {
throw new IllegalStateException();
},
(Throwable ex) -> {
return new AcceptPendingException();
}
).value(),
new Throws<>(IllegalStateException.class)
).affirm();
}

@SuppressWarnings("PMD.AvoidDuplicateLiterals")
public void usesContravarianceOnResultType() throws Exception {
new Assertion<>(
"Must use contravariance on result",
new Checked<CharSequence, IOException>(
() -> new String("contravariance"),
IOException::new
).value(),
new IsEqual<>("contravariance")
);
}

@Test
public void throwsIoException() throws Exception {
new Checked<>(
() -> {
throw new InterruptedException("interrupt");
},
IOException::new
).value();
new Assertion<>(
"Must throw io exception",
() -> new Checked<>(
() -> {
throw new InterruptedException("interrupt");
},
IOException::new
).value(),
new Throws<>(IOException.class)
).affirm();
}

@Test
Expand All @@ -66,10 +106,11 @@ public void ioExceptionGoesOut() throws Exception {
IOException::new
).value();
} catch (final IOException exp) {
MatcherAssert.assertThat(
new Assertion<>(
"Must not have cause when throwing io exception",
exp.getCause(),
Matchers.nullValue()
);
).affirm();
}
}

Expand All @@ -83,28 +124,26 @@ public void fileNotFoundExceptionGoesOut() throws Exception {
IOException::new
).value();
} catch (final FileNotFoundException exp) {
MatcherAssert.assertThat(
new Assertion<>(
"Must not have cause when throwing file not found exception",
exp.getCause(),
Matchers.nullValue()
);
).affirm();
}
}

@Test
public void throwsIoExceptionWithModifiedMessage() throws Exception {
final String message = "error msg";
try {
new Checked<>(
new Assertion<>(
"Must throw io exception with modified message",
() -> new Checked<>(
() -> {
throw new IOException("io");
},
exp -> new IOException(message, exp)
).value();
} catch (final IOException exp) {
MatcherAssert.assertThat(
exp.getMessage(),
Matchers.containsString(message)
);
}
).value(),
new Throws<>(message, IOException.class)
).affirm();
}
}

13 comments on commit f8d61e1

@0pdd
Copy link
Collaborator

@0pdd 0pdd commented on f8d61e1 Mar 14, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 1533-6b8653a3 discovered in src/main/java/org/cactoos/set/package-info.java and submitted as #1563. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but we discovered it only now.

@0pdd
Copy link
Collaborator

@0pdd 0pdd commented on f8d61e1 Mar 14, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 1533-0433abcf discovered in src/main/java/org/cactoos/io/package-info.java and submitted as #1564. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but we discovered it only now.

@0pdd
Copy link
Collaborator

@0pdd 0pdd commented on f8d61e1 Mar 14, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 1533-a2c34718 discovered in src/main/java/org/cactoos/iterator/package-info.java and submitted as #1565. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but we discovered it only now.

@0pdd
Copy link
Collaborator

@0pdd 0pdd commented on f8d61e1 Mar 14, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 1533-48e5c994 discovered in src/main/java/org/cactoos/list/package-info.java and submitted as #1566. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but we discovered it only now.

@0pdd
Copy link
Collaborator

@0pdd 0pdd commented on f8d61e1 Mar 14, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 1533-ac41b39c discovered in src/main/java/org/cactoos/proc/package-info.java and submitted as #1567. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but we discovered it only now.

@0pdd
Copy link
Collaborator

@0pdd 0pdd commented on f8d61e1 Mar 14, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 1533-8f051690 discovered in src/main/java/org/cactoos/iterable/package-info.java and submitted as #1568. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but we discovered it only now.

@0pdd
Copy link
Collaborator

@0pdd 0pdd commented on f8d61e1 Mar 14, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 1533-c35e3786 discovered in src/main/java/org/cactoos/scalar/package-info.java and submitted as #1569. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but we discovered it only now.

@0pdd
Copy link
Collaborator

@0pdd 0pdd commented on f8d61e1 Mar 14, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 1533-bf6d58aa discovered in src/main/java/org/cactoos/time/package-info.java and submitted as #1570. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but we discovered it only now.

@0pdd
Copy link
Collaborator

@0pdd 0pdd commented on f8d61e1 Mar 14, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 1533-fb13df65 discovered in src/main/java/org/cactoos/map/package-info.java and submitted as #1571. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but we discovered it only now.

@0pdd
Copy link
Collaborator

@0pdd 0pdd commented on f8d61e1 Mar 14, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 1533-37aa2e90 discovered in src/main/java/org/cactoos/func/package-info.java and submitted as #1572. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but we discovered it only now.

@0pdd
Copy link
Collaborator

@0pdd 0pdd commented on f8d61e1 Mar 14, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 1533-1282c35c discovered in src/main/java/org/cactoos/experimental/package-info.java and submitted as #1573. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but we discovered it only now.

@0pdd
Copy link
Collaborator

@0pdd 0pdd commented on f8d61e1 Mar 14, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 1533-1bce8d47 discovered in src/main/java/org/cactoos/text/package-info.java and submitted as #1574. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but we discovered it only now.

@0pdd
Copy link
Collaborator

@0pdd 0pdd commented on f8d61e1 Mar 14, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 1533-d1b82973 discovered in src/main/java/org/cactoos/collection/package-info.java and submitted as #1575. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but we discovered it only now.

Please sign in to comment.