147148149150151152153154155156157
when(r.path()).thenReturn(path); when(r.name()).thenReturn(path.substring(path.lastIndexOf('/')+1)); when(r.getType()).thenReturn(Type.RESOURCE); when(r.lastmodified()).thenReturn( System.currentTimeMillis() ); when(r.in()).thenReturn(content); when(r.out()).thenReturn(new ByteArrayOutputStream()); when(resourceStore.get(path)).thenReturn(r); paths.add( path ); return this; }
719720721722723724725726727728729
} private void copyResToDir(Resource r, Resource newDir) throws IOException { Resource newR = newDir.get(r.name()); try(InputStream in = r.in(); OutputStream out = newR.out()){ IOUtils.copy(in, out); } } private void ensureParent(Resource r) { r.parent().dir();
119120121122123124125126127128129
public void theoryLeavesHaveOstream(String path) throws Exception { Resource res = getResource(path); assumeThat(res, is(resource())); OutputStream result = res.out(); assertThat(result, notNullValue()); } @Theory
141142143144145146147148149150151
public void theoryUndefinedHaveOstream(String path) throws Exception { Resource res = getResource(path); assumeThat(res, is(undefined())); OutputStream result = res.out(); assertThat(result, notNullValue()); } @Theory
154155156157158159160161162163164
assumeThat(res, not(directory())); byte[] test = {42, 29, 32, 120, 69, 0, 1}; OutputStream ostream = res.out(); try { ostream.write(test); } finally { ostream.close(); }
188189190191192193194195196197198
public void theoryDirectoriesHaveNoOstream(String path) throws Exception { Resource res = getResource(path); assumeThat(res, is(directory())); exception.expect(IllegalStateException.class); res.out(); } @Theory public void theoryLeavesHaveNoListOfChildren(String path) throws Exception { Resource res = getResource(path);
341342343344345346347348349350351
396397398399400401402403404405406
byte[] testResource = {42, 29, 32, 120, 69, 0, 1}; byte[] testFile = {27, 3, 5, 90, -120, -3}; // Write to resource { OutputStream ostream = res.out(); try { ostream.write(testResource); } finally { ostream.close(); }
462463464465466467468469470471472
final byte[] thread1Content = "This is the content for thread 1".getBytes(); final byte[] thread2Content = "Thread 2 has this content".getBytes(); try(OutputStream out1 = res.out(); OutputStream out2 = res.out()) { for(int i=0; i<thread1Content.length || i<thread2Content.length; i++) { if(i<thread1Content.length) { out1.write(thread1Content[i]); }
463464465466467468469470471472473
final byte[] thread1Content = "This is the content for thread 1".getBytes(); final byte[] thread2Content = "Thread 2 has this content".getBytes(); try(OutputStream out1 = res.out(); OutputStream out2 = res.out()) { for(int i=0; i<thread1Content.length || i<thread2Content.length; i++) { if(i<thread1Content.length) { out1.write(thread1Content[i]); } if(i<thread2Content.length) {