Add transliteration test

here
ivanovlev 2017-01-25 00:04:05 +03:00
parent 06295abcb6
commit 09539fd9bf
3 changed files with 56 additions and 1 deletions

View File

@ -1,17 +1,21 @@
package nodomain.freeyourgadget.gadgetbridge.service;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import org.junit.Test;
import org.mockito.InOrder;
import org.mockito.Mock;
import org.mockito.Mockito;
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
import nodomain.freeyourgadget.gadgetbridge.GBException;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
import nodomain.freeyourgadget.gadgetbridge.model.DeviceType;
import nodomain.freeyourgadget.gadgetbridge.test.TestBase;
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_NOTIFICATION_BODY;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
@ -97,4 +101,17 @@ public class DeviceCommunicationServiceTestCase extends TestBase {
inOrder.verifyNoMoreInteractions();
}
@Test
public void testTransliterationSupport() {
SharedPreferences settings = GBApplication.getPrefs().getPreferences();
SharedPreferences.Editor editor = settings.edit();
editor.putBoolean("transliteration", true);
editor.commit();
Intent intent = mDeviceService.createIntent().putExtra(EXTRA_NOTIFICATION_BODY, "Прõсто текčт");
mDeviceService.invokeService(intent);
String result = intent.getStringExtra(EXTRA_NOTIFICATION_BODY);
assertTrue("Transliteration support fail!", result.equals("Prosto tekct"));
}
}

View File

@ -29,7 +29,7 @@ class TestDeviceService extends GBDeviceService {
// calling though to the service natively does not work with robolectric,
// we have to use the ServiceController to do that
service.onStartCommand(intent, Service.START_FLAG_REDELIVERY, (int) (Math.random() * 10000));
// super.invokeService(intent);
super.invokeService(intent);
}
@Override

View File

@ -0,0 +1,38 @@
package nodomain.freeyourgadget.gadgetbridge.test;
import android.content.SharedPreferences;
import org.junit.Test;
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
import nodomain.freeyourgadget.gadgetbridge.util.LanguageUtils;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
/**
* Tests LanguageUtils
*/
public class LanguageUtilsTest extends TestBase {
@Test
public void testStringTransliterate() throws Exception {
//input with cyrillic and diacritic letters
String input = "Прõсто текčт";
String output = LanguageUtils.transliterate(input);
String result = "Prosto tekct";
assertTrue(String.format("Transliteration fail! Expected '%s', but found '%s'}", result, output), output.equals(result));
}
@Test
public void testTransliterateOption() throws Exception {
assertFalse("Transliteration option fail! Expected 'Off' by default, but result is 'On'", LanguageUtils.transliterate());
SharedPreferences settings = GBApplication.getPrefs().getPreferences();
SharedPreferences.Editor editor = settings.edit();
editor.putBoolean("transliteration", true);
editor.commit();
assertTrue("Transliteration option fail! Expected 'On', but result is 'Off'", LanguageUtils.transliterate());
}
}