mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-09-03 04:56:27 +02:00
Add transliteration test
This commit is contained in:
parent
06295abcb6
commit
09539fd9bf
@ -1,17 +1,21 @@
|
|||||||
package nodomain.freeyourgadget.gadgetbridge.service;
|
package nodomain.freeyourgadget.gadgetbridge.service;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.mockito.InOrder;
|
import org.mockito.InOrder;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.Mockito;
|
import org.mockito.Mockito;
|
||||||
|
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.GBException;
|
import nodomain.freeyourgadget.gadgetbridge.GBException;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.model.DeviceType;
|
import nodomain.freeyourgadget.gadgetbridge.model.DeviceType;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.test.TestBase;
|
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.assertEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
@ -97,4 +101,17 @@ public class DeviceCommunicationServiceTestCase extends TestBase {
|
|||||||
inOrder.verifyNoMoreInteractions();
|
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"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,7 @@ class TestDeviceService extends GBDeviceService {
|
|||||||
// calling though to the service natively does not work with robolectric,
|
// calling though to the service natively does not work with robolectric,
|
||||||
// we have to use the ServiceController to do that
|
// we have to use the ServiceController to do that
|
||||||
service.onStartCommand(intent, Service.START_FLAG_REDELIVERY, (int) (Math.random() * 10000));
|
service.onStartCommand(intent, Service.START_FLAG_REDELIVERY, (int) (Math.random() * 10000));
|
||||||
// super.invokeService(intent);
|
super.invokeService(intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -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());
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user