Add test for self badge fetching
This commit is contained in:
parent
c0af911197
commit
df5498e1c0
|
@ -33,6 +33,7 @@ import org.mockito.ArgumentCaptor;
|
||||||
import org.whispersystems.textsecuregcm.configuration.BadgeConfiguration;
|
import org.whispersystems.textsecuregcm.configuration.BadgeConfiguration;
|
||||||
import org.whispersystems.textsecuregcm.configuration.BadgesConfiguration;
|
import org.whispersystems.textsecuregcm.configuration.BadgesConfiguration;
|
||||||
import org.whispersystems.textsecuregcm.entities.Badge;
|
import org.whispersystems.textsecuregcm.entities.Badge;
|
||||||
|
import org.whispersystems.textsecuregcm.entities.SelfBadge;
|
||||||
import org.whispersystems.textsecuregcm.storage.AccountBadge;
|
import org.whispersystems.textsecuregcm.storage.AccountBadge;
|
||||||
|
|
||||||
public class ConfiguredProfileBadgeConverterTest {
|
public class ConfiguredProfileBadgeConverterTest {
|
||||||
|
@ -116,20 +117,20 @@ public class ConfiguredProfileBadgeConverterTest {
|
||||||
|
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
@MethodSource
|
@MethodSource
|
||||||
void testNoLocales(String name, Instant expiration, boolean visible, Badge expectedBadge) {
|
void testNoLocales(String name, Instant expiration, boolean visible, boolean isSelf, Badge expectedBadge) {
|
||||||
BadgesConfiguration badgesConfiguration = createBadges(1);
|
BadgesConfiguration badgesConfiguration = createBadges(1);
|
||||||
ConfiguredProfileBadgeConverter badgeConverter =
|
ConfiguredProfileBadgeConverter badgeConverter =
|
||||||
new ConfiguredProfileBadgeConverter(clock, badgesConfiguration, resourceBundleFactory);
|
new ConfiguredProfileBadgeConverter(clock, badgesConfiguration, resourceBundleFactory);
|
||||||
setupResourceBundle(Locale.getDefault());
|
setupResourceBundle(Locale.getDefault());
|
||||||
|
|
||||||
if (expectedBadge != null) {
|
if (expectedBadge != null) {
|
||||||
assertThat(badgeConverter.convert(List.of(), List.of(new AccountBadge(name, expiration, visible)),
|
assertThat(badgeConverter.convert(List.of(), List.of(new AccountBadge(name, expiration, visible)), isSelf))
|
||||||
false)).isNotNull()
|
.isNotNull()
|
||||||
.hasSize(1)
|
.hasSize(1)
|
||||||
.containsOnly(expectedBadge);
|
.containsOnly(expectedBadge);
|
||||||
} else {
|
} else {
|
||||||
assertThat(badgeConverter.convert(List.of(), List.of(new AccountBadge(name, expiration, visible)),
|
assertThat(badgeConverter.convert(List.of(), List.of(new AccountBadge(name, expiration, visible)), isSelf))
|
||||||
false)).isNotNull()
|
.isNotNull()
|
||||||
.isEmpty();
|
.isEmpty();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -139,15 +140,22 @@ public class ConfiguredProfileBadgeConverterTest {
|
||||||
Instant expired = Instant.ofEpochSecond(41);
|
Instant expired = Instant.ofEpochSecond(41);
|
||||||
Instant notExpired = Instant.ofEpochSecond(43);
|
Instant notExpired = Instant.ofEpochSecond(43);
|
||||||
return Stream.of(
|
return Stream.of(
|
||||||
arguments(idFor(0), expired, false, null),
|
arguments(idFor(0), expired, false, false, null),
|
||||||
arguments(idFor(0), notExpired, false, null),
|
arguments(idFor(0), notExpired, false, false, null),
|
||||||
arguments(idFor(0), expired, true, null),
|
arguments(idFor(0), expired, true, false, null),
|
||||||
arguments(idFor(0), notExpired, true, new Badge(idFor(0), "other", imageUrlFor(0), nameFor(0), desriptionFor(0))),
|
arguments(idFor(0), notExpired, true, false, new Badge(idFor(0), "other", imageUrlFor(0), nameFor(0), desriptionFor(0))),
|
||||||
arguments(idFor(1), expired, false, null),
|
arguments(idFor(1), expired, false, false, null),
|
||||||
arguments(idFor(1), notExpired, false, null),
|
arguments(idFor(1), notExpired, false, false, null),
|
||||||
arguments(idFor(1), expired, true, null),
|
arguments(idFor(1), expired, true, false, null),
|
||||||
arguments(idFor(1), notExpired, true, null)
|
arguments(idFor(1), notExpired, true, false, null),
|
||||||
);
|
arguments(idFor(0), expired, false, true, null),
|
||||||
|
arguments(idFor(0), notExpired, false, true, new SelfBadge(idFor(0), "other", imageUrlFor(0), nameFor(0), desriptionFor(0), notExpired, false)),
|
||||||
|
arguments(idFor(0), expired, true, true, null),
|
||||||
|
arguments(idFor(0), notExpired, true, true, new SelfBadge(idFor(0), "other", imageUrlFor(0), nameFor(0), desriptionFor(0), notExpired, true)),
|
||||||
|
arguments(idFor(1), expired, false, true, null),
|
||||||
|
arguments(idFor(1), notExpired, false, true, null),
|
||||||
|
arguments(idFor(1), expired, true, true, null),
|
||||||
|
arguments(idFor(1), notExpired, true, true, null));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
Loading…
Reference in New Issue