Skip to content

Commit

Permalink
Add a test to verify issue #185
Browse files Browse the repository at this point in the history
It passes, close the issue
  • Loading branch information
stickfigure committed Sep 27, 2022
1 parent d5435c1 commit bbfc82c
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/test/java/com/googlecode/objectify/test/LoadFieldRefTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -230,4 +230,41 @@ void testGrouping() throws Exception {
assertThat(fetched.multi.get(1).get()).isEqualTo(t2);
assertThat(fetched.single.get()).isSameInstanceAs(fetched.multi.get(0).get());
}

/** */
@Entity
private static class HasMultipleLoadGroupsGroups {
static class GroupA {}
static class GroupB {}

@Id Long id;
@Load({GroupA.class, GroupB.class}) Ref<Trivial> single;
}

/**
* Test which covers https://github.com/objectify/objectify/issues/185
*/
@Test
void loadGroupsWorkEvenWhenMultipleGroupsAreAnOption() throws Exception {
factory().register(HasMultipleLoadGroupsGroups.class);

final HasMultipleLoadGroupsGroups he = new HasMultipleLoadGroupsGroups();
he.single = Ref.create(k1);
HasMultipleLoadGroupsGroups fetched = saveClearLoad(he);

final Key<HasMultipleLoadGroupsGroups> hekey = Key.create(he);

assertThat(fetched.single.isLoaded()).isFalse();
assertThat(fetched.single.equivalent(k1)).isTrue();

ofy().clear();
fetched = ofy().load().group(HasMultipleLoadGroupsGroups.GroupA.class).key(hekey).now();
assertThat(fetched.single.isLoaded()).isTrue();
assertThat(fetched.single.get()).isEqualTo(t1);

ofy().clear();
fetched = ofy().load().group(HasMultipleLoadGroupsGroups.GroupB.class).key(hekey).now();
assertThat(fetched.single.isLoaded()).isTrue();
assertThat(fetched.single.get()).isEqualTo(t1);
}
}

0 comments on commit bbfc82c

Please sign in to comment.