Skip to content

Commit

Permalink
Merge pull request #1 from percolate/add_tests
Browse files Browse the repository at this point in the history
Added Unit Tests
  • Loading branch information
brentwatson authored Oct 3, 2016
2 parents 61a0465 + 7aafc29 commit c2d6f19
Show file tree
Hide file tree
Showing 52 changed files with 1,486 additions and 719 deletions.
12 changes: 12 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Copyright (c) 2016, Percolate Industries, Inc.
All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4 changes: 3 additions & 1 deletion Mentions/build.gradle
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
ext.kotlin_version = '1.0.4'
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.3.0'
classpath 'com.android.tools.build:gradle:2.2.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
4 changes: 2 additions & 2 deletions Mentions/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Wed Aug 12 16:10:47 EDT 2015
#Fri Sep 16 10:56:47 EDT 2016
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.4-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
62 changes: 55 additions & 7 deletions Mentions/mentions/build.gradle
Original file line number Diff line number Diff line change
@@ -1,24 +1,72 @@
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'jacoco'

android {
compileSdkVersion 23
buildToolsVersion "22.0.1"
compileSdkVersion 24
buildToolsVersion "24.0.2"

defaultConfig {
minSdkVersion 16
targetSdkVersion 22
targetSdkVersion 24
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
debug {
testCoverageEnabled false
}
}
testOptions {
unitTests.all {
jacoco {
includeNoLocationClasses = true
}
}
}
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
}

jacoco {
version = '0.7.6.201602180812'
}

task coverage(type:JacocoReport, dependsOn: "testDebugUnitTest") {
group = "Reporting"
description = 'Create code coverage report for library.'

classDirectories = fileTree(
dir: "$buildDir/intermediates/classes/debug",
excludes: ['**/R.class',
'**/R$*.class',
'**/BuildConfig.*',
'com/percolate/mentions/CharSequenceUtils.class',
'com/percolate/mentions/StringUtils.class']
)

sourceDirectories = files("src/main/java")
executionData = files("build/jacoco/testDebugUnitTest.exec")

reports {
//noinspection GroovyAssignabilityCheck
xml.enabled = true
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.0.0'
compile 'com.android.support:appcompat-v7:24.2.1'

testCompile 'junit:junit:4.12'
testCompile "org.robolectric:robolectric:3.1.2"
testCompile 'org.mockito:mockito-core:2.1.0-RC.1'
testCompile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"

//Prevents class not found exception https://github.com/robolectric/robolectric/issues/1932
testCompile 'org.khronos:opengl-api:gl1.1-android-2.1_r1'
}
repositories {
mavenCentral()
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class CharSequenceUtils {
* @param start the start index
* @return the index where the search sequence was found
*/
public static int indexOf(final CharSequence cs, final CharSequence searchChar, final int start) {
static int indexOf(final CharSequence cs, final CharSequence searchChar, final int start) {
return cs.toString().indexOf(searchChar.toString(), start);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
/**
* Contains helper methods to determine if a search is valid.
*/
class MentionCheckerUtils {
class MentionCheckerLogic {

private EditText editText;
private final EditText editText;

/* Default limit of 13 characters to evaluate after the '@' symbol. */
private int maxCharacters = 13;
@SuppressWarnings("WeakerAccess")
protected int maxCharacters = 13;

public MentionCheckerUtils(EditText editText) {
MentionCheckerLogic(final EditText editText) {
this.editText = editText;
}

Expand All @@ -24,7 +25,7 @@ public MentionCheckerUtils(EditText editText) {
* @param maxCharacters int The maximum number of characters to considered after the
* '@' symbol as a query. The default is 13 characters.
*/
public void setMaxCharacters(int maxCharacters) {
void setMaxCharacters(final int maxCharacters) {
if (maxCharacters <= 0) {
throw new IllegalArgumentException("Maximum number of characters must be greater " +
"than 0.");
Expand All @@ -42,33 +43,27 @@ public void setMaxCharacters(int maxCharacters) {
*
* @return String A valid query that satisfies the three rules above.
*/
public String doMentionCheck() {

String doMentionCheck() {
String queryToken = "";

// perform a search if the {@link EditText} has an '@' symbol.
if (StringUtils.contains(editText.getText(), "@")) {

int cursorPosition = editText.getSelectionStart();

String allTextBeforeCursor = editText.getText().toString().substring(0, cursorPosition);

String providedSearchText = StringUtils.substringAfterLast(allTextBeforeCursor, "@");
final int cursorPosition = editText.getSelectionStart();
final String allTextBeforeCursor = editText.getText().toString().substring(0, cursorPosition);
final String providedSearchText = StringUtils.substringAfterLast(allTextBeforeCursor, "@");

// check search text is within <code>maxCharacters</code> and begins with a
// alpha numeric char.
if (searchIsWithinMaxChars(providedSearchText, maxCharacters)
&& searchBeginsWithAlphaNumericChar(providedSearchText)) {

int atSymbolPosition = StringUtils.lastIndexOf(allTextBeforeCursor, "@");
final int atSymbolPosition = StringUtils.lastIndexOf(allTextBeforeCursor, "@");

// check if search text is first in the view or has a space beforehand if there are
// more characters in the view.
if (atSymbolPosition == 0
|| spaceBeforeAtSymbol(allTextBeforeCursor, atSymbolPosition)) {

queryToken = providedSearchText;

}
}
}
Expand All @@ -86,9 +81,9 @@ && searchBeginsWithAlphaNumericChar(providedSearchText)) {
* {@link EditText}.
* @return true or false
*/
private boolean spaceBeforeAtSymbol(String currentTextBeforeCursor, int atSymbolPosition) {
private boolean spaceBeforeAtSymbol(final String currentTextBeforeCursor, final int atSymbolPosition) {
if (atSymbolPosition > 0) {
char charBeforeAtSymbol = currentTextBeforeCursor.charAt(atSymbolPosition - 1);
final char charBeforeAtSymbol = currentTextBeforeCursor.charAt(atSymbolPosition - 1);
if (Character.isWhitespace(charBeforeAtSymbol)) {
return true;
}
Expand All @@ -105,7 +100,7 @@ private boolean spaceBeforeAtSymbol(String currentTextBeforeCursor, int atSymbol
* value is configurable.
* @return true or false
*/
private boolean searchIsWithinMaxChars(String providedSearchText, int maxCharacters) {
private boolean searchIsWithinMaxChars(final String providedSearchText, final int maxCharacters) {
return (providedSearchText.length() >= 1 && providedSearchText.length() <= maxCharacters);
}

Expand All @@ -115,7 +110,7 @@ private boolean searchIsWithinMaxChars(String providedSearchText, int maxCharact
* @param providedSearchText String The text after the '@' symbol entered by the user.
* @return true or false
*/
private boolean searchBeginsWithAlphaNumericChar(String providedSearchText) {
private boolean searchBeginsWithAlphaNumericChar(final String providedSearchText) {
return Character.isLetterOrDigit(providedSearchText.charAt(0));
}

Expand All @@ -125,10 +120,9 @@ private boolean searchBeginsWithAlphaNumericChar(String providedSearchText) {
*
* @return true or false
*/
public boolean currentWordStartsWithAtSign() {

int start = editText.getSelectionStart();
int end = editText.getSelectionEnd();
boolean currentWordStartsWithAtSign() {
final int start = editText.getSelectionStart();
final int end = editText.getSelectionEnd();

if (start == end) {
//Multiple text is not highlighted
Expand Down
Loading

0 comments on commit c2d6f19

Please sign in to comment.