Skip to content

Commit

Permalink
Fixed issue with test failing due to wrong name
Browse files Browse the repository at this point in the history
  • Loading branch information
mt-krainski committed Dec 31, 2018
1 parent 3421b80 commit 88727a9
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -378,18 +378,18 @@ private void createInitialCalculationModules(){

public void notifyUser(String text, int duration, String id){
if (userNotifier!=null){
userNotifier.notifyUser(text, duration, id);
userNotifier.displayMessage(text, duration, id);
} else {
Log.d(TAG, "notifyUser: userNotifier not set! " +
Log.d(TAG, "displayMessage: userNotifier not set! " +
"Set it by calling GnssCoreService.assignUserNotifier!");
}
}

public void notifyUser(String text, int duration){
if (userNotifier!=null){
userNotifier.notifyUser(text, duration, null);
userNotifier.displayMessage(text, duration, null);
} else {
Log.d(TAG, "notifyUser: userNotifier not set! " +
Log.d(TAG, "displayMessage: userNotifier not set! " +
"Set it by calling GnssCoreService.assignUserNotifier!");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
import com.google.android.gms.location.LocationServices;
import com.rd.PageIndicatorView;

import java.util.HashMap;
import java.util.Observable;
import java.util.Observer;

Expand Down Expand Up @@ -176,6 +175,7 @@ public void onServiceDisconnected(ComponentName name) {

Snackbar snackbar = null;
String snackbarId = "";
String snackbarText = "";
int snackbarDuration = 0;
boolean snackbarAlive = false;

Expand All @@ -202,7 +202,7 @@ public void run() {
};

@Override
public void notifyUser(String text, int duration, String id) {
public void displayMessage(String text, int duration, String id) {
if(mainView == null)
return;
if (id == null) {
Expand All @@ -215,7 +215,7 @@ public void notifyUser(String text, int duration, String id) {
} else {
synchronized (this) {
boolean snackbarExtended = false;
if (id.equals(snackbarId) && snackbar!=null){
if (id.equals(snackbarId) && text.equals(snackbarText) && snackbar!=null){
if(snackbar.isShown()){
snackbarDuration = duration;
snackbarExtended = true;
Expand All @@ -226,6 +226,7 @@ public void notifyUser(String text, int duration, String id) {
mainView,
text,
Snackbar.LENGTH_INDEFINITE);
snackbarText = text;
snackbarId = id;
snackbarDuration = duration;
snackbar.show();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,27 @@
package com.galfins.gnss_compare;

import android.support.design.widget.Snackbar;

/**
* Created by pc1 on 30-Dec-18.
* This class is for:
*/
public abstract class UserNotifier {
public abstract void notifyUser(String text, int duration, String id);

/**
* This method should implement a way to display the text to the user
* @param text Text do be displayed to be user
* @param duration duration of the message (ms)
* @param id id of the message (for advanced handling)
*/
protected abstract void displayMessage(String text, int duration, String id);

public void notifyUser(String text, int duration, String id){
if(duration == Snackbar.LENGTH_SHORT)
duration = 2000;
else if (duration == Snackbar.LENGTH_LONG)
duration = 3500;

displayMessage(text, duration, id);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public void CreateByNameTest() throws Exception {
FileLogger.initialize();

String moduleName = "Test";
String constellationName = "GPS";
String constellationName = "GPS L1";
String correctionName = "Klobuchar Iono Correction";
Set<String> correctionNames = new HashSet<>();
correctionNames.add(correctionName);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,46 @@
package com.galfins.gnss_compare;

import static org.junit.Assert.*;

import org.junit.Test;

import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import static org.mockito.Mockito.when;

/**
* Test for the user MainActivity's implementation of User Notifier
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@RunWith(MockitoJUnitRunner.class)
public class UserNotifierTest {
/**
* Testing creation from description
* @throws Exception
*/
@Test
public void MainActivityUserNotifierTest() throws Exception{

}
}
//package com.galfins.gnss_compare;
//
//import static org.junit.Assert.*;
//
//import org.junit.Rule;
//import org.junit.Test;
//
//import org.junit.runner.RunWith;
//import org.mockito.Mock;
//import org.mockito.runners.MockitoJUnitRunner;
//import static org.mockito.Mockito.when;
//
///**
// * Test for the user MainActivity's implementation of User Notifier
// *
// * @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
// */
//@RunWith(AndroidJUnit4.class)
//public class UserNotifierTest {
//
// private class TestUserNotifier extends UserNotifier{
//
// private String lastMessage = null;
// private int lastDuration;
// private String lastId = null;
//
// @Override
// protected void displayMessage(String text, int duration, String id) {
// lastMessage = text;
// lastDuration = duration;
// lastId = id;
// }
// }
//
//// @Rule
//// public final ServiceTestRule mServiceRule = new ServiceTestRule();
//
// /**
// * Testing creation from description
// * @throws Exception
// */
// @Test
// public void MainActivityUserNotifierTest() throws Exception{
//
// }
//}

0 comments on commit 88727a9

Please sign in to comment.