Skip to content

Commit

Permalink
Merge branch 'feature/fix-automated-tests-VIALA-759' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremy.norman committed Mar 9, 2018
2 parents 15ecdda + 66176a2 commit d681f87
Show file tree
Hide file tree
Showing 15 changed files with 53 additions and 521 deletions.
8 changes: 0 additions & 8 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ ext {
androidTestVersion = "0.5"
firebaseVersion = "11.6.2"
jUnitVersion = "4.12"
powerMockVersion = "1.7.3"
okHttpVersion = "3.9.0"
retroFitVersion = "2.3.0"
roboElectricVersion = "3.4.2"
Expand Down Expand Up @@ -130,13 +129,6 @@ dependencies {
testCompile "org.robolectric:robolectric:${roboElectricVersion}"
testCompile "org.mockito:mockito-core:${mockitoCoreVersion}"

// Setup for local tests.
testCompile "org.powermock:powermock-module-junit4:${powerMockVersion}"
testCompile "org.powermock:powermock-module-junit4-rule:${powerMockVersion}"
testCompile "org.powermock:powermock-api-mockito2:${powerMockVersion}"
testCompile "org.powermock:powermock-classloading-xstream:${powerMockVersion}"
testCompile "com.squareup.okhttp3:mockwebserver:${okHttpVersion}"

// Setup for instrumented tests.
androidTestCompile "com.android.support.test:runner:${androidTestVersion}"
androidTestCompile "com.android.support.test:rules:${androidTestVersion}"
Expand Down
20 changes: 18 additions & 2 deletions app/src/main/java/com/voipgrid/vialer/t9/T9NameMatcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,34 @@ public static boolean T9QueryMatchesName(String query, String displayName) {
* @return Name with <b></b> tags.
*/
public static String highlightMatchedPart(String t9Query, String displayName) {

ArrayList<String> possibleQueries = T9Query.generateT9NameQueries(displayName);

String queryOfWholeName = possibleQueries.get(0);

int start = queryOfWholeName.indexOf(t9Query);
int start = adjustStartBasedOnSpaces(displayName, queryOfWholeName.indexOf(t9Query));
int end = start + t9Query.length();

// Add a empty space behind the displayname to be able to substring untill the last char
// without causing outofboundexceptions.
return placeBoldingTags(displayName + " ", start, end, end-start);
}

/**
* Calculates the number of spaces in the display name before the start value and increases
* start based on this value.
*
* @param displayName
* @param start
* @return The value of start adjusted based on the number of spaces.
*/
private static int adjustStartBasedOnSpaces(String displayName, int start) {
String substr = displayName.substring(0, start);

int spaceCount = substr.length() - substr.replace(" ", "").length();

return start + spaceCount;
}

/**
* Recursively builds a string with the correct highlighting.
*/
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package com.voipgrid.vialer.test;

import com.voipgrid.vialer.util.PhoneNumberUtils;

import org.junit.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import com.voipgrid.vialer.util.PhoneNumberUtils;

import org.junit.Test;

/**
* PhoneNumberUtilsTest class for testing PhoneNumberUtils functions.
*/
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.voipgrid.vialer.test.logging;

import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.when;

import com.voipgrid.vialer.logging.DeviceInformation;
import com.voipgrid.vialer.logging.LogComposer;

Expand All @@ -9,9 +12,6 @@
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;

import static org.junit.Assert.*;
import static org.mockito.Mockito.when;

@RunWith(MockitoJUnitRunner.class)
public class LogComposerTest {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
package com.voipgrid.vialer.test.logging;

import static org.mockito.ArgumentMatchers.anyObject;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import android.content.Context;

import com.logentries.logger.AsyncLoggingWorker;
Expand All @@ -12,12 +18,6 @@
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;

import static org.mockito.ArgumentMatchers.anyObject;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

@RunWith(MockitoJUnitRunner.class)
public class VialerLoggerTest {

Expand Down Expand Up @@ -63,4 +63,4 @@ public void it_handles_the_factory_not_being_able_to_create_an_environment() {
classUnderTest.initialize(new String[] {"invalidToken"});
classUnderTest.log("A log message");
}
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.voipgrid.vialer.test.logging.formatting;

import static org.junit.Assert.assertFalse;

import com.voipgrid.vialer.fcm.FcmMessagingService;
import com.voipgrid.vialer.logging.formatting.formatters.PayloadAnonymizer;

import org.junit.Test;

import static org.junit.Assert.*;

public class PayloadAnonymizerTest {
private String dummyPayloadLog = "FcmMessagingService Payload: {message_start_time=1.517230273029763E9, caller_id=, phonenumber=+41501109999, type=call, unique_key=209779d101c25d5d486304900cc8e75e, response_api=https://vialerpush.voipgrid.nl/api/call-response/}";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package com.voipgrid.vialer.test.logging.formatting;

import static org.junit.Assert.assertFalse;

import com.voipgrid.vialer.logging.formatting.formatters.PayloadAnonymizer;
import com.voipgrid.vialer.logging.formatting.formatters.SipLogAnonymizer;
import com.voipgrid.vialer.sip.SipService;

import org.junit.Test;

import static org.junit.Assert.*;


public class SipLogAnonymizerTest {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package com.voipgrid.vialer.test.t9;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import com.voipgrid.vialer.t9.T9NameMatcher;

import org.junit.Test;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

/**
* Class for testing the T9NameMatcher class.
*/
Expand Down Expand Up @@ -50,44 +51,29 @@ public void T9QueryMatchesNameTest() {

@Test
public void highlightMatchedPartTest() {
String name = "Henk van den Berg";
String query;
String expectedResult;

// hen.
query = "436";
expectedResult = "<b>Hen</b>k van den Berg";
assertTrue(expectedResult.equals(T9NameMatcher.highlightMatchedPart(query, name)));
t9matcherTest("436", "<b>Hen</b>k van den Berg ");

// henk.
query = "4365";
expectedResult = "<b>Henk</b> van den Berg";
assertTrue(expectedResult.equals(T9NameMatcher.highlightMatchedPart(query, name)));
t9matcherTest("4365", "<b>Henk</b> van den Berg ");

// van.
query = "826";
expectedResult = "Henk <b>van</b> den Berg";
assertTrue(expectedResult.equals(T9NameMatcher.highlightMatchedPart(query, name)));
t9matcherTest("826", "Henk <b>van</b> den Berg ");

// vande.
query = "82633";
expectedResult = "Henk <b>van de</b>n Berg";
assertTrue(expectedResult.equals(T9NameMatcher.highlightMatchedPart(query, name)));
t9matcherTest("82633", "Henk <b>van de</b>n Berg ");

// den.
query = "336";
expectedResult = "Henk van <b>den</b> Berg";
assertTrue(expectedResult.equals(T9NameMatcher.highlightMatchedPart(query, name)));
t9matcherTest("336", "Henk van <b>den</b> Berg ");

// denb.
query = "3362";
expectedResult = "Henk van <b>den B</b>erg";
assertTrue(expectedResult.equals(T9NameMatcher.highlightMatchedPart(query, name)));
t9matcherTest("3362", "Henk van <b>den B</b>erg ");

// berg.
query = "2374";
expectedResult = "Henk van den <b>Berg</b>";
assertTrue(expectedResult.equals(T9NameMatcher.highlightMatchedPart(query, name)));
t9matcherTest("2374", "Henk van den <b>Berg</b> ");
}

private void t9matcherTest(String query, String expected) {
String name = "Henk van den Berg";
assertEquals(expected, T9NameMatcher.highlightMatchedPart(query, name));
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package com.voipgrid.vialer.test.t9;

import static org.junit.Assert.assertEquals;

import com.voipgrid.vialer.t9.T9Query;

import org.junit.Test;

import java.util.ArrayList;

import static org.junit.Assert.assertEquals;

public class T9QueryTest {

/**
Expand Down
Loading

0 comments on commit d681f87

Please sign in to comment.