|
|
@@ -6,12 +6,20 @@
|
|
|
*/
|
|
|
package net.ranides.assira.io;
|
|
|
|
|
|
+import java.io.BufferedOutputStream;
|
|
|
import java.io.BufferedReader;
|
|
|
+import java.io.DataOutputStream;
|
|
|
import java.io.File;
|
|
|
+import java.io.FileInputStream;
|
|
|
+import java.io.FileOutputStream;
|
|
|
import java.io.IOException;
|
|
|
+import java.io.InputStream;
|
|
|
import java.io.Writer;
|
|
|
+import java.util.MissingResourceException;
|
|
|
import java.util.Random;
|
|
|
import net.ranides.assira.math.LFSR;
|
|
|
+import net.ranides.assira.text.StringLoader;
|
|
|
+import net.ranides.assira.text.Strings;
|
|
|
import org.junit.Test;
|
|
|
import static org.junit.Assert.*;
|
|
|
|
|
|
@@ -21,7 +29,70 @@ import static org.junit.Assert.*;
|
|
|
*/
|
|
|
public class FileHelperTest {
|
|
|
|
|
|
- public FileHelperTest() {
|
|
|
+ @Test
|
|
|
+ public void testExtractResource() throws IOException {
|
|
|
+ File file1 = FileHelper.createTempFile("resource", FileHelperTest.class);
|
|
|
+ FileHelper.extractResource("/native-types.txt", file1);
|
|
|
+ String expected = Strings.raw(
|
|
|
+/*Native types (8)
|
|
|
+-------------------
|
|
|
+byte
|
|
|
+short
|
|
|
+int
|
|
|
+long
|
|
|
+float
|
|
|
+double
|
|
|
+char
|
|
|
+boolean
|
|
|
+
|
|
|
+Boxed types (8)
|
|
|
+-------------------
|
|
|
+Byte
|
|
|
+Short
|
|
|
+Integer
|
|
|
+Long
|
|
|
+Float
|
|
|
+Double
|
|
|
+Character
|
|
|
+Boolean*/);
|
|
|
+ assertEquals(expected, StringLoader.fromFile(file1));
|
|
|
+
|
|
|
+ try {
|
|
|
+ FileHelper.extractResource("/not-found.resource", file1);
|
|
|
+ fail("MissingResourceException expected");
|
|
|
+ } catch(MissingResourceException ex) {
|
|
|
+ assertTrue(true);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testCopyEquals() throws IOException {
|
|
|
+ File file1 = FileHelper.createTempFile("equals", "", FileHelperTest.class);
|
|
|
+ File file2 = FileHelper.createTempFile("equals", "", FileHelperTest.class);
|
|
|
+ File file3 = FileHelper.createTempFile("equals", "", FileHelperTest.class);
|
|
|
+ File file4 = FileHelper.createTempFile("equals", "", FileHelperTest.class);
|
|
|
+ File file5 = FileHelper.createTempFile("equals", "", FileHelperTest.class);
|
|
|
+
|
|
|
+ DataOutputStream out1 = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(file1)));
|
|
|
+ DataOutputStream out4 = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(file4)));
|
|
|
+ DataOutputStream out5 = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(file5)));
|
|
|
+
|
|
|
+ Random gen1 = new LFSR(0x45454545);
|
|
|
+ for(int i=0; i<256*1024; i++) {
|
|
|
+ out1.writeInt(gen1.nextInt());
|
|
|
+ out4.writeInt(gen1.nextInt());
|
|
|
+ out5.writeLong(gen1.nextLong());
|
|
|
+ }
|
|
|
+ FileHelper.close(out1);
|
|
|
+ FileHelper.close(out4);
|
|
|
+
|
|
|
+ FileHelper.copy(file2, file1);
|
|
|
+ FileHelper.copy(file3.toString(), file1.toString());
|
|
|
+
|
|
|
+ assertTrue(FileHelper.equals(file1, file2));
|
|
|
+ assertTrue(FileHelper.equals(file1, file3));
|
|
|
+ assertFalse(FileHelper.equals(file1, file4));
|
|
|
+ assertFalse(FileHelper.equals(file1, file5));
|
|
|
}
|
|
|
|
|
|
@Test
|