-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
352 additions
and
31 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
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
123 changes: 123 additions & 0 deletions
123
fj-core/src/test/java/test/org/fugerit/java/core/io/line/TestLineIOUtils.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,123 @@ | ||
package test.org.fugerit.java.core.io.line; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.ByteArrayOutputStream; | ||
import java.io.File; | ||
import java.io.FileInputStream; | ||
import java.io.FileReader; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.Reader; | ||
import java.io.StringWriter; | ||
import java.util.List; | ||
|
||
import org.fugerit.java.core.io.line.LineIOUtils; | ||
import org.fugerit.java.core.io.line.LineReader; | ||
import org.fugerit.java.core.io.line.LineWriter; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
|
||
@Slf4j | ||
public class TestLineIOUtils { | ||
|
||
private static final String TEST_FILE_PATH = "src/test/resources/core/db/base-db-conn.properties"; | ||
|
||
private static final int EXPECTED_SIZE = 9; | ||
|
||
@Test | ||
public void testLineReadStream() throws IOException { | ||
try ( InputStream is = new FileInputStream( TEST_FILE_PATH ) ) { | ||
List<String> lines = LineIOUtils.readLines( is ); | ||
Assert.assertEquals( EXPECTED_SIZE , lines.size() ); | ||
} | ||
} | ||
|
||
@Test | ||
public void testLineReadReader() throws IOException { | ||
try ( Reader is = new FileReader( TEST_FILE_PATH ) ) { | ||
List<String> lines = LineIOUtils.readLines( is ); | ||
Assert.assertEquals( EXPECTED_SIZE , lines.size() ); | ||
} | ||
} | ||
|
||
@Test | ||
public void testLineReadFile() throws IOException { | ||
List<String> lines = LineIOUtils.readLines( new File( TEST_FILE_PATH ) ); | ||
lines.stream().forEach( s -> log.info( "current line -> {}", s ) ); | ||
String[] array = LineIOUtils.toLines(lines); | ||
Assert.assertEquals( EXPECTED_SIZE , array.length ); | ||
} | ||
|
||
private int testLineReader( LineReader reader ) throws IOException { | ||
String line = null; | ||
int count = 0; | ||
do { | ||
line = reader.readLine(); | ||
if ( line != null ) { | ||
count ++; | ||
} | ||
} while ( line != null ); | ||
return count; | ||
} | ||
|
||
@Test | ||
public void testCreateLineReader() throws IOException { | ||
try ( Reader is = new FileReader( TEST_FILE_PATH ); | ||
LineReader reader = LineIOUtils.createLineReader( is ) ) { | ||
int count = this.testLineReader(reader); | ||
Assert.assertEquals( EXPECTED_SIZE , count ); | ||
} | ||
} | ||
|
||
@Test | ||
public void testCreateLineBufferedReader() throws IOException { | ||
try ( Reader is = new BufferedReader( new FileReader( TEST_FILE_PATH ) ); | ||
LineReader reader = LineIOUtils.createLineReader( is ) ) { | ||
int count = this.testLineReader(reader); | ||
Assert.assertEquals( EXPECTED_SIZE , count ); | ||
} | ||
} | ||
|
||
@Test | ||
public void testCreateLineReaderStream() throws IOException { | ||
try ( InputStream is = new FileInputStream( TEST_FILE_PATH ); | ||
LineReader reader = LineIOUtils.createLineReader( is ) ) { | ||
int count = this.testLineReader(reader); | ||
Assert.assertEquals( EXPECTED_SIZE , count ); | ||
} | ||
} | ||
|
||
private static final String[] TEST_LINES = { "test1", "test2", "test3" }; | ||
|
||
private int testLineWriter( LineWriter writer ) { | ||
int count = 0; | ||
for ( String line : TEST_LINES ) { | ||
writer.println(line); | ||
count++; | ||
} | ||
writer.print("END"); | ||
writer.println(); | ||
return count; | ||
} | ||
|
||
@Test | ||
public void testCreateLineWriter() throws IOException { | ||
try ( StringWriter w = new StringWriter(); | ||
LineWriter writer = LineIOUtils.createLineWriter( w ) ) { | ||
int count = this.testLineWriter(writer); | ||
Assert.assertEquals( TEST_LINES.length , count ); | ||
} | ||
} | ||
|
||
@Test | ||
public void testCreateLineWriterStream() throws IOException { | ||
try ( ByteArrayOutputStream w = new ByteArrayOutputStream(); | ||
LineWriter writer = LineIOUtils.createLineWriter( w ) ) { | ||
int count = this.testLineWriter(writer); | ||
Assert.assertEquals( TEST_LINES.length , count ); | ||
} | ||
} | ||
|
||
} |
41 changes: 41 additions & 0 deletions
41
fj-core/src/test/java/test/org/fugerit/java/core/lang/helpers/TestExHandler.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,41 @@ | ||
package test.org.fugerit.java.core.lang.helpers; | ||
|
||
import java.io.IOException; | ||
|
||
import org.fugerit.java.core.lang.helpers.ExHandler; | ||
import org.fugerit.java.core.lang.helpers.Result; | ||
import org.fugerit.java.core.lang.helpers.ResultExHandler; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
|
||
@Slf4j | ||
public class TestExHandler { | ||
|
||
private boolean worker( ExHandler handler ) { | ||
handler.fatal( new IOException( "fatal" ) ); | ||
handler.error( new IOException( "error" ) ); | ||
handler.warning( new IOException( "warning" ) ); | ||
return handler != null; | ||
} | ||
|
||
@Test | ||
public void testResultExHandler() { | ||
ResultExHandler handler = new ResultExHandler(); | ||
handler.setResult( new Result() ); | ||
log.info( "test : {}", handler.getResult() ); | ||
boolean ok = this.worker(handler); | ||
Assert.assertTrue( ok ); | ||
} | ||
|
||
@Test | ||
public void testResultExHandlerAlt() { | ||
org.fugerit.java.core.util.result.ResultExHandler handler = new org.fugerit.java.core.util.result.ResultExHandler(); | ||
handler.setResult( new Result() ); | ||
log.info( "test : {}", handler.getResult() ); | ||
boolean ok = this.worker(handler); | ||
Assert.assertTrue( ok ); | ||
} | ||
|
||
} |
Oops, something went wrong.