Skip to content

Commit 7aaec8e

Browse files
committed
Test coverage
1 parent d8e86d4 commit 7aaec8e

File tree

3 files changed

+44
-2
lines changed

3 files changed

+44
-2
lines changed

fj-core-jvfs/src/main/java/org/fugerit/java/core/jvfs/helpers/AbstractJFile.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ public List<JFile> lsFiles() throws IOException {
130130

131131
@Override
132132
public String describe() {
133-
// see SafeFunction.get() [if any Exception is thrown, it will be wrapped by a ConfigRuntimeException]
133+
// see SafeFunction : https://jupiterdocs.fugerit.org/fj-core/src/docs/SafeFunction.html
134134
return SafeFunction.get( () -> this.getClass().getSimpleName()+"[path:"+this.getPath()+",isDirectory:"+this.isDirectory()+",isFile:"+this.isFile()+"]" );
135135
}
136136

fj-core/README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,8 @@
55
Simple utilities for IO, Configuration, DB, Language types and more.
66

77
[![Maven Central](https://img.shields.io/maven-central/v/org.fugerit.java/fj-core.svg)](https://mvnrepository.com/artifact/org.fugerit.java/fj-core)
8-
[![javadoc](https://javadoc.io/badge2/org.fugerit.java/fj-core/javadoc.svg)](https://javadoc.io/doc/org.fugerit.java/fj-core)
8+
[![javadoc](https://javadoc.io/badge2/org.fugerit.java/fj-core/javadoc.svg)](https://javadoc.io/doc/org.fugerit.java/fj-core)
9+
10+
## Main features documentation
11+
12+
- [SafeFunction](src/docs/SafeFunction.md)

fj-core/src/docs/SafeFunction.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# SafeFunction
2+
3+
[fj-core index](../../README.md)
4+
5+
SafeFunction provides API for handling exception without a try catch block.
6+
7+
Imagine, for instance, you are writing some code to append all the lines in a reader to one line, the classic code would look like :
8+
9+
```
10+
public String testExampleToOneLineClassic() {
11+
StringBuilder builder = new StringBuilder();
12+
try ( BufferedReader reader = new BufferedReader( new StringReader( "test" ) ) ) {
13+
reader.lines().forEach( line -> builder.append( line+" " ) );
14+
} catch (IOException e) {
15+
throw new ConfigRuntimeException( e );
16+
}
17+
return builder.toString();
18+
}
19+
```
20+
21+
With safe functions it look likes :
22+
23+
```
24+
public String testExampleToOneLineSafeFunction() {
25+
return SafeFunction.get(() -> {
26+
StringBuilder builder = new StringBuilder();
27+
try ( BufferedReader reader = new BufferedReader( new StringReader( "test" ) ) ) {
28+
reader.lines().forEach( line -> builder.append( line+" " ) );
29+
}
30+
return builder.toString();
31+
});
32+
}
33+
```
34+
35+
The default behavior is that any thrown Exception will be wrapped by a ConfigRuntimeException.
36+
It is possible to provide custom exception handlers.
37+
38+
Read the [SafeFunction javadoc](https://javadoc.io/doc/org.fugerit.java/fj-core/latest/org/fugerit/java/core/function/SafeFunction.html) too.

0 commit comments

Comments
 (0)