Skip to content

Commit

Permalink
Made plist serialization unit tests platform independendent
Browse files Browse the repository at this point in the history
  • Loading branch information
hugithordarson committed Jun 30, 2023
1 parent 49f9d00 commit d29a727
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
22 changes: 12 additions & 10 deletions src/test/java/ng/AbstractTest.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package ng;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.stream.Collectors;
import java.io.UncheckedIOException;

/**
* Abstract parent class for unit tests providing some potentially useful
Expand All @@ -13,16 +11,20 @@
* @author paulh
*/
public abstract class AbstractTest {

/**
* Returns a resource as a {@link String}. {@code filename} should be a path
* relative to {@code src/test/resources}.
*
*
* @param filename filename
* @return content of {@code filename} as a {@link String}
*/
protected String testResourceAsString(String filename) {
InputStream is = getClass().getClassLoader().getResourceAsStream(filename);
BufferedReader reader = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8));
return reader.lines().collect(Collectors.joining(System.lineSeparator()));
protected String testResourceAsString( String filename ) {
try( InputStream is = getClass().getClassLoader().getResourceAsStream( filename )) {
return new String( is.readAllBytes() );
}
catch( IOException e ) {
throw new UncheckedIOException( e );
}
}
}
}
2 changes: 1 addition & 1 deletion src/test/resources/plists/listString.plist
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
<string>beta</string>
<string>gamma</string>
</array>
</plist>
</plist>
2 changes: 1 addition & 1 deletion src/test/resources/plists/mapStringString.plist
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
<key>gamma</key>
<string>delta</string>
</dict>
</plist>
</plist>

0 comments on commit d29a727

Please sign in to comment.