Skip to content

Commit

Permalink
Add serialVersionUID and readResolve method to service factories. Upd…
Browse files Browse the repository at this point in the history
…ated tests.
  • Loading branch information
mziccard committed Sep 21, 2015
1 parent 09e03e0 commit 0d2446e
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,28 @@
package com.google.gcloud.datastore;

import com.google.gcloud.ServiceFactory;
import java.io.ObjectStreamException;

/**
* A base class for Datastore factories.
*/
public abstract class DatastoreFactory implements ServiceFactory<Datastore, DatastoreOptions> {

private static final long serialVersionUID = 5037190305022535983L;

private static final DatastoreFactory INSTANCE = new DatastoreFactory() {
@Override
public Datastore get(DatastoreOptions options) {
return new DatastoreImpl(options, this);
}
};

private static final long serialVersionUID = 5893914895344559491L;

@Override
public Datastore get(DatastoreOptions options) {
return new DatastoreImpl(options, this);
}

private Object readResolve() throws ObjectStreamException {
return INSTANCE;
}
};

/**
* Returns the default factory instance.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,8 @@ public class SerializationTest {
@Test
public void testStorageFactory() throws Exception {
DatastoreFactory serializedCopy = serializeAndDeserialize(DATASTORE_FACTORY);
assertNotSame(DATASTORE_FACTORY, serializedCopy);
assertEquals(DATASTORE_FACTORY, serializedCopy);
assertEquals(DATASTORE_FACTORY.hashCode(), serializedCopy.hashCode());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,27 @@
package com.google.gcloud.storage;

import com.google.gcloud.ServiceFactory;
import java.io.ObjectStreamException;

/**
* A base class for Storage factories.
*/
public abstract class StorageFactory implements ServiceFactory<Storage, StorageOptions> {

private static final long serialVersionUID = 1866883249985063753L;

private static final StorageFactory INSTANCE = new StorageFactory() {

private static final long serialVersionUID = -7985210081064222485L;

@Override
public Storage get(StorageOptions options) {
return new StorageImpl(options, this);
}

private Object readResolve() throws ObjectStreamException {
return INSTANCE;
}
};

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ public class SerializationTest {
@Test
public void testStorageFactory() throws Exception {
StorageFactory serializedCopy = serializeAndDeserialize(STORAGE_FACTORY);
assertNotSame(STORAGE_FACTORY, serializedCopy);
assertEquals(STORAGE_FACTORY, serializedCopy);
assertEquals(STORAGE_FACTORY.hashCode(), serializedCopy.hashCode());
}

@Test
Expand Down

0 comments on commit 0d2446e

Please sign in to comment.