Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- There is a shh method taking AnnoyingRunnable then returns Runner so that any nullary function case can be solved.
- Loading branch information
Showing
9 changed files
with
208 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package j8plus.types.annoying; | ||
|
||
/** | ||
* @author Kevin Lee | ||
* @since 2017-06-10 | ||
*/ | ||
@FunctionalInterface | ||
public interface AnnoyingRunnable { | ||
/** | ||
* When an object implementing interface <code>Runnable</code> is used | ||
* to create a thread, starting the thread causes the object's | ||
* <code>run</code> method to be called in that separately executing | ||
* thread. | ||
* <p> | ||
* The general contract of the method <code>run</code> is that it may | ||
* take any action whatsoever. | ||
* | ||
* @see java.lang.Thread#run() | ||
* @throws Exception | ||
*/ | ||
void run() throws Exception; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package j8plus.types.annoying; | ||
|
||
import java.util.Objects; | ||
|
||
/** | ||
* @author Kevin Lee | ||
* @since 2017-06-10 | ||
*/ | ||
@FunctionalInterface | ||
public interface AnnoyingRunner extends AnnoyingRunnable { | ||
void run() throws Exception; | ||
|
||
/** | ||
* Returns a composed {@code Consumer} that performs, in sequence, this operation followed by the {@code after} | ||
* operation. If performing either operation throws an exception, it is relayed to the caller of the composed | ||
* operation. If performing this operation throws an exception, the {@code after} operation will not be performed. | ||
* | ||
* @param after | ||
* the operation to perform after this operation | ||
* @return a composed {@code Runner} that performs in sequence this operation followed by the {@code after} operation | ||
* @throws NullPointerException | ||
* if {@code after} is null | ||
*/ | ||
default AnnoyingRunner andThen(final AnnoyingRunner after) { | ||
Objects.requireNonNull(after); | ||
return () -> { | ||
run(); | ||
after.run(); | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
src/test/java/j8plus/types/annoying/AnnoyingRunnerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package j8plus.types.annoying; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.mockito.Mockito.*; | ||
|
||
/** | ||
* @author Kevin Lee | ||
* @since 2017-06-10 | ||
*/ | ||
public class AnnoyingRunnerTest { | ||
|
||
interface ResultChecker { | ||
void result1(); | ||
void result2(); | ||
} | ||
|
||
@Test | ||
public void testAndThen() throws Exception { | ||
final ResultChecker resultChecker = mock(ResultChecker.class); | ||
|
||
final AnnoyingRunner f = () -> resultChecker.result1(); | ||
final AnnoyingRunner g = f.andThen(() -> resultChecker.result2()); | ||
|
||
g.run(); | ||
|
||
verify(resultChecker).result1(); | ||
verify(resultChecker).result2(); | ||
} | ||
|
||
@Test | ||
public void testAndThenWithMethodReference() throws Exception { | ||
final ResultChecker resultChecker = mock(ResultChecker.class); | ||
|
||
final AnnoyingRunner f = resultChecker::result1; | ||
final AnnoyingRunner g = f.andThen(resultChecker::result2); | ||
|
||
g.run(); | ||
|
||
verify(resultChecker).result1(); | ||
verify(resultChecker).result2(); | ||
} | ||
|
||
} |