Skip to content
This repository was archived by the owner on Apr 12, 2021. It is now read-only.

Commit 6b7a848

Browse files
authored
Merge pull request #4 from JSpiner/develop
Create pr/issue template, change groupId, add ignore function
2 parents fbfecc3 + e34198d commit 6b7a848

File tree

10 files changed

+130
-5
lines changed

10 files changed

+130
-5
lines changed

.github/ISSUE_TEMPLATE.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Thanks for creating issue.
2+
Please don't file issues directly, use one of our available templates:
3+
4+
[find a bug?](https://github.com/JSpiner/SafeExecutor/issues/new?template=bug.md)
5+
[hava a question?](https://github.com/JSpiner/SafeExecutor/issues/new?template=question.md)

.github/ISSUE_TEMPLATE/bug.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
Thanks for creating bug issue.
2+
3+
- library version : (x.x.x)
4+
- platform : (sdk 26)
5+
- etc : (run on background...)
6+
7+
## Expected Behavior
8+
9+
10+
## Actual Behavior
11+
12+
13+
## Steps to Reproduce the Problem
14+
1.
15+
1.
16+
1.

.github/ISSUE_TEMPLATE/question.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Thanks for creating question issue.
2+
3+
- library version : (x.x.x)
4+
- platform : (sdk 26)
5+
- etc : (run on background...)
6+
7+
## Question

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Thanks for pull request.
2+
Please don't create PR directly, use one of our available templates:
3+
4+
[new feature or bug resolve?](?template=feature.md)
5+
[new release?](?template=release.md)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
## Description
2+
3+
## Proposed Changes
4+
-
5+
-
6+
-
7+
8+
## Related Issues
9+
-
10+
-
11+
-
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Release Version : x.x.x
2+
3+
## Proposed Changes
4+
-
5+
-
6+
-
7+
8+
## Related Pull Requests
9+
-
10+
-
11+
-

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44

55
SafeExecutor is event-based error handler.
66

7+
[find a bug?](https://github.com/JSpiner/SafeExecutor/issues/new?template=bug.md)
8+
[hava a question?](https://github.com/JSpiner/SafeExecutor/issues/new?template=question.md)
9+
10+
711
# STILL DEVELOPING !!!
812
### now support
913
- error listener

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
55
<modelVersion>4.0.0</modelVersion>
66

7-
<groupId>net.jspiner</groupId>
7+
<groupId>net.jspiner.executor</groupId>
88
<artifactId>safeexecutor</artifactId>
9-
<version>0.3</version>
9+
<version>0.4</version>
1010

1111
<name>SafeExecutor</name>
1212
<description>event based error handler </description>

src/main/java/net.jspiner.executor/SafeExecutor.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import java.util.ArrayList;
44

5-
public class SafeExecutor {
5+
public final class SafeExecutor {
66

77
public SafeExecutor(){
88
throw new RuntimeException("create SafeExecutor() is not allowed. use SafeExecutor.build();");
@@ -12,10 +12,11 @@ public static SafeExecutorBuilder build() {
1212
return new SafeExecutorBuilder();
1313
}
1414

15-
public static class SafeExecutorBuilder {
15+
public static final class SafeExecutorBuilder {
1616

1717
private ArrayList<Executable> executableList;
1818
private ErrorListener errorListener;
19+
private boolean ignore;
1920

2021
private SafeExecutorBuilder() {
2122
executableList = new ArrayList<>();
@@ -27,16 +28,24 @@ public SafeExecutorBuilder add(Executable executable) {
2728
}
2829

2930
public SafeExecutorBuilder onError(ErrorListener errorListener) {
31+
this.ignore = false;
3032
this.errorListener = errorListener;
3133
return this;
3234
}
3335

36+
public SafeExecutorBuilder ignore() {
37+
this.ignore = true;
38+
return this;
39+
}
40+
3441
public void run() {
3542
for (Executable executable : executableList) {
3643
try {
3744
executable.execute();
3845
} catch (Exception error) {
39-
executeError(error);
46+
if (!ignore) {
47+
executeError(error);
48+
}
4049
}
4150
}
4251
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package net.jspiner.executor;
2+
3+
import org.junit.Test;
4+
5+
public class IgnoreErrorTest {
6+
7+
@Test(expected = RuntimeException.class)
8+
public void notIgnoreTest() {
9+
SafeExecutor.build()
10+
.add(() -> {
11+
throw new RuntimeException("test error");
12+
}
13+
).run();
14+
}
15+
16+
@Test
17+
public void ignoreExceptionTest() {
18+
SafeExecutor.build()
19+
.add(() -> {
20+
throw new RuntimeException("test error");
21+
}
22+
).ignore()
23+
.run();
24+
}
25+
26+
@Test
27+
public void ignoreNoExceptionTest() {
28+
SafeExecutor.build()
29+
.add(() -> doNothing())
30+
.ignore()
31+
.run();
32+
}
33+
34+
@Test
35+
public void ignoreMultipleExceptionTest() {
36+
SafeExecutor.build()
37+
.add(() -> {
38+
throw new RuntimeException("test error");
39+
})
40+
.add(() -> {
41+
throw new RuntimeException("test error");
42+
})
43+
.add(() -> {
44+
throw new RuntimeException("test error");
45+
})
46+
.add(() -> {
47+
throw new RuntimeException("test error");
48+
})
49+
.ignore()
50+
.run();
51+
}
52+
53+
private void doNothing() {
54+
// do nothing for test
55+
}
56+
57+
}

0 commit comments

Comments
 (0)