Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.mockStatic;
Expand Down Expand Up @@ -81,19 +83,32 @@ public void tearDown() {
@Test
public void applyThemeSettings_noChangeWhenPreferenceSame() {
defaultPrefs.edit().putString("theme", "light").apply();
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
boolean changed = repository.applyThemeSettings(new String[]{"system", "light", "dark", "auto"});
assertFalse(changed);
assertEquals(AppCompatDelegate.MODE_NIGHT_NO, AppCompatDelegate.getDefaultNightMode());

try (MockedStatic<AppCompatDelegate> appCompatDelegate = mockStatic(AppCompatDelegate.class)) {
appCompatDelegate.when(AppCompatDelegate::getDefaultNightMode).thenReturn(AppCompatDelegate.MODE_NIGHT_NO);

boolean changed = repository.applyThemeSettings(new String[]{"system", "light", "dark", "auto"});

assertFalse(changed);
appCompatDelegate.verify(AppCompatDelegate::getDefaultNightMode);
appCompatDelegate.verifyNoMoreInteractions();
}
}

@Test
public void applyThemeSettings_changesWhenPreferenceDiffers() {
defaultPrefs.edit().putString("theme", "dark").apply();
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
boolean changed = repository.applyThemeSettings(new String[]{"system", "light", "dark", "auto"});
assertTrue(changed);
assertEquals(AppCompatDelegate.MODE_NIGHT_YES, AppCompatDelegate.getDefaultNightMode());

try (MockedStatic<AppCompatDelegate> appCompatDelegate = mockStatic(AppCompatDelegate.class)) {
appCompatDelegate.when(AppCompatDelegate::getDefaultNightMode).thenReturn(AppCompatDelegate.MODE_NIGHT_NO);

boolean changed = repository.applyThemeSettings(new String[]{"system", "light", "dark", "auto"});

assertTrue(changed);
appCompatDelegate.verify(AppCompatDelegate::getDefaultNightMode);
appCompatDelegate.verify(() -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES));
appCompatDelegate.verifyNoMoreInteractions();
}
}

@Test
Expand All @@ -104,6 +119,12 @@ public void getBottomNavLabelVisibilityAndDefaultTabPreferenceReturnStoredValues
assertEquals("search", repository.getDefaultTabPreference());
}

@Test
public void getBottomNavLabelVisibilityAndDefaultTabPreferenceReturnDefaultValues() {
assertEquals("never", repository.getBottomNavLabelVisibility());
assertEquals("home", repository.getDefaultTabPreference());
}

@Test
public void startupScreenDefaultsTrueAndFlipsAfterMark() {
assertTrue(repository.shouldShowStartupScreen());
Expand All @@ -114,8 +135,24 @@ public void startupScreenDefaultsTrueAndFlipsAfterMark() {
@Test
public void applyLanguageSettings_setsLocales() {
defaultPrefs.edit().putString("language", "fr").apply();
repository.applyLanguageSettings();
assertEquals("fr", AppCompatDelegate.getApplicationLocales().toLanguageTags());

final LocaleListCompat[] capturedLocale = new LocaleListCompat[1];

try (MockedStatic<AppCompatDelegate> appCompatDelegate = mockStatic(AppCompatDelegate.class)) {
appCompatDelegate
.when(() -> AppCompatDelegate.setApplicationLocales(any(LocaleListCompat.class)))
.thenAnswer(invocation -> {
capturedLocale[0] = invocation.getArgument(0);
return null;
});

repository.applyLanguageSettings();

assertNotNull(capturedLocale[0]);
assertEquals("fr", capturedLocale[0].toLanguageTags());
appCompatDelegate.verify(() -> AppCompatDelegate.setApplicationLocales(capturedLocale[0]));
appCompatDelegate.verifyNoMoreInteractions();
}
}

@Test
Expand Down