Commit 0f547c84 authored by Nicklas Bergman's avatar Nicklas Bergman

* Added more tests

parent 099dfe7a
......@@ -410,6 +410,21 @@ public class InstrumentedTests {
}
}
@Test
public void testGetDelayString() {
final String none = targetContext.getString(R.string.none);
final String minute = targetContext.getString(R.string.minute);
final String minutes = targetContext.getString(R.string.minutes);
final String second = targetContext.getString(R.string.second);
final String seconds = targetContext.getString(R.string.seconds);
final int[] testParams = {0, 1, 2, 60, 61, 122};
final String[] expectedReturns = {none, "1 " + second, "2 " + seconds, "1 " + minute, "1 " + minute + " 1 " + second,
"2 " + minutes + " 2 " + seconds};
for (int i = 0; i < testParams.length; i++) {
assertEquals(expectedReturns[i], Util.getDelayString(targetContext, testParams[i]));
}
}
public boolean enableBluetooth(final BluetoothAdapter bluetoothAdapter) {
boolean enabled;
if (bluetoothAdapter.isEnabled()) {
......
......@@ -39,6 +39,8 @@
<string name="enable_notifications">Enable notifications</string>
<string name="abort_job_button">Keep Bluetooth on</string>
<string name="disable_button">Disable Greentooth</string>
<string name="minute">minute</string>
<string name="second">second</string>
<string name="seconds">seconds</string>
<string name="minutes">minutes</string>
<string name="seconds_uppercase">Seconds</string>
......
......@@ -28,7 +28,7 @@ import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.when;
@RunWith(MockitoJUnitRunner.class)
public class UnitTests {
public class BluetoothUtilUnitTests {
@Mock
BluetoothAdapter bluetoothAdapter;
......
package com.smilla.greentooth;
import android.content.SharedPreferences;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import static com.smilla.greentooth.GreenApplication.DEFAULT_DELAY;
import static com.smilla.greentooth.GreenApplication.DELAY_KEY;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.when;
@RunWith(MockitoJUnitRunner.class)
public class UtilUnitTests {
@Mock
SharedPreferences mockPreferences;
@Test
public void testGetSaneDelay() {
final int[] testParameters = {50, -1, 3600};
final int[] expectedReturns = {50, 0, 3599};
for (int i = 0; i < testParameters.length; i++) {
when(mockPreferences.getInt(DELAY_KEY, DEFAULT_DELAY)).thenReturn(testParameters[i]);
assertEquals(expectedReturns[i], Util.getSaneDelay(mockPreferences));
}
}
}
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment