-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from tvd12/version-1.1.3
Version 1.1.3
- Loading branch information
Showing
12 changed files
with
337 additions
and
33 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
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
22 changes: 22 additions & 0 deletions
22
src/test/java/com/monkey/properties/file/testing/AutoCloseTest.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,22 @@ | ||
package com.monkey.properties.file.testing; | ||
|
||
import java.io.Closeable; | ||
import java.io.IOException; | ||
|
||
public class AutoCloseTest { | ||
|
||
private static class InternalClose implements Closeable { | ||
@Override | ||
public void close() throws IOException { | ||
System.out.println("I'm closed"); | ||
} | ||
} | ||
|
||
public static void main(String[] args) { | ||
try(InternalClose close = new InternalClose()) { | ||
System.out.println(close); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
} |
76 changes: 76 additions & 0 deletions
76
src/test/java/com/monkey/properties/file/testing/FileReaderTest.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,76 @@ | ||
package com.monkey.properties.file.testing; | ||
|
||
import static org.mockito.Mockito.doThrow; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.times; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.when; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.util.Properties; | ||
|
||
import org.testng.annotations.Test; | ||
|
||
import com.tvd12.properties.file.reader.FileReader; | ||
import com.tvd12.test.assertion.Asserts; | ||
|
||
import lombok.AllArgsConstructor; | ||
|
||
public class FileReaderTest { | ||
|
||
private static final Properties PROPERTIES = new Properties(); | ||
|
||
@Test | ||
public void readByClassLoaderAndFileCloseFailed() throws Exception { | ||
// given | ||
InternalFileReader sut = new InternalFileReader(false); | ||
|
||
ClassLoader classLoader = mock(ClassLoader.class); | ||
String file = "config.properties"; | ||
|
||
InputStream inputStream = mock(InputStream.class); | ||
doThrow(new IOException("just test")).when(inputStream).close(); | ||
when(classLoader.getResourceAsStream(file)).thenReturn(inputStream); | ||
|
||
Properties actual = sut.read(classLoader, file); | ||
|
||
// then | ||
Asserts.assertEmpty(actual); | ||
verify(classLoader, times(1)).getResourceAsStream(file); | ||
} | ||
|
||
@Test | ||
public void readFailed() throws Exception { | ||
// given | ||
InternalFileReader sut = new InternalFileReader(true); | ||
|
||
File file = new File("src/test/resources/application.yaml"); | ||
|
||
Properties actual = sut.read(file); | ||
|
||
// then | ||
Asserts.assertEmpty(actual); | ||
} | ||
|
||
@AllArgsConstructor | ||
private static class InternalFileReader implements FileReader { | ||
|
||
private final boolean exception; | ||
|
||
@Override | ||
public Properties loadInputStream( | ||
InputStream inputStream, String contentType) { | ||
return PROPERTIES; | ||
} | ||
|
||
@Override | ||
public Properties loadInputStreamOrThrows( | ||
InputStream inputStream, String contentType) throws IOException { | ||
if(exception) | ||
throw new IOException("just test"); | ||
return PROPERTIES; | ||
} | ||
} | ||
} |
Oops, something went wrong.