AudienceHistorian { @NonNull public List<AttributeMutation> getAttributeHistory(long sinceDate) { synchronized (attributeRecords) { return filterHistory(attributeRecords, sinceDate); } } AudienceHistorian(@NonNull AirshipChannel channel, @NonNull NamedUser namedUser, @NonNull Clock clock); @NonNull List<TagGroupsMutation> getTagGroupHistory(long sinceDate); @NonNull List<AttributeMutation> getAttributeHistory(long sinceDate);  }
@Test public void getAttributeHistory() { when(mockNamedUser.getId()).thenReturn("named-user-id"); clock.currentTimeMillis = 100; final AttributeMutation channelMutation = AttributeMutation.newSetAttributeMutation("channel attribute", JsonValue.wrapOpt("some value"), 100); channelAttributeListener.onAttributeMutationsUploaded("channel-id", Collections.singletonList(channelMutation)); clock.currentTimeMillis = 200; final AttributeMutation namedUserMutation = AttributeMutation.newSetAttributeMutation("named user attribute", JsonValue.wrapOpt("some value"), 100); namedUserAttributeListener.onAttributeMutationsUploaded("named-user-id", Collections.singletonList(namedUserMutation)); List<AttributeMutation> allMutations = new ArrayList<>(); allMutations.add(channelMutation); allMutations.add(namedUserMutation); assertEquals(allMutations, historian.getAttributeHistory(100)); assertEquals(Collections.singletonList(namedUserMutation), historian.getAttributeHistory(101)); clock.currentTimeMillis = 201; assertEquals(Collections.emptyList(), historian.getAttributeHistory(201)); }
@Test public void getAttributeHistoryDifferentNamedUser() { when(mockNamedUser.getId()).thenReturn("foo"); clock.currentTimeMillis = 100; AttributeMutation fooMutation = AttributeMutation.newSetAttributeMutation("foo attribute", JsonValue.wrapOpt("some value"), 100); namedUserAttributeListener.onAttributeMutationsUploaded("foo", Collections.singletonList(fooMutation)); AttributeMutation barMutation = AttributeMutation.newSetAttributeMutation("bar attribute", JsonValue.wrapOpt("some value"), 100); namedUserAttributeListener.onAttributeMutationsUploaded("bar", Collections.singletonList(barMutation)); assertEquals(Collections.singletonList(fooMutation), historian.getAttributeHistory(0)); }