forked from yegor256/wring
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
For yegor256#76: Exec register error tests.
- Loading branch information
1 parent
220aed2
commit 61291e3
Showing
4 changed files
with
120 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,6 +33,7 @@ | |
import com.jcabi.log.Logger; | ||
import com.jcabi.manifests.Manifests; | ||
import io.sentry.Sentry; | ||
import io.wring.model.Errors; | ||
import io.wring.model.Events; | ||
import io.wring.model.Pipe; | ||
import java.io.ByteArrayOutputStream; | ||
|
@@ -52,14 +53,20 @@ | |
* One execution. | ||
* | ||
* @author Yegor Bugayenko ([email protected]) | ||
* @author Paulo Lobo ([email protected]) | ||
* @version $Id$ | ||
* @since 0.13 | ||
* @todo #72:30min Errors occurred during execution must be saved and later | ||
* @todo #76:30min Errors occurred during execution must be saved and later | ||
* listed to user in a page. User should be able to mark errors as `read` | ||
* in this page. Wire Error and Errors implementations in Exec flow so | ||
* these errors are properly saved once they happen. Cover this with tests. | ||
* these errors are properly saved once they happen and remove | ||
* Exec(final Agent agt, final Events evt, final Pipe ppe) constructor so | ||
* errors is injected in Exec every time. Then remove Singularfield and | ||
* UnusedPrivateField check ignores and uncomment tests for error | ||
* registering in ExecTest.registerErrors. | ||
* @checkstyle ClassDataAbstractionCouplingCheck (500 lines) | ||
*/ | ||
@SuppressWarnings({"PMD.SingularField", "PMD.UnusedPrivateField"}) | ||
final class Exec { | ||
|
||
/** | ||
|
@@ -77,16 +84,34 @@ final class Exec { | |
*/ | ||
private final transient Pipe pipe; | ||
|
||
/** | ||
* Errors. | ||
*/ | ||
private final Errors errors; | ||
|
||
/** | ||
* Ctor. | ||
* @param agt Agent | ||
* @param evt Events | ||
* @param ppe Pipe | ||
*/ | ||
Exec(final Agent agt, final Events evt, final Pipe ppe) { | ||
this(agt, evt, ppe, new Errors.Simple()); | ||
} | ||
|
||
/** | ||
* Ctor. | ||
* @param agt Agent | ||
* @param evt Events | ||
* @param ppe Pipe | ||
* @param err Errors | ||
* @checkstyle ParameterNumberCheck (2 lines) | ||
*/ | ||
Exec(final Agent agt, final Events evt, final Pipe ppe, final Errors err) { | ||
this.agent = agt; | ||
this.events = evt; | ||
this.pipe = ppe; | ||
this.errors = err; | ||
} | ||
|
||
/** | ||
|
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 |
---|---|---|
|
@@ -30,16 +30,22 @@ | |
package io.wring.agents; | ||
|
||
import io.wring.fake.FkPipe; | ||
import io.wring.model.Errors; | ||
import io.wring.model.Events; | ||
import java.io.IOException; | ||
import org.hamcrest.MatcherAssert; | ||
import org.hamcrest.Matchers; | ||
import org.hamcrest.collection.IsIterableWithSize; | ||
import org.hamcrest.core.IsEqual; | ||
import org.junit.Ignore; | ||
import org.junit.Test; | ||
import org.mockito.Mockito; | ||
import org.mockito.hamcrest.MockitoHamcrest; | ||
|
||
/** | ||
* Test case for {@link Exec}. | ||
* @author Yegor Bugayenko ([email protected]) | ||
* @author Paulo Lobo ([email protected]) | ||
* @version $Id$ | ||
* @since 0.13 | ||
*/ | ||
|
@@ -69,4 +75,25 @@ public void catchesExceptions() throws Exception { | |
); | ||
} | ||
|
||
/** | ||
* Exec can register an error. | ||
* @throws Exception If some problem inside | ||
*/ | ||
@Test | ||
@Ignore | ||
public void registerErrors() throws Exception { | ||
final Agent agent = Mockito.mock(Agent.class); | ||
final Events events = Mockito.mock(Events.class); | ||
final Errors errors = new Errors.Simple(); | ||
Mockito.doThrow(new IOException("<error>")).when(agent).push(events); | ||
new Exec(agent, events, new FkPipe(), errors).run(); | ||
MatcherAssert.assertThat( | ||
"Could not register error", | ||
errors.iterate(), | ||
new IsIterableWithSize<>( | ||
new IsEqual<>(1) | ||
) | ||
); | ||
} | ||
|
||
} |