@Override public VFSRegistryEntry getValue() { return new VFSRegistryEntry(VFSRuntimeRegistry.class.getName(), ENTRY_CONTENT); }
@Override public VFSRegistryEntry getValue() { return new VFSRegistryEntry(VFSRuntimeRegistry.class.getName(), ENTRY_CONTENT); }
/** * Stores an Object marshalled value as a VFSRegistryEntry in the target path. * @param path a path for storing the generated VFSRegistryEntry. * @param value an object value to marshall and store. * @throws Exception exceptions might be thrown in cases of filesystem or marshalling errors. */ public void storeEntry(final Path path, final Object value) throws Exception { final Marshaller marshaller = marshallerRegistry.get(value.getClass()); if (marshaller == null) { throw new Exception("No marshaller was found for class: " + value.getClass()); } @SuppressWarnings("unchecked") final String marshalledValue = marshaller.marshal(value); final VFSRegistryEntry entry = new VFSRegistryEntry(value.getClass().getName(), marshalledValue); final String content = entryMarshaller.marshal(entry); writeBatch(path, content); }
@Test public void testStoreEntryWhenMarshallerExists() throws Exception { when(marshallerRegistry.get(value.getClass())).thenReturn(marshaller); when(marshaller.marshal(value)).thenReturn(MARSHALLED_VALUE); VFSRegistryEntry expectedEntry = new VFSRegistryEntry(value.getClass().getName(), MARSHALLED_VALUE); when(entryMarshaller.marshal(expectedEntry)).thenReturn(MARSHALLED_ENTRY); registryHelper.storeEntry(path, value); verify(marshallerRegistry, times(1)).get(value.getClass()); verify(registryHelper, times(1)).writeBatch(path, MARSHALLED_ENTRY); }
@Test public void testStoreEntryWhenMarshallerExists() throws Exception { when(marshallerRegistry.get(value.getClass())).thenReturn(marshaller); when(marshaller.marshal(value)).thenReturn(MARSHALLED_VALUE); VFSRegistryEntry expectedEntry = new VFSRegistryEntry(value.getClass().getName(), MARSHALLED_VALUE); when(entryMarshaller.marshal(expectedEntry)).thenReturn(MARSHALLED_ENTRY); registryHelper.storeEntry(path, value); verify(marshallerRegistry, times(1)).get(value.getClass()); verify(registryHelper, times(1)).writeBatch(path, MARSHALLED_ENTRY); }