Merge pull request #10 in LWC/locusworks-commons from feature/updated_methods to develop

* commit '79f913cc6d1c8c0eed19dbf431341938835f23ce':
  Added junit intigration and fixed issues iwth object mapper
This commit is contained in:
Isaac Parenteau
2019-07-21 16:53:02 +00:00
4 changed files with 11 additions and 19 deletions

View File

@ -31,10 +31,6 @@
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId> <artifactId>maven-surefire-plugin</artifactId>
<version>2.20.1</version> <version>2.20.1</version>
<configuration>
<testFailureIgnore>true</testFailureIgnore>
<skipTests>true</skipTests>
</configuration>
</plugin> </plugin>
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>

View File

@ -88,6 +88,9 @@ public class ObjectMapperHelper {
*/ */
public static <T> ObjectMapperResults<T> readValue(Object src, Class<T> clazz) { public static <T> ObjectMapperResults<T> readValue(Object src, Class<T> clazz) {
try { try {
if (src instanceof String) {
return readValue((String)src, clazz);
}
return readValue(mapper.writeValueAsString(src), clazz); return readValue(mapper.writeValueAsString(src), clazz);
} catch (Exception ex) { } catch (Exception ex) {
return new ObjectMapperResults<T>(ex); return new ObjectMapperResults<T>(ex);
@ -116,6 +119,9 @@ public class ObjectMapperHelper {
*/ */
public static <T, L extends Collection<?>> ObjectMapperListResults<List<T>> readListValue(Object object, Class<T> objectClass, Class<L> listClass) { public static <T, L extends Collection<?>> ObjectMapperListResults<List<T>> readListValue(Object object, Class<T> objectClass, Class<L> listClass) {
try { try {
if (object instanceof String) {
return readListValue((String)object, objectClass, listClass);
}
return readListValue(mapper.writeValueAsString(object), objectClass, listClass); return readListValue(mapper.writeValueAsString(object), objectClass, listClass);
} catch (Exception ex) { } catch (Exception ex) {
return new ObjectMapperListResults<>(ex); return new ObjectMapperListResults<>(ex);

View File

@ -4,7 +4,6 @@ import static net.locusworks.common.Charsets.UTF_8;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.File; import java.io.File;
import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.nio.file.Files; import java.nio.file.Files;
@ -84,12 +83,8 @@ public class FileReader implements AutoCloseableIterator<FileReader.LineInfo>, I
throw new IllegalArgumentException("Unable to find resource with name of" + fileName); throw new IllegalArgumentException("Unable to find resource with name of" + fileName);
} }
//Call the buffered reader initializer once the file is found BufferedReader br = new BufferedReader(new InputStreamReader(is, UTF_8));
try(BufferedReader br = new BufferedReader(new InputStreamReader(is, UTF_8))) {
init(br); init(br);
} catch (IOException e) {
throw new IllegalArgumentException(e);
}
} }
/** /**
@ -100,7 +95,8 @@ public class FileReader implements AutoCloseableIterator<FileReader.LineInfo>, I
if (file == null) throw new IllegalArgumentException("File cannot be null"); if (file == null) throw new IllegalArgumentException("File cannot be null");
if (Files.notExists(file)) throw new IllegalArgumentException("File " + file + " does not exist"); if (Files.notExists(file)) throw new IllegalArgumentException("File " + file + " does not exist");
if (!Files.isRegularFile(file)) throw new IllegalArgumentException("File " + file + " is not a file"); if (!Files.isRegularFile(file)) throw new IllegalArgumentException("File " + file + " is not a file");
try (BufferedReader br = Files.newBufferedReader(file)) { try {
BufferedReader br = Files.newBufferedReader(file);
init(br); init(br);
} catch (Exception ex) { } catch (Exception ex) {
throw new RuntimeException(ex); throw new RuntimeException(ex);

View File

@ -1,6 +0,0 @@
#test propertis
#Fri Feb 16 09:42:40 EST 2018
logLevel=INFO
dbPort=3306
userExpirationDays=3650
dbHost=localhost