This commit is contained in:
Junwei Bai 2024-10-19 16:38:47 +11:00
commit 306d235175
23 changed files with 115 additions and 77 deletions

View file

@ -174,7 +174,7 @@ dependencies {
kaptTest "androidx.databinding:databinding-compiler:8.0.2"
kaptAndroidTest "androidx.databinding:databinding-compiler:8.0.2"
implementation("io.github.coordinates2country:coordinates2country-android:1.3") { exclude group: 'com.google.android', module: 'android' }
implementation("io.github.coordinates2country:coordinates2country-android:1.8") { exclude group: 'com.google.android', module: 'android' }
//OSMDroid
implementation ("org.osmdroid:osmdroid-android:$OSMDROID_VERSION")

View file

@ -17,6 +17,8 @@ import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.hamcrest.MatcherAssert.assertThat
import org.hamcrest.CoreMatchers.equalTo
@LargeTest
@RunWith(AndroidJUnit4::class)
@ -59,7 +61,7 @@ class WelcomeActivityTest {
.perform(ViewActions.click())
onView(withId(R.id.finishTutorialButton))
.perform(ViewActions.click())
assert(activityRule.activity.isDestroyed)
assertThat(activityRule.activity.isDestroyed, equalTo(true))
}
}
@ -69,10 +71,10 @@ class WelcomeActivityTest {
.perform(ViewActions.click())
onView(withId(R.id.welcomePager))
.perform(ViewActions.swipeLeft())
assert(true)
assertThat(true, equalTo(true))
onView(withId(R.id.welcomePager))
.perform(ViewActions.swipeRight())
assert(true)
assertThat(true, equalTo(true))
}
@Test
@ -84,13 +86,13 @@ class WelcomeActivityTest {
.perform(ViewActions.swipeLeft())
.perform(ViewActions.swipeLeft())
.perform(ViewActions.swipeLeft())
assert(true)
assertThat(true, equalTo(true))
onView(withId(R.id.welcomePager))
.perform(ViewActions.swipeRight())
.perform(ViewActions.swipeRight())
.perform(ViewActions.swipeRight())
.perform(ViewActions.swipeRight())
assert(true)
assertThat(true, equalTo(true))
}
@Test
@ -101,10 +103,10 @@ class WelcomeActivityTest {
if (viewPager.currentItem == 3) {
onView(withId(R.id.welcomePager))
.perform(ViewActions.swipeLeft())
assert(true)
assertThat(true, equalTo(true))
onView(withId(R.id.welcomePager))
.perform(ViewActions.swipeRight())
assert(false)
assertThat(true, equalTo(true))
}
}
}
@ -119,7 +121,7 @@ class WelcomeActivityTest {
.perform(ViewActions.click())
onView(withId(R.id.finishTutorialButton))
.perform(ViewActions.click())
assert(activityRule.activity.isDestroyed)
assertThat(activityRule.activity.isDestroyed, equalTo(true))
}
}
}

View file

@ -13,7 +13,9 @@
android:maxSdkVersion="29"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.AUTHENTICATE_ACCOUNTS" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<!-- Permission needed up to Android 5.1, see https://github.com/commons-app/apps-android-commons/pull/5863 -->
<uses-permission android:name="android.permission.GET_ACCOUNTS"
android:maxSdkVersion="22"/>
<uses-permission android:name="android.permission.USE_CREDENTIALS" />
<uses-permission android:name="android.permission.MANAGE_ACCOUNTS" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>

View file

@ -40,7 +40,7 @@ class MediaConverter
metadata.licenseShortName(),
metadata.prefixedLicenseUrl,
getAuthor(metadata),
imageInfo.user,
getAuthor(metadata),
MediaDataExtractorUtil.extractCategoriesFromList(metadata.categories),
metadata.latLng,
entity.labels().mapValues { it.value.value() },

View file

@ -16,7 +16,6 @@ public interface Constants {
int PICK_PICTURE_FROM_DOCUMENTS = FILE_PICKER_IMAGE_IDENTIFICATOR + (1 << 11);
int PICK_PICTURE_FROM_GALLERY = FILE_PICKER_IMAGE_IDENTIFICATOR + (1 << 12);
int TAKE_PICTURE = FILE_PICKER_IMAGE_IDENTIFICATOR + (1 << 13);
int CAPTURE_VIDEO = FILE_PICKER_IMAGE_IDENTIFICATOR + (1 << 14);
int RECEIVE_DATA_FROM_FULL_SCREEN_MODE = 1 << 9;
}

View file

@ -109,7 +109,13 @@ public class FilePicker implements Constants {
*/
public static void openGallery(Activity activity, int type, boolean openDocumentIntentPreferred) {
Intent intent = createGalleryIntent(activity, type, openDocumentIntentPreferred);
activity.startActivityForResult(intent, RequestCodes.PICK_PICTURE_FROM_GALLERY);
int requestCode = RequestCodes.PICK_PICTURE_FROM_GALLERY;
if(openDocumentIntentPreferred){
requestCode = RequestCodes.PICK_PICTURE_FROM_DOCUMENTS;
}
activity.startActivityForResult(intent, requestCode);
}
/**
@ -157,7 +163,6 @@ public class FilePicker implements Constants {
requestCode &= ~RequestCodes.SOURCE_CHOOSER;
if (requestCode == RequestCodes.PICK_PICTURE_FROM_GALLERY ||
requestCode == RequestCodes.TAKE_PICTURE ||
requestCode == RequestCodes.CAPTURE_VIDEO ||
requestCode == RequestCodes.PICK_PICTURE_FROM_DOCUMENTS ||
requestCode == RequestCodes.PICK_PICTURE_FROM_CUSTOM_SELECTOR) {
if (resultCode == Activity.RESULT_OK) {
@ -169,19 +174,16 @@ public class FilePicker implements Constants {
onPictureReturnedFromCustomSelector(data, activity, callbacks);
} else if (requestCode == RequestCodes.TAKE_PICTURE) {
onPictureReturnedFromCamera(activity, callbacks);
} else if (requestCode == RequestCodes.CAPTURE_VIDEO) {
onVideoReturnedFromCamera(activity, callbacks);
} else if (isPhoto(data)) {
onPictureReturnedFromCamera(activity, callbacks);
} else {
onPictureReturnedFromDocuments(data, activity, callbacks);
}
} else {
if (requestCode == RequestCodes.PICK_PICTURE_FROM_DOCUMENTS) {
callbacks.onCanceled(FilePicker.ImageSource.DOCUMENTS, restoreType(activity));
} else if (requestCode == RequestCodes.PICK_PICTURE_FROM_GALLERY) {
callbacks.onCanceled(FilePicker.ImageSource.GALLERY, restoreType(activity));
} else {
} else if (requestCode == RequestCodes.PICK_PICTURE_FROM_CUSTOM_SELECTOR){
callbacks.onCanceled(ImageSource.CUSTOM_SELECTOR, restoreType(activity));
}
else {
callbacks.onCanceled(FilePicker.ImageSource.CAMERA_IMAGE, restoreType(activity));
}
}

View file

@ -19,6 +19,7 @@ import fr.free.nrw.commons.databinding.ActivityNotificationBinding;
import fr.free.nrw.commons.auth.SessionManager;
import fr.free.nrw.commons.auth.csrf.InvalidLoginTokenException;
import fr.free.nrw.commons.notification.models.Notification;
import fr.free.nrw.commons.notification.models.NotificationType;
import fr.free.nrw.commons.theme.BaseActivity;
import fr.free.nrw.commons.utils.NetworkUtils;
import fr.free.nrw.commons.utils.ViewUtil;
@ -148,7 +149,11 @@ public class NotificationActivity extends BaseActivity {
}
adapter = new NotificatinAdapter(item -> {
Timber.d("Notification clicked %s", item.getLink());
handleUrl(item.getLink());
if (item.getNotificationType() == NotificationType.EMAIL){
ViewUtil.showLongSnackbar(binding.container,getString(R.string.check_your_email_inbox));
} else {
handleUrl(item.getLink());
}
removeNotification(item);
return Unit.INSTANCE;
});

View file

@ -51,13 +51,23 @@ class NotificationClient
}
}
private fun WikimediaNotification.toCommonsNotification() =
Notification(
notificationType = NotificationType.UNKNOWN,
notificationText = contents?.compactHeader ?: "",
date = DateUtil.getMonthOnlyDateString(timestamp),
link = contents?.links?.primary?.url ?: "",
iconUrl = "",
notificationId = id().toString(),
)
private fun WikimediaNotification.toCommonsNotification() :
Notification {
val notificationText = contents?.compactHeader ?: ""
val notificationType =
if (notificationText.contains("Sent you an email", ignoreCase = true)) {
NotificationType.EMAIL
} else {
NotificationType.UNKNOWN
}
return Notification(
notificationType = notificationType,
notificationText = notificationText,
date = DateUtil.getMonthOnlyDateString(timestamp),
link = contents?.links?.primary?.url ?: "",
iconUrl = "",
notificationId = id().toString(),
)
}
}

View file

@ -4,6 +4,7 @@ public enum NotificationType {
THANK_YOU_EDIT("thank-you-edit"),
EDIT_USER_TALK("edit-user-talk"),
MENTION("mention"),
EMAIL("email"),
WELCOME("welcome"),
UNKNOWN("unknown");
private String type;

View file

@ -242,8 +242,8 @@
<string name="nominated_for_deletion">Meneget eo bet ar skeudenn evit lemel.</string>
<string name="skip_login">Lezel a-gostez</string>
<string name="navigation_item_login">Kevreañ</string>
<string name="skip_login_title" fuzzy="true">Ha c\'hoant ho peus, evit gwir, da gevreañ ?</string>
<string name="skip_login_message" fuzzy="true">Da gevreañ ho po en amzer-da-zont evit pellgargañ skeudennoù.</string>
<string name="skip_login_title">Ha n\'ho peus ket c\'hoant, evit gwir, da gevreañ ?</string>
<string name="skip_login_message">Ret e vo deoc\'h kevreañ en amzer-da-zont evit pellgargañ skeudennoù.</string>
<string name="login_alert_message">Kevreit, mar plij, evit implijout an arc\'hwel-mañ</string>
<string name="copy_wikicode">Eilañ an destenn wiki er golver</string>
<string name="wikicode_copied">Testenn wiki eilet er golver</string>

View file

@ -106,7 +106,7 @@
<string name="menu_view_file_page">Хьажа файлан агӀоне</string>
<string name="share_title_hint">Куьг йазор (ТIедилина ду)</string>
<string name="add_caption_toast">Дехар ду, хӀокху файлан цIе гайта</string>
<string name="share_description_hint">Цунах лаьцна</string>
<string name="share_description_hint">Цуьнах лаьцна</string>
<string name="share_caption_hint">Куьг</string>
<string name="login_failed_network">Чувала(йала) тара цало — сетан гӀалат</string>
<string name="login_failed_throttled">ТӀех дукха кхиаме боцу гӀертарш. Дехар ду масех минот йаьлча йуха а хьажа.</string>

View file

@ -29,6 +29,7 @@
* Sujan
* Sushi
* Tacsipacsi
* TheRabbit22
* ThisCarthing
* Tobi 406
* TomatoCake
@ -802,4 +803,17 @@
<string name="multiple_files_depiction">Bitte beachte, dass bei einem Multiupload alle Bilder die gleichen Kategorien und Bezeichnungen erhalten. Sollten die Bilder keine gemeinsamen Bezeichnungen und Kategorien haben, führe bitte mehrere separate Uploads durch.</string>
<string name="multiple_files_depiction_header">Hinweis zu Mehrfach-Uploads</string>
<string name="nearby_wikitalk">Melde ein Problem mit diesem Datenobjekt an Wikidata</string>
<string name="please_enter_some_comments">Bitte gib einige Kommentare ein</string>
<string name="talk">Diskussion</string>
<string name="write_something_about_the_item">Schreibe etwas über das Objekt %1$s. Deine Beschreibung wird öffentlich sichtbar sein.</string>
<string name="does_not_exist_anymore_no_picture_can_ever_be_taken_of_it">%1$s existiert nicht mehr, es kann kein Foto mehr davon gemacht werden.</string>
<string name="is_at_a_different_place_please_specify_the_correct_place_below_if_possible_tell_us_the_correct_latitude_longitude">%1$s ist jetzt an einem anderen Ort. Bitte gib den richtigen Ort und, wenn möglich, den Breiten- und Längengrad an.</string>
<string name="other_problem_or_information_please_explain_below">Sonstiges Problem oder Information (bitte unten erläutern).</string>
<string name="feedback_destination_note">Dein Feedback wird auf der folgenden Wiki-Seite veröffentlicht werden: &lt;a href=\"https://commons.wikimedia.org/wiki/Commons:Mobile_app/Feedback\"&gt;Commons:Mobile app/Feedback&lt;/a&gt;</string>
<string name="are_you_sure_that_you_want_cancel_all_the_uploads">Möchtest du wirklich alle Uploads abbrechen?</string>
<string name="cancelling_all_the_uploads">Alle Uploads werden abgebrochen…</string>
<string name="uploads">Hochgeladene Dateien</string>
<string name="pending">Ausstehend</string>
<string name="failed">Fehlgeschlagen</string>
<string name="could_not_load_place_data">Ortsdaten konnten nicht geladen werden</string>
</resources>

View file

@ -679,6 +679,7 @@
<string name="error_sending_thanks">作者への感謝の送信エラー。</string>
<string name="invalid_login_message">ログインが期限切れになりました。もう一度ログインしてください。</string>
<string name="no_application_available_to_open_gpx_files">GPXファイルを開くことができるアプリケーションがありません</string>
<string name="check_your_email_inbox">メールをご確認ください</string>
<plurals name="custom_picker_images_selected_title_appendix">
<item quantity="other">%d件の画像が選択されました</item>
</plurals>

View file

@ -38,7 +38,7 @@
<string name="preference_category_appearance">ਦਿੱਖ</string>
<string name="preference_category_general">ਆਮ</string>
<string name="app_name" fuzzy="true">ਵਿਕੀਮੀਡੀਆ ਕਾਮਨਜ਼</string>
<string name="menu_settings">ਸੈਟਿੰਗ</string>
<string name="menu_settings">ਪਸੰਦਾਂ</string>
<string name="username">ਵਰਤੋਂਕਾਰ ਨਾਂ</string>
<string name="password">ਲੰਘ-ਸ਼ਬਦ</string>
<string name="login">ਦਾਖ਼ਲ ਹੋਵੋ</string>
@ -85,7 +85,7 @@
<string name="categories_not_found">%1$s ਨਾਲ਼ ਮੇਲ ਖਾਂਦੀ ਕੋਈ ਸ਼੍ਰੇਣੀ ਨਹੀਂ ਲੱਭੀ</string>
<string name="categories_skip_explanation" fuzzy="true">ਆਪਣੀਆਂ ਤਸਵੀਰਾਂ ਨੂੰ ਵਿਕੀਮੀਡੀਆ ਕਾਮਨਜ਼ ਵਿਚ ਜ਼ਿਆਦਾ ਲੱਭਣਯੋਗ ਬਣਾਉਣ ਲਈ ਸ਼੍ਰੇਣੀਆਂ ਜੋੜੋ।\n\nਸ਼੍ਰੇਣੀਆਂ ਜੋੜਨ ਲਈ ਟਾਈਪ ਕਰਨ ਅਰੰਭ ਕਰੋ।\nਇਸ ਕਾਰਜ ਨੂੰ ਅਣਡਿੱਠਾ ਕਰਨ ਲਈ ਇਹ ਸੁਨੇਹਾ ਥਪੇੜੋ (ਜਾਂ ਵਾਪਸੀ ਬਟਨ ਦਬਾਓ)।</string>
<string name="categories_activity_title">ਸ਼੍ਰੇਣੀਆਂ</string>
<string name="title_activity_settings">ਸੈਟਿੰਗ</string>
<string name="title_activity_settings">ਪਸੰਦਾਂ</string>
<string name="title_activity_signup">ਸਾਈਨ ਅੱਪ</string>
<string name="title_activity_category_details">ਸ਼੍ਰੇਣੀ</string>
<string name="menu_about">ਇਸ ਬਾਰੇ</string>
@ -126,6 +126,7 @@
<string name="welcome_copyright_subtext">ਇੰਟਰਨੈੱਟ ਉੱਤੇ ਮਿਲੀ ਕਾਪੀਰਾਈਟ ਸਮੱਗਰੀ ਅਤੇ ਪੋਸਟਰਾਂ, ਕਿਤਾਬਾਂ ਦੀਆਂ ਜਿਲਦਾਂ ਦੀਆਂ ਤਸਵੀਆਂ ਆਦਿ ਤੋਂ ਪਰਹੇਜ਼ ਰੱਖੋ।</string>
<string name="welcome_final_text">ਤੁਹਾਨੂੰ ਲੱਗਦਾ ਹੈ ਕਿ ਤੁਹਾਡੇ ਕੋਲ ਹੈ?</string>
<string name="welcome_final_button_text">ਹਾਂ!</string>
<string name="welcome_help_button_text">ਹੋਰ ਜਾਣਕਾਰੀ</string>
<string name="detail_panel_cats_label">ਸ਼੍ਰੇਣੀਆਂ</string>
<string name="detail_panel_cats_loading">ਲੱਦ ਰਿਹਾ ਹੈ...</string>
<string name="detail_panel_cats_none">ਕੋਈ ਵੀ ਨਹੀਂ ਚੁਣਿਆ</string>
@ -148,8 +149,8 @@
<string name="media_detail_coordinates_empty">ਕੋਈ ਉਪਲਬਧ ਨਹੀਂ</string>
<string name="_2fa_code">2FA ਕੋਡ</string>
<string name="logout_verification">ਕੀ ਤੁਸੀਂ ਸੱਚੀਂ ਬੰਦ ਕਰਨਾ ਚਾਹੁੰਦੇ ਹੋ?</string>
<string name="welcome_image_welcome_wikipedia">ਵਿਕੀਪੀਡੀਆ \'ਤੇ ਸੁਆਗਤ</string>
<string name="welcome_image_welcome_copyright">ਕਾਪੀਰਾਈਟ ਸੁਆਗਤ</string>
<string name="welcome_image_welcome_wikipedia">ਵਿਕੀਪੀਡੀਆ \'ਤੇ ਜੀ ਆਇਆਂ ਨੂੰ</string>
<string name="welcome_image_welcome_copyright">ਜੀ ਆਇਆਂ ਨੂੰ ਕਾਪੀਰਾਈਟ</string>
<string name="cancel">ਰੱਦ ਕਰੋ</string>
<string name="navigation_drawer_open">ਖੋਲ੍ਹੋ</string>
<string name="navigation_drawer_close">ਬੰਦ ਕਰੋ</string>
@ -177,10 +178,14 @@
<string name="about_translate_cancel">ਰੱਦ ਕਰੋ</string>
<string name="menu_search_button">ਲੱਭੋ</string>
<string name="title_activity_search">ਲੱਭੋ</string>
<string name="search_recent_header">ਹਾਲੀਆ ਖੋਜਾਂ:</string>
<string name="provider_searches">ਹਾਲ ਦੀਆਂ ਪੁੱਛਗਿੱਛ ਖੋਜਾਂ</string>
<string name="provider_recent_languages">ਹਾਲ ਹੀ ਵਿੱਚ ਬੋਲੀਆਂ ਬਾਰੇ ਪੁੱਛਗਿੱਛ</string>
<string name="search_tab_title_categories">ਸ਼੍ਰੇਣੀਆਂ</string>
<string name="explore_tab_title_map">ਨਕਸ਼ਾ</string>
<string name="question">ਸਵਾਲ</string>
<string name="continue_message">ਜਾਰੀ ਰੱਖੋ</string>
<string name="no_recent_searches">ਕੋਈ ਤਾਜ਼ਾ ਖੋਜ ਨਹੀਂ</string>
<string name="delete">ਮਿਟਾਓ</string>
<string name="Achievements">ਪ੍ਰਾਪਤੀਆਂ</string>
<string name="statistics">ਅੰਕੜੇ</string>
@ -199,6 +204,7 @@
<string name="copied_successfully">ਉਤਾਰਾ ਕੀਤਾ</string>
<string name="exif_tag_name_location">ਟਿਕਾਣਾ</string>
<string name="wikipedia_instructions_step_7">ਲਿਖਤ ਛਾਪੋ</string>
<string name="leaderboard_tab_title">ਮੁਹਰੈਲ</string>
<string name="leaderboard_column_user">ਵਰਤੋਂਕਾਰ</string>
<string name="invalid_login_message">ਤੁਹਾਡੇ ਦਾਖਲੇ ਦੀ ਮਿਆਦ ਪੁੱਗ ਗਈ ਹੈ। ਕਿਰਪਾ ਕਰਕੇ ਦੁਬਾਰਾ ਦਾਖਲ ਹੋਵੋ।</string>
</resources>

View file

@ -111,4 +111,5 @@
<string name="detail_description_empty">没有说明</string>
<string name="detail_license_empty">未知授权协议</string>
<string name="menu_refresh">刷新</string>
<string name="check_your_email_inbox">请查看你的电子邮箱</string>
</resources>

View file

@ -215,4 +215,5 @@
<string name="description_info">請盡可能描述媒體內容:拍攝於何處?是顯示什麼事物?有什麼脈絡?請描述對象或人物。透露出一些較不易猜測的訊息,例如是風景的話,可以是一天裡的時間。如果媒體顯示出了一些不尋常的事物,請說明不尋常原因。</string>
<string name="learn_how_to_write_a_useful_description">學習如何編寫有用的描述</string>
<string name="learn_how_to_write_a_useful_caption">學習如何編寫有用的標題</string>
<string name="check_your_email_inbox">請查看你的電子郵件信箱</string>
</resources>

View file

@ -805,4 +805,5 @@
<string name="pending">待處理</string>
<string name="failed">失敗</string>
<string name="could_not_load_place_data">無法載入地點資料</string>
<string name="check_your_email_inbox">請查看你的電子郵件信箱</string>
</resources>

View file

@ -7,6 +7,7 @@
* A Retired User
* Aefgh39622
* Angrydog001
* Chimes
* Crowley666
* D41D8CD98F
* Deathkon
@ -827,4 +828,11 @@
<string name="is_at_a_different_place_please_specify_the_correct_place_below_if_possible_tell_us_the_correct_latitude_longitude">“%1$s”位于一个不同的位置。请在下方给出正确的位置可以的话请填写正确的经纬度。</string>
<string name="other_problem_or_information_please_explain_below">其他问题或信息(请在下方解释)。</string>
<string name="feedback_destination_note">您的反馈已经发布在以下wiki页面&lt;a href=\"https://commons.wikimedia.org/wiki/Commons:Mobile_app/Feedback\"&gt;Commons:Mobile app/Feedback&lt;/a&gt;</string>
<string name="are_you_sure_that_you_want_cancel_all_the_uploads">您确定要取消所有上传吗?</string>
<string name="cancelling_all_the_uploads">取消所有的上传...</string>
<string name="uploads">上传</string>
<string name="pending">待处理</string>
<string name="failed">失败</string>
<string name="could_not_load_place_data">无法加载地点数据</string>
<string name="check_your_email_inbox">请查看你的电子邮箱</string>
</resources>

View file

@ -504,6 +504,7 @@ Upload your first media by tapping on the add button.</string>
<string name="no_notification">You have no unread notifications</string>
<string name="no_read_notification">You have no read notifications</string>
<string name="share_logs_using">Share logs using</string>
<string name="check_your_email_inbox">Check your email inbox</string>
<string name="menu_option_read">View read</string>
<string name="menu_option_unread">View unread</string>

View file

@ -18,7 +18,7 @@ WHERE {
}
# Get the label in the preferred language of the user, or any other language if no label is available in that language.
OPTIONAL {?item rdfs:label ?itemLabelPreferredLanguage. FILTER (lang(?itemLabelPreferredLanguage) = "en")}
OPTIONAL {?item rdfs:label ?itemLabelPreferredLanguage. FILTER (lang(?itemLabelPreferredLanguage) = "${LANG}")}
OPTIONAL {?item rdfs:label ?itemLabelAnyLanguage}
BIND(COALESCE(?itemLabelPreferredLanguage, ?itemLabelAnyLanguage, "?") as ?label)

View file

@ -64,12 +64,17 @@ class FilePickerTest {
`when`(PreferenceManager.getDefaultSharedPreferences(activity)).thenReturn(sharedPref)
`when`(sharedPref.edit()).thenReturn(sharedPreferencesEditor)
`when`(sharedPref.edit().putInt("type", 0)).thenReturn(sharedPreferencesEditor)
FilePicker.openGallery(activity, 0, nextBoolean())
val openDocumentPreferred = nextBoolean()
FilePicker.openGallery(activity, 0, openDocumentPreferred)
verify(activity).startActivityForResult(
ArgumentMatchers.any(),
requestCodeCaptor?.capture()?.toInt()!!,
)
assertEquals(requestCodeCaptor?.value, RequestCodes.PICK_PICTURE_FROM_GALLERY)
if(openDocumentPreferred){
assertEquals(requestCodeCaptor?.value, RequestCodes.PICK_PICTURE_FROM_DOCUMENTS)
}else{
assertEquals(requestCodeCaptor?.value, RequestCodes.PICK_PICTURE_FROM_GALLERY)
}
}
@Test
@ -165,32 +170,6 @@ class FilePickerTest {
method.invoke(mockFilePicker, activity)
}
@Test
fun testTakenCameraVideo() {
val mockFilePicker = mock(FilePicker::class.java)
val method: Method =
FilePicker::class.java.getDeclaredMethod(
"takenCameraVideo",
Context::class.java,
)
method.isAccessible = true
method.invoke(mockFilePicker, context)
}
@Test
fun testTakenCameraVideoCaseTrue() {
val mockFilePicker = mock(FilePicker::class.java)
`when`(PreferenceManager.getDefaultSharedPreferences(activity)).thenReturn(sharedPref)
`when`(sharedPref.getString("last_video", null)).thenReturn("")
val method: Method =
FilePicker::class.java.getDeclaredMethod(
"takenCameraVideo",
Context::class.java,
)
method.isAccessible = true
method.invoke(mockFilePicker, activity)
}
@Test
fun testIsPhoto() {
val mockFilePicker = mock(FilePicker::class.java)

View file

@ -2,6 +2,9 @@ package fr.free.nrw.commons.location
import org.junit.Before
import org.junit.Test
import org.hamcrest.MatcherAssert.assertThat
import org.hamcrest.CoreMatchers.equalTo
import org.hamcrest.CoreMatchers.not
class LatLngTest {
private lateinit var latLng1: LatLng
@ -14,51 +17,51 @@ class LatLngTest {
@Test
fun testConstructorSmallLongitude() {
latLng1 = LatLng(0.0, -181.0, 0.0f)
assert(latLng1.longitude == 179.0)
assertThat(latLng1.longitude, equalTo(179.0))
}
@Test
fun testConstructorBigLongitude() {
latLng1 = LatLng(0.0, 181.0, 0.0f)
assert(latLng1.longitude == -179.0)
assertThat(latLng1.longitude, equalTo(-179.0))
}
@Test
fun testConstructorSmallLatitude() {
latLng1 = LatLng(-91.0, 0.0, 0.0f)
assert(latLng1.latitude == -90.0)
assertThat(latLng1.latitude, equalTo(-90.0))
}
@Test
fun testConstructorBigLatitude() {
latLng1 = LatLng(91.0, 0.0, 0.0f)
assert(latLng1.latitude == 90.0)
assertThat(latLng1.latitude, equalTo(90.0))
}
@Test
fun testHashCodeDiffersWenLngZero() {
latLng1 = LatLng(2.0, 0.0, 0.0f)
latLng2 = LatLng(1.0, 0.0, 0.0f)
assert(latLng1.hashCode() != latLng2.hashCode())
assertThat(latLng1.hashCode(), not(equalTo(latLng2.hashCode())))
}
@Test
fun testHashCodeDiffersWenLatZero() {
latLng1 = LatLng(0.0, 1.0, 0.0f)
latLng2 = LatLng(0.0, 2.0, 0.0f)
assert(latLng1.hashCode() != latLng2.hashCode())
assertThat(latLng1.hashCode(), not(equalTo(latLng2.hashCode())))
}
@Test
fun testEqualsWorks() {
latLng1 = LatLng(1.0, 2.0, 5.0f)
latLng2 = LatLng(1.0, 2.0, 0.0f)
assert(latLng1.equals(latLng2))
assertThat(latLng1, equalTo(latLng2))
}
@Test
fun testToString() {
latLng1 = LatLng(1.0, 2.0, 5.0f)
assert(latLng1.toString().equals("lat/lng: (1.0,2.0)"))
assertThat(latLng1.toString(), equalTo("lat/lng: (1.0,2.0)"))
}
}

View file

@ -3,6 +3,8 @@ package fr.free.nrw.commons.nearby
import fr.free.nrw.commons.R
import org.junit.Before
import org.junit.Test
import org.hamcrest.MatcherAssert.assertThat
import org.hamcrest.CoreMatchers.equalTo
class LabelTest {
private lateinit var label: Label
@ -21,7 +23,7 @@ class LabelTest {
*/
@Test
fun testLabelIcon() {
assert(label.icon.equals(R.drawable.round_icon_church))
assertThat(label.icon, equalTo(R.drawable.round_icon_church))
}
/**
@ -30,6 +32,6 @@ class LabelTest {
@Test
fun testNullLabelIcon() {
var nullLabel: Label = Label.fromText("a random text not exist in label texts")
assert(nullLabel.icon.equals(R.drawable.round_icon_unknown))
assertThat(nullLabel.icon, equalTo(R.drawable.round_icon_unknown))
}
}