Skip to content

Commit

Permalink
Squashed 'libs/utils/' changes from a15de7604a..1a43e016c6
Browse files Browse the repository at this point in the history
1a43e016c6 Merge pull request #29 from wordpress-mobile/issue/28-empty-img-tag-crash-fix
a4c24373e5 Updated the release version to 1.24
a33296f4d6 Check if img source is null before checking for image smileys
1dd7406ad5 Merge pull request #27 from wordpress-mobile/combined-updates-from-wpandroid
b918b23ac5 Check if announcement is available in App Settings before showing option. Updated AppLog to include announcement related tracker.
94e23e28c1 Rename build.gradle fields with invalid name syntax
d0be1240ca Make sure url utils recognizes atomic image proxy as valid image url.
9bdbdff3a9 Merge branch 'feature/support-private-at-sites' of https://github.com/wordpress-mobile/WordPress-Android into feature/support-private-at-sites
fcc5c99e37 Updated Photon utils to utilize new url for private AT proxy.
130195092f Gutenberg/integrate release 1.25.0 with dark mode (#11580)
a25096c291 Restoring Utils lib version to 1.24
edfef1e58c Merge branch 'develop' into issue/11249-media-not-load-jetpack
60d516266e Merge pull request #11536 from wordpress-mobile/add/log-persistence
1aceca9950 Make the linter happy
18c8447fe3 Change provider visibility
dac4e5ce38 Fixes to LogFileHelpersTest
76f9f75f5d Variablize recent created files test
a4d0a773e7 Small fixes for LogFileCleanerTest
24ac53fabf Make the queue private
64ea6a8cdf Use correct hungarian notation for static member
1c978ca61a Refactor tests to match project refactoring
565b88903c Persist log files in a background thread
3ae86d48e4 Refactor LogEntry.toString method
b900bdda83 Refactor LogFileHelpers to not use context and be a LogFileProvider
225e1db645 Upgrading lib version.
6fd47e8eb6 Using the assertThat pattern.
0948a93056 Adding connected testing.
dc5c2e3cd6 Refactor LogFileWriter to use LogFileProvider instead of context
2d5d0b65c0 Refactor LogFileCleaner to not need context and use a LogFileProvider instead
84b7a8a87d Minor changes in LogFileWriter to make it more idiomatic
8cfa0950aa Merge branch 'develop' into issue/11249-media-not-load-jetpack
31a14daeb4 Bump the utils minSdkVersion to 18
f65fd78414 Add log persistence
fe3960d6b7 Updating ssl logic for photon addresses.
1b4b31bf88 Merge pull request #11524 from wordpress-mobile/fix/wordpressutils-tests
6c80419806 Fix WordPressUtils tests
def5be4e88 Revert "Feature/material theme and Dark Theme support (#11469)" (#11486)
16540e85f1 Feature/material theme and Dark Theme support (#11469)
0ae297bbd3 Adding ssl parameter to query for Photon https.
89725645a6 made method name more meaningful.
76343d3d6d Added util function to check if a Uri is a content one.
75790052ef Merge pull request #11072 from wordpress-mobile/issue-10843/latitude_fix_api_29
981eb82158 Merge branch 'develop' into try/media-upload-completion-processor
8799a19ec4 removes safe check due to nature of RecyclerView
7906f07645 Fixed latitude missing column issue on api 29
882a64faf3 updated gradle wrapper of utils project.
b012d38c3f resolved conflicts and merged utils subtree
e8aae6d282 Merge branch 'develop' into try/media-upload-completion-processor
da19376391 Add MediaFile method to generate attachment page url
e35a9e0cd8 Used delegate safe method for focused accessibility event listener
de02499434 Merge remote-tracking branch 'origin/develop' into issue/10894-aztec-media-talkback
1812393e22 Added accessibility heading
30aa9a3132 Added a safe way to set accessibility delegates.
870518ff07 Moved method to util class that's more appropriate for it's behavior
a998f6e877 added annotations to event listener method
43013a5a79 Moved behavior to Utils so that it can be replicated in other areas.
54ca204429 Removed unused imports.
373db7c13f Removed unneeded whitespace and added necessary whiteline
785da6617b WP Media Picker now announces when an image is selected.
75f0913259 "Done" button now has a content description of "Cancel"
42ec1fb96c Disabled hint announcements and applied accessibility headings
916e2b0d96 Add comment to downloadExternalMedia method
573ba7f5e8 Clean up AddMediaToEditor logic
dda3a1ebb8 Merge pull request #10565 from wordpress-mobile/clean-up-after-legacy-editor
d84fb1f61f Upgrade Gradle to 5.4.1, gradle plugin to 3.5.1 and fix various errors
0511354994 Remove WPEditText
19d3f4aaf0 Optimize AppLog
b4401cd84f Fix simple date format concurrency issue
15ee1b27d0 Remove usages of buggy DateTimeUtils methods
e9f01e5e3c Fixed loop.
47eec63356 Merge branch 'develop' of github.com:wordpress-mobile/WordPress-Android into issue/9815-email-verification-reminder
25d1310312 Fix AndroidX import order
a21c7120d8 Fix import ordering for androidx
35b99bc73e Migrate to AndroidX
d40e8773bb Merge branch 'issue/9815-create-call-to-action' into issue/9815-add-reminder-message
892eacce49 Make getPath private again
ae6291c612 Use existing method instead of creating a new one in MediaUtils
10b59f8d06 Implement comments from PR
f1b21d0acc Add logging for the failing cases
702881b26f A crash fix for uploaded docs
cc1c0334a8 Added reminder message toast after domain has been registered
9a14564929 Merge branch 'develop' of github.com:wordpress-mobile/WordPress-Android into issue/9452-domain-suggestions
a4d8873a2e Update style config from style-config-android
1c10935b8c Merge branch 'develop' of github.com:wordpress-mobile/WordPress-Android into issue/9452-domain-suggestions
971cf76d96 Remove unused get snackbar duration method from accessibility utils class
28b0685ae7 Update is accessibility enabled method in accessibility utils for simplicity
a418cb7dc8 Update get snackbar duration method in accessibility utils for indefinite constant
e0dd4824c9 Merge branch 'develop' of github.com:wordpress-mobile/WordPress-Android into issue/9452-domain-suggestions
506f9883ce refactored ToastUtils to be able to pass gravity as param. Also showing toast after back-dating a scheduled post on top anchor now
e164cd7a61 Fixing merge conflicts from domain register branch.
586222ec51 Merge pull request #8164 from usamahamid/feature/domain-register
50de29e20a Introduced Domain Suggestion Network request in ViewModel

git-subtree-dir: libs/utils
git-subtree-split: 1a43e016c63bd9dc19f3e27d39b8dc1cba7c5263
  • Loading branch information
mzorz committed Jun 11, 2020
1 parent 90001f8 commit 56e3b3f
Show file tree
Hide file tree
Showing 39 changed files with 824 additions and 183 deletions.
38 changes: 32 additions & 6 deletions WordPressUtils/build.gradle
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
buildscript {
ext.kotlinVersion = '1.3.61'

repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
classpath 'com.novoda:bintray-release:0.9'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
classpath 'com.android.tools.build:gradle:3.5.1'
classpath 'com.novoda:bintray-release:0.9.1'
}
}

apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'com.novoda.bintray-release'

repositories {
Expand All @@ -19,15 +24,25 @@ repositories {

dependencies {
implementation 'org.apache.commons:commons-text:1.1'
implementation 'com.mcxiaoke.volley:library:1.0.18'
implementation 'com.android.support:design:28.0.0'
implementation 'com.android.support:recyclerview-v7:28.0.0'
implementation 'com.android.volley:volley:1.1.1'
implementation 'com.google.android.material:material:1.0.0'
implementation 'androidx.recyclerview:recyclerview:1.0.0'
implementation 'org.greenrobot:eventbus:3.0.0'

implementation "androidx.core:core-ktx:+"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlinVersion"

testImplementation 'junit:junit:4.12'
testImplementation 'org.assertj:assertj-core:3.11.1'
testImplementation "org.robolectric:robolectric:4.3.1"
testImplementation 'androidx.test:core:1.0.0'

lintChecks 'org.wordpress:lint:1.0.1'
androidTestImplementation 'androidx.test:runner:1.1.0'
androidTestImplementation 'androidx.test:rules:1.1.0'
androidTestImplementation 'androidx.test.ext:junit:1.1.0'
androidTestImplementation 'com.android.support.test.uiautomator:uiautomator-v18:2.1.2'

}

android {
Expand All @@ -38,8 +53,19 @@ android {

defaultConfig {
versionName "1.24"
minSdkVersion 15
minSdkVersion 18
targetSdkVersion 26

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
testOptions {
unitTests {
includeAndroidResources = true
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
package org.wordpress.android.util;

import android.graphics.BitmapFactory;
import android.test.InstrumentationTestCase;

public class ImageUtilsTest extends InstrumentationTestCase {
import org.junit.Test;

import static org.junit.Assert.assertEquals;

public class ImageUtilsTest {
@Test
public void testGetScaleForResizingReturnsOneWhenMaxSizeIsZero() {
BitmapFactory.Options options = new BitmapFactory.Options();
int scale = ImageUtils.getScaleForResizing(0, options);

assertEquals(1, scale);
}

@Test
public void testGetScaleForResizingSameSizeReturnsOne() {
BitmapFactory.Options options = new BitmapFactory.Options();
options.outHeight = 100;
Expand All @@ -22,6 +27,7 @@ public void testGetScaleForResizingSameSizeReturnsOne() {
assertEquals(1, scale);
}

@Test
public void testGetScaleForResizingPortraitMaxHeightSameAsMaxSizeReturnsOne() {
BitmapFactory.Options options = new BitmapFactory.Options();
options.outHeight = 100;
Expand All @@ -33,6 +39,7 @@ public void testGetScaleForResizingPortraitMaxHeightSameAsMaxSizeReturnsOne() {
assertEquals(1, scale);
}

@Test
public void testGetScaleForResizingLandscapeMaxWidthSameAsMaxSizeReturnsOne() {
BitmapFactory.Options options = new BitmapFactory.Options();
options.outHeight = 1;
Expand All @@ -44,6 +51,7 @@ public void testGetScaleForResizingLandscapeMaxWidthSameAsMaxSizeReturnsOne() {
assertEquals(1, scale);
}

@Test
public void testGetScaleForResizingDoubleSizeReturnsTwo() {
BitmapFactory.Options options = new BitmapFactory.Options();
options.outHeight = 100;
Expand All @@ -55,6 +63,7 @@ public void testGetScaleForResizingDoubleSizeReturnsTwo() {
assertEquals(2, scale);
}

@Test
public void testGetScaleForResizingThreeTimesSizeReturnsTwo() {
BitmapFactory.Options options = new BitmapFactory.Options();
options.outHeight = 100;
Expand All @@ -66,6 +75,7 @@ public void testGetScaleForResizingThreeTimesSizeReturnsTwo() {
assertEquals(2, scale);
}

@Test
public void testGetScaleForResizingEightTimesSizeReturnsEight() {
BitmapFactory.Options options = new BitmapFactory.Options();
options.outHeight = 100;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,36 @@
package org.wordpress.android.util;

import android.test.InstrumentationTestCase;

import org.json.JSONArray;
import org.json.JSONObject;
import org.junit.Test;

public class JSONUtilsTest extends InstrumentationTestCase {
public class JSONUtilsTest {
@Test
public void testQueryJSONNullSource1() {
JSONUtils.queryJSON((JSONObject) null, "", "");
}

@Test
public void testQueryJSONNullSource2() {
JSONUtils.queryJSON((JSONArray) null, "", "");
}

@Test
public void testQueryJSONNullQuery1() {
JSONUtils.queryJSON(new JSONObject(), null, "");
}

@Test
public void testQueryJSONNullQuery2() {
JSONUtils.queryJSON(new JSONArray(), null, "");
}

@Test
public void testQueryJSONNullReturnValue1() {
JSONUtils.queryJSON(new JSONObject(), "", null);
}

@Test
public void testQueryJSONNullReturnValue2() {
JSONUtils.queryJSON(new JSONArray(), "", null);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
package org.wordpress.android.util;

import org.junit.Test;
import org.wordpress.android.util.PhotonUtils.Quality;

import java.util.HashMap;
import java.util.Map;

import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.core.IsEqual.equalTo;
import static org.junit.Assert.assertThat;


public class PhotonUtilsTest {
@Test
public void getPhotonImageUrlIsEmptyWhenUrlIsNull() {
String photonUrl = PhotonUtils.getPhotonImageUrl(null, 0, 1);

assertThat(photonUrl, equalTo(""));
}

@Test
public void getPhotonImageUrlIsEmptyWhenUrlIsEmpty() {
String photonUrl = PhotonUtils.getPhotonImageUrl("", 0, 1);

assertThat(photonUrl, equalTo(""));
}

@Test
public void getPhotonImageUrlReturnsImageUrlOnNoScheme() {
String imageUrl = "wordpress.com";
String photonUrl = PhotonUtils.getPhotonImageUrl(imageUrl, 0, 1);

assertThat(photonUrl, equalTo(imageUrl));
}

@Test
public void getPhotonImageUrlReturnsMshots() {
String imageUrl = "http://test.wordpress.com/mshots/test.jpg?query=dummy";
String photonUrl = PhotonUtils.getPhotonImageUrl(imageUrl, 0, 1);

assertThat(photonUrl, equalTo("http://test.wordpress.com/mshots/test.jpg?w=0&h=1"));
}

@Test
public void getPhotonImageUrlReturnsCorrectQuality() {
Map<Quality, String> qualities = new HashMap<>();
qualities.put(Quality.HIGH, "100");
qualities.put(Quality.MEDIUM, "65");
qualities.put(Quality.LOW, "35");

String imageUrl = "http://test.wordpress.com/test.jpg?query=dummy";

for (Quality quality : qualities.keySet()) {
String photonUrl = PhotonUtils.getPhotonImageUrl(imageUrl, 0, 1, quality);
assertThat(photonUrl, containsString("&quality=" + qualities.get(quality)));
}
}

@Test
public void getPhotonImageUrlUsesResize() {
String imageUrl = "http://test.wordpress.com/test.jpg?query=dummy";
String photonUrl = PhotonUtils.getPhotonImageUrl(imageUrl, 2, 1);

assertThat(photonUrl, equalTo("http://test.wordpress.com/test.jpg?strip=info&quality=65&resize=2,1"));
}

@Test
public void getPhotonImageUrlManageSslOnPhotonUrl() {
String imageUrl = "https://i0.wp.com/test.jpg?query=dummy";
String photonUrl = PhotonUtils.getPhotonImageUrl(imageUrl, 2, 1);

assertThat(photonUrl, equalTo("https://i0.wp.com/test.jpg?strip=info&quality=65&resize=2,1"));

imageUrl = "https://i0.wp.com/test.jpg?query=dummy&ssl=1";
photonUrl = PhotonUtils.getPhotonImageUrl(imageUrl, 2, 1);

assertThat(photonUrl, equalTo("https://i0.wp.com/test.jpg?strip=info&quality=65&resize=2,1&ssl=1"));
}

@Test
public void getPhotonImageUrlDoNotUseSslOnWordPressCom() {
String imageUrl = "https://test.wordpress.com/test.jpg?query=dummy";
String photonUrl = PhotonUtils.getPhotonImageUrl(imageUrl, 2, 1);

assertThat(photonUrl, equalTo("https://test.wordpress.com/test.jpg?strip=info&quality=65&resize=2,1"));

imageUrl = "https://test.wordpress.com/test.jpg?query=dummy&ssl=1";
photonUrl = PhotonUtils.getPhotonImageUrl(imageUrl, 2, 1);

assertThat(photonUrl, equalTo("https://test.wordpress.com/test.jpg?strip=info&quality=65&resize=2,1"));
}

@Test
public void getPhotonImageUrlUsesSslOnHttpsImageUrl() {
String imageUrl = "http://mysite.com/test.jpg?query=dummy";
String photonUrl = PhotonUtils.getPhotonImageUrl(imageUrl, 2, 1);

assertThat(photonUrl, equalTo("https://i0.wp.com/mysite.com/test.jpg?strip=info&quality=65&resize=2,1"));

imageUrl = "https://mysite.com/test.jpg?query=dummy&ssl=1";
photonUrl = PhotonUtils.getPhotonImageUrl(imageUrl, 2, 1);

assertThat(photonUrl, equalTo("https://i0.wp.com/mysite.com/test.jpg?strip=info&quality=65&resize=2,1&ssl=1"));
}
}
Original file line number Diff line number Diff line change
@@ -1,24 +1,31 @@
package org.wordpress.android.util;

import android.test.InstrumentationTestCase;
import org.junit.Test;

public class ShortcodeUtilsTest extends InstrumentationTestCase {
import static org.junit.Assert.assertEquals;

public class ShortcodeUtilsTest {
@Test
public void testGetVideoPressShortcodeFromId() {
assertEquals("[wpvideo abcd1234]", ShortcodeUtils.getVideoPressShortcodeFromId("abcd1234"));
}

@Test
public void testGetVideoPressShortcodeFromNullId() {
assertEquals("", ShortcodeUtils.getVideoPressShortcodeFromId(null));
}

@Test
public void testGetVideoPressIdFromCorrectShortcode() {
assertEquals("abcd1234", ShortcodeUtils.getVideoPressIdFromShortCode("[wpvideo abcd1234]"));
}

@Test
public void testGetVideoPressIdFromInvalidShortcode() {
assertEquals("", ShortcodeUtils.getVideoPressIdFromShortCode("[other abcd1234]"));
}

@Test
public void testGetVideoPressIdFromNullShortcode() {
assertEquals("", ShortcodeUtils.getVideoPressIdFromShortCode(null));
}
Expand Down
Loading

0 comments on commit 56e3b3f

Please sign in to comment.