Skip to content

Commit

Permalink
Fixed some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
federicoiosue committed Oct 28, 2023
1 parent 40ce838 commit 0eadf44
Show file tree
Hide file tree
Showing 17 changed files with 79 additions and 80 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class DocumentFileHelperTest : BaseAndroidTestCase() {
}

@Test
@Ignore("runned manually")
@Ignore("run manually")
fun copyFileTo_performance() {
for (i in 1..50) copyFileTo()

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright (C) 2013-2023 Federico Iosue (federico@iosue.it)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package it.feio.android.omninotes.helpers

import it.feio.android.omninotes.testutils.BaseAndroidTestCase
import org.junit.Assert.assertNotNull
import org.junit.Assert.assertTrue
import org.junit.Test

class GeocodeProviderBaseFactoryTest : BaseAndroidTestCase() {

@Test
@Throws(Exception::class)
fun checkUtilityClassWellDefined() {
assertUtilityClassWellDefined(GeocodeProviderBaseFactory::class.java, true, true)
}

@Test
fun provider() {
assertNotNull(GeocodeProviderBaseFactory.getProvider(testContext))
}

@Test
fun checkHighAccuracyLocationProvider() {
assertTrue(GeocodeProviderBaseFactory.checkHighAccuracyLocationProvider(testContext))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
import it.feio.android.omninotes.async.bus.NotesUpdatedEvent;
import it.feio.android.omninotes.db.DbHelper;
import it.feio.android.omninotes.exceptions.TestException;
import it.feio.android.omninotes.helpers.BuildVersionHelper;
import it.feio.android.omninotes.helpers.BuildHelper;
import it.feio.android.omninotes.models.Attachment;
import it.feio.android.omninotes.models.Category;
import it.feio.android.omninotes.models.Note;
Expand Down Expand Up @@ -98,9 +98,12 @@ public void tearDown() {

private static void grantPermissions() {
GrantPermissionRule.grant(ACCESS_COARSE_LOCATION, ACCESS_FINE_LOCATION, READ_EXTERNAL_STORAGE, RECORD_AUDIO);
if (BuildVersionHelper.isBelowOrEqual(VERSION_CODES.Q)) {
if (BuildHelper.isBelowOrEqual(VERSION_CODES.Q)) {
GrantPermissionRule.grant(WRITE_EXTERNAL_STORAGE);
}
if (BuildHelper.isAboveOrEqual(VERSION_CODES.TIRAMISU)) {
GrantPermissionRule.grant(POST_NOTIFICATIONS);
}
}

private void preparePreferences() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import static android.text.Html.fromHtml;
import static android.text.TextUtils.isEmpty;
import static androidx.core.view.ViewCompat.animate;
import static it.feio.android.omninotes.helpers.BuildHelper.isDebugBuild;
import static it.feio.android.omninotes.utils.ConstantsBase.ACTION_FAB_TAKE_PHOTO;
import static it.feio.android.omninotes.utils.ConstantsBase.ACTION_MERGE;
import static it.feio.android.omninotes.utils.ConstantsBase.ACTION_POSTPONE;
Expand Down Expand Up @@ -1260,7 +1261,7 @@ public void onEvent(PasswordRemovedEvent passwordRemovedEvent) {
}

private void animateListView() {
if (!OmniNotes.isDebugBuild()) {
if (!isDebugBuild()) {
animate(binding.progressWheel)
.setDuration(getResources().getInteger(R.integer.list_view_fade_anim)).alpha(0);
animate(binding.list).setDuration(getResources().getInteger(R.integer.list_view_fade_anim))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@

package it.feio.android.omninotes;

import static it.feio.android.omninotes.OmniNotes.isDebugBuild;
import static it.feio.android.omninotes.helpers.AppVersionHelper.isAppUpdated;
import static it.feio.android.omninotes.helpers.AppVersionHelper.updateAppVersionInPreferences;
import static it.feio.android.omninotes.helpers.BuildHelper.isDebugBuild;
import static it.feio.android.omninotes.helpers.ChangelogHelper.showChangelog;
import static it.feio.android.omninotes.utils.ConstantsBase.ACTION_NOTIFICATION_CLICK;
import static it.feio.android.omninotes.utils.ConstantsBase.ACTION_RESTART_APP;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package it.feio.android.omninotes;

import static it.feio.android.omninotes.helpers.BuildHelper.isDebugBuild;
import static it.feio.android.omninotes.utils.Constants.PACKAGE;
import static it.feio.android.omninotes.utils.ConstantsBase.PREF_LANG;

Expand All @@ -39,10 +40,6 @@ public class OmniNotes extends MultiDexApplication {

private static Context mContext;

public static boolean isDebugBuild() {
return BuildConfig.BUILD_TYPE.equals("debug");
}

public static Context getAppContext() {
return OmniNotes.mContext;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import it.feio.android.omninotes.BaseActivity;
import it.feio.android.omninotes.OmniNotes;
import it.feio.android.omninotes.db.DbHelper;
import it.feio.android.omninotes.helpers.BuildVersionHelper;
import it.feio.android.omninotes.helpers.BuildHelper;
import it.feio.android.omninotes.helpers.LogDelegate;
import it.feio.android.omninotes.models.Note;
import it.feio.android.omninotes.utils.ReminderHelper;
Expand All @@ -39,7 +39,7 @@ public class AlarmRestoreOnRebootService extends JobIntentService {
public static final int JOB_ID = 0x01;

public static void enqueueWork(Context context, Intent work) {
if (BuildVersionHelper.isAboveOrEqual(VERSION_CODES.O)) {
if (BuildHelper.isAboveOrEqual(VERSION_CODES.O)) {
enqueueWork(context, AlarmRestoreOnRebootService.class, JOB_ID, work);
} else {
Intent jobIntent = new Intent(context, AlarmRestoreOnRebootService.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@
package it.feio.android.omninotes.helpers

import android.os.Build
import it.feio.android.omninotes.BuildConfig

class BuildVersionHelper {
class BuildHelper {

companion object {
@JvmStatic
Expand All @@ -41,5 +42,10 @@ class BuildVersionHelper {
fun isBelow(sdk: Int): Boolean {
return Build.VERSION.SDK_INT < sdk
}

@JvmStatic
fun isDebugBuild(): Boolean {
return BuildConfig.BUILD_TYPE == "debug"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ protected GeocodeProviderBaseFactory() {
}

public static LocationProvider getProvider(Context context) {
if (BuildVersionHelper.isBelow(VERSION_CODES.P) && checkHighAccuracyLocationProvider(context)) {
if (BuildHelper.isBelow(VERSION_CODES.P) && checkHighAccuracyLocationProvider(context)) {
Toast.makeText(context, R.string.location_set_high_accuracy, Toast.LENGTH_SHORT).show();
context.startActivity((new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS)));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,15 @@ public static PendingIntent getNotePendingIntent(@NonNull Context context, @NonN

public static int immutablePendingIntentFlag(final int flag) {
int pIntentFlags = flag;
if (BuildVersionHelper.isAboveOrEqual(VERSION_CODES.M)) {
if (BuildHelper.isAboveOrEqual(VERSION_CODES.M)) {
pIntentFlags = pIntentFlags | FLAG_IMMUTABLE;
}
return pIntentFlags;
}

public static int mutablePendingIntentFlag(final int flag) {
int pIntentFlags = flag;
if (BuildVersionHelper.isAboveOrEqual(VERSION_CODES.S)) {
if (BuildHelper.isAboveOrEqual(VERSION_CODES.S)) {
pIntentFlags = pIntentFlags | FLAG_MUTABLE;
}
return pIntentFlags;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public static String getCurrentLocaleAsString(Context context) {
}

public static Locale getCurrentLocale(Context context) {
if (BuildVersionHelper.isAboveOrEqual(VERSION_CODES.N)) {
if (BuildHelper.isAboveOrEqual(VERSION_CODES.N)) {
return context.getResources().getConfiguration().getLocales().get(0);
} else {
return context.getResources().getConfiguration().locale;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

import android.app.Activity;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Build.VERSION_CODES;
import android.view.View;
import androidx.core.app.ActivityCompat;
Expand Down Expand Up @@ -65,7 +64,7 @@ public static void requestPermission(Activity activity, String permission,
}

private static boolean skipPermissionRequest(String permission) {
return BuildVersionHelper.isAbove(VERSION_CODES.Q) && permission.equals(WRITE_EXTERNAL_STORAGE);
return BuildHelper.isAbove(VERSION_CODES.Q) && permission.equals(WRITE_EXTERNAL_STORAGE);
}

private static void requestPermissionExecute(Activity activity, String permission,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
import it.feio.android.omninotes.MainActivity;
import it.feio.android.omninotes.R;
import it.feio.android.omninotes.async.bus.NotificationsGrantedEvent;
import it.feio.android.omninotes.helpers.BuildVersionHelper;
import it.feio.android.omninotes.helpers.BuildHelper;
import lombok.NonNull;


Expand All @@ -71,7 +71,7 @@ public NotificationsHelper(Context mContext) {
*/
@TargetApi(VERSION_CODES.O)
public void initNotificationChannels() {
if (BuildVersionHelper.isAboveOrEqual(VERSION_CODES.O)) {
if (BuildHelper.isAboveOrEqual(VERSION_CODES.O)) {

String soundFromPrefs = Prefs.getString("settings_notification_ringtone", null);
Uri sound = soundFromPrefs != null ? Uri.parse(soundFromPrefs)
Expand All @@ -97,7 +97,7 @@ public void initNotificationChannels() {

@TargetApi(Build.VERSION_CODES.O)
public void updateNotificationChannelsSound() {
if (BuildVersionHelper.isAboveOrEqual(VERSION_CODES.O)) {
if (BuildHelper.isAboveOrEqual(VERSION_CODES.O)) {
Intent intent = new Intent(Settings.ACTION_APP_NOTIFICATION_SETTINGS);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra(Settings.EXTRA_APP_PACKAGE, mContext.getPackageName());
Expand Down Expand Up @@ -148,7 +148,7 @@ public NotificationsHelper setLargeIcon(int largeIconResource) {
}

public NotificationsHelper setRingtone(String ringtone) {
if (ringtone != null && BuildVersionHelper.isBelow(VERSION_CODES.O)) {
if (ringtone != null && BuildHelper.isBelow(VERSION_CODES.O)) {
mBuilder.setSound(Uri.parse(ringtone));
}
return this;
Expand Down Expand Up @@ -242,13 +242,14 @@ public void cancel(int id) {
}

public boolean checkNotificationsEnabled(Context context) {
return BuildVersionHelper.isBelow(VERSION_CODES.TIRAMISU)
return BuildHelper.isBelow(VERSION_CODES.TIRAMISU)
|| BuildHelper.isDebugBuild()
|| ContextCompat.checkSelfPermission(context, permission.POST_NOTIFICATIONS)
== PackageManager.PERMISSION_GRANTED;
}

public void askToEnableNotifications(ComponentActivity activity) {
if (BuildVersionHelper.isAboveOrEqual(VERSION_CODES.TIRAMISU)) {
if (BuildHelper.isAboveOrEqual(VERSION_CODES.TIRAMISU)) {
if (!checkNotificationsEnabled(activity)) {
activity.registerForActivityResult(new RequestPermission(),
isGranted -> EventBus.getDefault().post(new NotificationsGrantedEvent(isGranted)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@

package it.feio.android.omninotes.intro;

import static it.feio.android.omninotes.helpers.BuildHelper.isDebugBuild;
import static it.feio.android.omninotes.utils.ConstantsBase.PREF_TOUR_COMPLETE;

import android.os.Bundle;
import com.github.paolorotolo.appintro.AppIntro2;
import com.pixplicity.easyprefs.library.Prefs;
import it.feio.android.omninotes.OmniNotes;


public class IntroActivity extends AppIntro2 {
Expand All @@ -44,7 +44,7 @@ public void onDonePressed() {
}

public static boolean mustRun() {
return !OmniNotes.isDebugBuild() && !Prefs.getBoolean(PREF_TOUR_COMPLETE, false);
return !isDebugBuild() && !Prefs.getBoolean(PREF_TOUR_COMPLETE, false);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
import com.pixplicity.easyprefs.library.Prefs;
import it.feio.android.omninotes.MainActivity;
import it.feio.android.omninotes.R;
import it.feio.android.omninotes.helpers.BuildVersionHelper;
import it.feio.android.omninotes.helpers.BuildHelper;
import it.feio.android.omninotes.helpers.date.DateHelper;
import it.feio.android.omninotes.models.Note;
import lombok.SneakyThrows;
Expand All @@ -54,7 +54,7 @@ public static void addShortcut(Context context, Note note) {
.getCreation(),
Prefs.getBoolean(PREF_PRETTIFIED_DATES, true));

if (BuildVersionHelper.isBelow(VERSION_CODES.O)) {
if (BuildHelper.isBelow(VERSION_CODES.O)) {
createShortcutPreOreo(context, note, shortcutTitle);
} else {
createShortcutPostOreo(context, note, shortcutTitle);
Expand Down Expand Up @@ -118,7 +118,7 @@ private static void createShortcutPreOreo(Context context, Note note, String sho
* Removes note shortcut from home launcher
*/
public static void removeShortcut(Context context, Note note) {
if (BuildVersionHelper.isBelow(VERSION_CODES.O)) {
if (BuildHelper.isBelow(VERSION_CODES.O)) {
removeShortcutPreOreo(context, note);
} else {
removeShortcutPostOreo(context, note);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,10 @@ public void getNoteInfo() {
var contextMock = getContextMock();
try (
MockedStatic<OmniNotes> omniNotes = mockStatic(OmniNotes.class);
MockedStatic<BuildVersionHelper> buildVersionHelper = mockStatic(BuildVersionHelper.class);
MockedStatic<BuildHelper> buildVersionHelper = mockStatic(BuildHelper.class);
) {
omniNotes.when(OmniNotes::getAppContext).thenReturn(contextMock);
buildVersionHelper.when(() -> BuildVersionHelper.isAboveOrEqual(VERSION_CODES.N)).thenReturn(true);
buildVersionHelper.when(() -> BuildHelper.isAboveOrEqual(VERSION_CODES.N)).thenReturn(true);

var info = NotesHelper.getNoteInfo(new Note());

Expand Down

0 comments on commit 0eadf44

Please sign in to comment.