@Theory public void theoryAddingFileToDirectoryAddsResource(String path) throws Exception { Resource res = getResource(path); assumeThat(res, is(directory())); File dir = res.dir(); File file = new File(dir, "newFileCreatedDirectly"); assumeTrue(file.createNewFile()); Resource child = getResource(Paths.path(res.path(), "newFileCreatedDirectly")); Collection<Resource> children = res.list(); assertThat(child, is(defined())); assertThat(children, hasItem(child)); }
@Theory public void theoryDoubleClose(String path) throws Exception { final Resource res = getResource(path); assumeThat(res, is(resource())); OutputStream os = res.out(); os.close(); os.close(); }
@Theory public void theoryExtantHaveDate(String path) throws Exception { Resource res = getResource(path); assumeThat(res, defined()); long result = res.lastmodified(); assertThat(result, notNullValue()); }
@Theory public void theoryLeavesHaveEmptyListOfChildren(String path) throws Exception { Resource res = getResource(path); assumeThat(res, is(resource())); Collection<Resource> result = res.list(); assertThat(result, empty()); }
@Theory public void theoryUndefinedHaveEmptyListOfChildren(String path) throws Exception { Resource res = getResource(path); assumeThat(res, is(undefined())); Collection<Resource> result = res.list(); assertThat(result, empty()); }
@Theory public void theoryAddingFileToDirectoryAddsResource(String path) throws Exception { Resource res = getResource(path); assumeThat(res, is(directory())); File dir = res.dir(); File file = new File(dir, "newFileCreatedDirectly"); assumeTrue(file.createNewFile()); Resource child = getResource(Paths.path(res.path(), "newFileCreatedDirectly")); Collection<Resource> children = res.list(); assertThat(child, is(defined())); assertThat(children, hasItem(child)); }
@Theory public void theoryExtantHaveDate(String path) throws Exception { Resource res = getResource(path); assumeThat(res, defined()); long result = res.lastmodified(); assertThat(result, notNullValue()); }
@Theory public void theoryNonDirectoriesHaveFileWithSameContents(String path) throws Exception { Resource res = getResource(path); assumeThat(res, not(directory())); byte[] test = {42, 29, 32, 120, 69, 0, 1}; try (OutputStream ostream = res.out()) { ostream.write(test); } byte[] result = new byte[test.length]; try (InputStream istream = new FileInputStream(res.file())) { istream.read(result); assertThat(istream.read(), is(-1)); } assertThat(result, equalTo(test)); }
@Theory public void theoryLeavesHaveOstream(String path) throws Exception { Resource res = getResource(path); assumeThat(res, is(resource())); try (OutputStream result = res.out()) { assertThat(result, notNullValue()); } }
@Theory public void theoryNonDirectoriesPersistData(String path) throws Exception { Resource res = getResource(path); assumeThat(res, not(directory())); byte[] test = {42, 29, 32, 120, 69, 0, 1}; try (OutputStream ostream = res.out()) { ostream.write(test); } byte[] result = new byte[test.length]; try (InputStream istream = res.in()) { istream.read(result); assertThat(istream.read(), is(-1)); } assertThat(result, equalTo(test)); }
@Theory public void theoryLeavesHaveIstream(String path) throws Exception { Resource res = getResource(path); assumeThat(res, is(resource())); try (InputStream result = res.in()) { assertThat(result, notNullValue()); } }
@Theory public void theoryUndefinedHaveEmptyListOfChildren(String path) throws Exception { Resource res = getResource(path); assumeThat(res, is(undefined())); Collection<Resource> result = res.list(); assertThat(result, empty()); }