diff --git a/src/test/TestCases.xlsx b/src/test/TestCases.xlsx index 73b6235..afa5fc4 100644 Binary files a/src/test/TestCases.xlsx and b/src/test/TestCases.xlsx differ diff --git a/src/test/java/com/olexyn/ensync/AppTest.java b/src/test/java/com/olexyn/ensync/AppTest.java deleted file mode 100644 index b1b28ec..0000000 --- a/src/test/java/com/olexyn/ensync/AppTest.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.olexyn.ensync; - -import static org.junit.Assert.assertTrue; - -import org.junit.Test; - -/** - * Unit test for simple App. - */ -public class AppTest -{ - /** - * Rigorous Test :-) - */ - @Test - public void shouldAnswerWithTrue() - { - assertTrue( true ); - } -} diff --git a/src/test/java/com/olexyn/ensync/files/FileTest.java b/src/test/java/com/olexyn/ensync/files/FileTest.java index fd2aafd..347873e 100644 --- a/src/test/java/com/olexyn/ensync/files/FileTest.java +++ b/src/test/java/com/olexyn/ensync/files/FileTest.java @@ -3,8 +3,11 @@ package com.olexyn.ensync.files; import com.olexyn.ensync.Execute; import com.olexyn.ensync.Tools; import org.junit.Assert; +import org.junit.Test; import java.io.File; +import java.util.ArrayList; +import java.util.List; public class FileTest { @@ -16,133 +19,138 @@ public class FileTest { private static final String fileAPath = "asdf"; private static final String fileBPath = "asff"; - private final File a = new File(fileAPath); - private final File b = new File(fileBPath); - - private void createFile(File file){ - - } - - private void updateFile(File file){ + private final TestFile a = new TestFile(fileAPath); + private final TestFile b = new TestFile(fileBPath); + private List createFile(File file) { + try { + Thread.sleep(10); + } catch (InterruptedException e) { + System.out.println(""); + } + return new ArrayList(); } - - private void deleteFile(File file){ - + private List updateFile(File file) { + try { + Thread.sleep(10); + } catch (InterruptedException e) { + System.out.println(""); + } + return new ArrayList(); } - - - - public void deleteA(){ - - Assert.assertFalse(a.exists()); - Assert.assertFalse(b.exists()); - - - + private void deleteFile(File file) { + try { + Thread.sleep(10); + } catch (InterruptedException e) { + System.out.println(""); + } } - /** - * Simulates user activity on disk. - */ - void createFiles() throws InterruptedException { - StringBuilder sbA = new StringBuilder("a"); - StringBuilder sbB = new StringBuilder("b"); - - // dv (deleted-void) - // TODO - - // dd - tools.writeSbToPath(PATH+"/a/dd", sbA); - Thread.sleep(10); - tools.writeSbToPath(PATH+"/b/dd", sbB); - Thread.sleep(10);Thread.sleep(10); - x.execute(new String[]{"rm", PATH+"/a/dd"}); - Thread.sleep(10); - x.execute(new String[]{"rm", PATH+"/b/dd"}); - Thread.sleep(10); - - // dc - tools.writeSbToPath(PATH+"/a/dc", sbA); - Thread.sleep(10); - x.execute(new String[]{"rm", PATH+"/a/dc"}); - Thread.sleep(10); - tools.writeSbToPath(PATH+"/b/dc", sbB); - Thread.sleep(10); - - // dm - tools.writeSbToPath(PATH+"/a/dm", sbA); - Thread.sleep(10); - x.execute(new String[]{"rm", PATH+"/a/dm"}); - Thread.sleep(10); - tools.writeSbToPath(PATH+"/b/dm", sbB); - Thread.sleep(10); - - // dv (deleted-void) - // TODO - - // cd - // TODO - - // cc - // TODO - - // cm - // TODO - - // cv (created-void) - // TODO - - // md - // TODO - - // mc - // TODO - - // mm - // TODO - + private void cleanDirs() { + deleteFile(a); + deleteFile(b); } - /** - * Checks if end-state is as desired. - * @throws Exception otherwise. + * Perform the 15 test cases in TestCases.xlsx. */ - void fileTest() throws Exception { - - - - - - - - // Files where the second (= the newer) file was deleted. Thus both files should not exist in the end-state. - String[] arrayToDelete = {"/a/dd", "/b/dd" , "/a/cd", "/b/cd", "/a/md", "/b/md"}; - for (String path : arrayToDelete){ - if (new TestableFile(path).exists()) throw new Exception(); - } - - // Files where the second (= the newer) file was created or modified. Thus both files should contain "b" in the end-state. - String[] arrayToB = {"/a/dc", "/b/dc" , "/a/dm", "/b/dm", "/a/cc", "/b/cc"}; - for (String path : arrayToB){ - if (!new TestableFile(path).hasContent("b")) throw new Exception(); - } - - + @Test + public void doFileTests() { + List sideloadContentA; + List sideloadContentB; + // 1 + createFile(a); + deleteFile(a); + Assert.assertFalse(a.exists()); + Assert.assertFalse(b.exists()); + cleanDirs(); + // 2 + createFile(b); + createFile(a); + deleteFile(a); + Assert.assertFalse(a.exists()); + Assert.assertFalse(b.exists()); + cleanDirs(); + // 3 + createFile(a); + createFile(b); + deleteFile(a); + deleteFile(b); + Assert.assertFalse(a.exists()); + Assert.assertFalse(b.exists()); + cleanDirs(); + // 4 + createFile(a); + deleteFile(a); + sideloadContentB = createFile(b); + Assert.assertEquals(sideloadContentB, a.updateContent().getContent()); + cleanDirs(); + // 5 + createFile(a); + createFile(b); + deleteFile(a); + sideloadContentB = updateFile(b); + Assert.assertEquals(sideloadContentB, a.updateContent().getContent()); + cleanDirs(); + // 6 + sideloadContentA = createFile(a); + Assert.assertEquals(sideloadContentA, b.updateContent().getContent()); + // 7 + createFile(b); + createFile(a); + Assert.assertEquals(sideloadContentA, b.updateContent().getContent()); + // 8 + createFile(a); + createFile(b); + deleteFile(b); + Assert.assertFalse(a.exists()); + Assert.assertFalse(b.exists()); + cleanDirs(); + //9 + createFile(a); + sideloadContentB = createFile(b); + Assert.assertEquals(sideloadContentB, a.updateContent().getContent()); + cleanDirs(); + // 10 + createFile(b); + createFile(a); + sideloadContentB = updateFile(b); + Assert.assertEquals(sideloadContentB, a.updateContent().getContent()); + // 11 + createFile(a); + sideloadContentA = updateFile(a); + Assert.assertEquals(sideloadContentA, b.updateContent().getContent()); + // 12 + createFile(a); + createFile(b); + sideloadContentA = updateFile(a); + Assert.assertEquals(sideloadContentA, b.updateContent().getContent()); + // 13 + createFile(a); + createFile(b); + updateFile(a); + deleteFile(b); + Assert.assertFalse(a.exists()); + Assert.assertFalse(b.exists()); + cleanDirs(); + // 14 + createFile(a); + updateFile(a); + sideloadContentB = createFile(b); + Assert.assertEquals(sideloadContentB, a.updateContent().getContent()); + cleanDirs(); + // 15 + createFile(a); + createFile(b); + updateFile(a); + sideloadContentB = updateFile(b); + Assert.assertEquals(sideloadContentB, a.updateContent().getContent()); + cleanDirs(); } - - // Assertion Exception - - - - - - } diff --git a/src/test/java/com/olexyn/ensync/files/TestFile.java b/src/test/java/com/olexyn/ensync/files/TestFile.java new file mode 100644 index 0000000..37a8f05 --- /dev/null +++ b/src/test/java/com/olexyn/ensync/files/TestFile.java @@ -0,0 +1,58 @@ +package com.olexyn.ensync.files; + +import com.olexyn.ensync.Tools; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; + +public class TestFile extends File { + + Tools tools = new Tools(); + private List content = new ArrayList<>(); + + /** + * Wrapper for File that adds tools for assessing it's state. + */ + public TestFile(String pathname) { + super(pathname); + } + + public void setContent(List content) { + this.content = content; + } + + public List getContent() { + return content; + } + + public List copyContent() { + return List.copyOf(content); + } + + public TestFile updateContent() { + String line = tools.fileToLines(this).get(0); + this.content.add(line); + return this; + } + + @Override + public boolean equals(Object o) { + if (this == o) { return true; } + if (o == null || getClass() != o.getClass()) { return false; } + if (!super.equals(o)) { return false; } + TestFile that = (TestFile) o; + + + + + + return Objects.equals(tools, that.tools); + } + + @Override + public int hashCode() { + return Objects.hash(super.hashCode(), tools); + } +} diff --git a/src/test/java/com/olexyn/ensync/files/TestableFile.java b/src/test/java/com/olexyn/ensync/files/TestableFile.java deleted file mode 100644 index 77db06a..0000000 --- a/src/test/java/com/olexyn/ensync/files/TestableFile.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.olexyn.ensync.files; - -import com.olexyn.ensync.Tools; - -import java.io.File; - -public class TestableFile extends File { - - Tools tools = new Tools(); - - - public TestableFile(String pathname) { - super(pathname); - } - - public boolean hasContent(String s){ - - String line = tools.fileToLines(this).get(0); - return line.equals(s); - } -}