Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into feature/account-se…
Browse files Browse the repository at this point in the history
…ttings
  • Loading branch information
oguzkocer committed Feb 16, 2016
2 parents 1b7d78d + 62db2a7 commit b7c87e7
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 1 deletion.
2 changes: 1 addition & 1 deletion WordPressUtils/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ android {
buildToolsVersion "23.0.2"

defaultConfig {
versionName "1.8.0"
versionName "1.9.0"
minSdkVersion 14
targetSdkVersion 23
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.wordpress.android.util;

import android.test.InstrumentationTestCase;

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

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

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

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

public void testGetVideoPressIdFromNullShortcode() {
assertEquals("", ShortcodeUtils.getVideoPressIdFromShortCode(null));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package org.wordpress.android.util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class ShortcodeUtils {
public static String getVideoPressShortcodeFromId(String videoPressId) {
if (videoPressId == null || videoPressId.isEmpty()) {
return "";
}

return "[wpvideo " + videoPressId + "]";
}

public static String getVideoPressIdFromShortCode(String shortcode) {
String videoPressId = "";

if (shortcode != null) {
String videoPressShortcodeRegex = "^\\[wpvideo (.*)]$";

Pattern pattern = Pattern.compile(videoPressShortcodeRegex);
Matcher matcher = pattern.matcher(shortcode);

if (matcher.find()) {
videoPressId = matcher.group(1);
}
}

return videoPressId;
}
}

0 comments on commit b7c87e7

Please sign in to comment.