Skip to content

Commit

Permalink
tests for "loadXXX" added
Browse files Browse the repository at this point in the history
  • Loading branch information
moh-sushi authored and igr committed Oct 25, 2018
1 parent 63e6ce2 commit 1653cca
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 4 deletions.
25 changes: 21 additions & 4 deletions jodd-props/src/test/java/jodd/props/BasePropsTest.java
Expand Up @@ -25,15 +25,32 @@

package jodd.props;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.Writer;
import java.net.URISyntaxException;
import java.net.URL;

import jodd.io.FastCharArrayWriter;
import jodd.io.StreamUtil;
import jodd.util.ClassLoaderUtil;

import java.io.IOException;
import java.io.InputStream;
import java.io.Writer;
abstract class BasePropsTest {

public abstract class BasePropsTest {
protected InputStream readDataToInputstream(String fileName) throws IOException {
String dataFolder = this.getClass().getPackage().getName() + ".data.";
dataFolder = dataFolder.replace('.', '/');
return ClassLoaderUtil.getResourceAsStream(dataFolder + fileName);
}

protected File readDataToFile(String fileName) throws URISyntaxException {
String dataFolder = this.getClass().getPackage().getName() + ".data.";
dataFolder = dataFolder.replace('.', '/');

final URL url = ClassLoaderUtil.getResourceUrl("/" + dataFolder + fileName);
return new File(url.toURI());
}

protected String readDataFile(String fileName) throws IOException {
String dataFolder = this.getClass().getPackage().getName() + ".data.";
Expand Down
40 changes: 40 additions & 0 deletions jodd-props/src/test/java/jodd/props/PropsTest.java
Expand Up @@ -33,8 +33,12 @@
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Method;
import java.net.URISyntaxException;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
Expand Down Expand Up @@ -944,6 +948,42 @@ void testDifferentLineEndings() {
assertEquals("line1| line2| line3| line4", props.getValue("text"));
}

@Test
void testLoad_with_file_props() throws IOException, URISyntaxException {
final File src = readDataToFile("test2.props");
final Props actual = new Props().load(src);

// asserts
assertEquals(3, actual.countTotalProperties());
}

@Test
void testLoad_with_file_properties() throws IOException, URISyntaxException {
final File src = readDataToFile("test.properties");
final Props actual = new Props().load(src);

// asserts
assertEquals(3, actual.countTotalProperties());
}

@Test
void testLoad_with_file_and_encoding() throws IOException, URISyntaxException {
final File src = readDataToFile("test2.props");
final Props actual = new Props().load(src, StandardCharsets.UTF_8.name());

// asserts
assertEquals(3, actual.countTotalProperties());
}

@Test
void testLoad_with_inputstream() throws IOException {
try (final InputStream is = readDataToInputstream("test2.props")) {
final Props actual = new Props().load(is);
// asserts
assertEquals(3, actual.countTotalProperties());
}
}

@Nested
@DisplayName("test for Props#getXXXValue() - methods")
@TestInstance(TestInstance.Lifecycle.PER_CLASS) // needed because annotation MethodSource requires static method without that
Expand Down

0 comments on commit 1653cca

Please sign in to comment.