Created
June 22, 2012 07:47
-
-
Save mgenov/2971101 to your computer and use it in GitHub Desktop.
IterableTranslator.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protected Collection<Object> createCollection(Type type) | |
{ | |
// support reusing existing implementations | |
if (datastore.refresh != null) | |
{ | |
@SuppressWarnings("unchecked") | |
Collection<Object> result = (Collection<Object>) datastore.refresh; | |
datastore.refresh = null; | |
return result; | |
} | |
else | |
{ | |
if (type instanceof ParameterizedType) | |
{ | |
ParameterizedType t = (ParameterizedType) type; | |
Class<?> rawType = (Class<?>) t.getRawType(); | |
if (Set.class.isAssignableFrom(rawType)) | |
{ | |
return new HashSet<Object>(); | |
} | |
} | |
return new ArrayList<Object>(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.google.code.twig; | |
import com.google.code.twig.annotation.AnnotationObjectDatastore; | |
import com.google.code.twig.annotation.Id; | |
import org.junit.Test; | |
import java.util.HashSet; | |
import java.util.Set; | |
import static org.hamcrest.CoreMatchers.equalTo; | |
import static org.hamcrest.CoreMatchers.is; | |
import static org.junit.Assert.assertThat; | |
/** | |
* @author Miroslav Genov ([email protected]) | |
*/ | |
public class SetPersistenceTest extends LocalDatastoreTestCase { | |
static class Foo { | |
@Id | |
private String key; | |
private Set<String> items; | |
} | |
@Test | |
public void emptySetIsLoadedWhenEmptySetIsPersisted() { | |
ObjectDatastore datastore = new AnnotationObjectDatastore(true); | |
Foo foo = new Foo(); | |
foo.key = "key1"; | |
foo.items = new HashSet<String>(); | |
datastore.store().instance(foo).now(); | |
datastore.disassociateAll(); | |
Foo existingFoo = datastore.load().type(Foo.class).id(foo.key).now(); | |
assertThat(existingFoo.items.size(),is(equalTo(0))); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment