PageRenderTime 5ms CodeModel.GetById 1ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/sigmah/src/test/java/org/sigmah/server/endpoint/file/FileManagerTestConfigModule.java

http://sigma-h.googlecode.com/
Java | 49 lines | 33 code | 16 blank | 0 comment | 0 complexity | a5f12d78114285e137d429276c014aae MD5 | raw file
 1package org.sigmah.server.endpoint.file;
 2
 3import java.io.ByteArrayInputStream;
 4import java.io.ByteArrayOutputStream;
 5import java.io.File;
 6import java.io.IOException;
 7import java.io.InputStream;
 8import java.io.OutputStream;
 9import java.util.Date;
10import java.util.HashMap;
11import java.util.Map;
12import java.util.Properties;
13
14import com.google.inject.AbstractModule;
15import com.google.inject.Provides;
16import com.google.inject.Singleton;
17
18public class FileManagerTestConfigModule extends AbstractModule {
19
20	@Override
21	protected void configure() {
22		bind(FileStorageProvider.class).toInstance(new StorageProviderStub());
23	}
24	
25	
26	private static class StorageProviderStub implements FileStorageProvider {
27
28		public Map<String, ByteArrayOutputStream> files = new HashMap<String, ByteArrayOutputStream>();
29		
30		
31		@Override
32		public OutputStream create(String storageId) throws IOException {
33			ByteArrayOutputStream baos = new ByteArrayOutputStream();
34			files.put(storageId, baos);
35			return baos;
36		}
37
38		@Override
39		public InputStream open(String storageId) throws IOException {
40			return new ByteArrayInputStream(files.get(storageId).toByteArray());
41		}
42		
43		
44		
45		
46	}
47	
48	
49}