forked from upstream-mirrors/OpenTracks
Upgraded tests to Junit4.
This commit is contained in:
+22
-16
@@ -15,14 +15,19 @@
|
|||||||
*/
|
*/
|
||||||
package de.dennisguse.opentracks.services;
|
package de.dennisguse.opentracks.services;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import org.junit.Assert;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.junit.runners.JUnit4;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests the {@link AdaptiveLocationListenerPolicy}.
|
* Tests the {@link AdaptiveLocationListenerPolicy}.
|
||||||
*
|
*
|
||||||
* @author youtaol
|
* @author youtaol
|
||||||
*/
|
*/
|
||||||
public class AdaptiveLocationListenerPolicyTest extends TestCase {
|
@RunWith(JUnit4.class)
|
||||||
|
public class AdaptiveLocationListenerPolicyTest {
|
||||||
|
|
||||||
private static final long MIN = 1000;
|
private static final long MIN = 1000;
|
||||||
private static final long MAX = 3000;
|
private static final long MAX = 3000;
|
||||||
@@ -31,12 +36,11 @@ public class AdaptiveLocationListenerPolicyTest extends TestCase {
|
|||||||
private static final long NEW_IDLE_TIME_NORMAL = 5000;
|
private static final long NEW_IDLE_TIME_NORMAL = 5000;
|
||||||
private static final long NEW_IDLE_TIME_SMALL = 2000;
|
private static final long NEW_IDLE_TIME_SMALL = 2000;
|
||||||
private static final long NEW_IDLE_TIME_LESS_THAN_MIN = 500;
|
private static final long NEW_IDLE_TIME_LESS_THAN_MIN = 500;
|
||||||
private AdaptiveLocationListenerPolicy adocationListenerPolicy;
|
private AdaptiveLocationListenerPolicy adaptiveLocationListenerPolicy;
|
||||||
|
|
||||||
@Override
|
@Before
|
||||||
protected void setUp() throws Exception {
|
public void setUp() {
|
||||||
super.setUp();
|
adaptiveLocationListenerPolicy = new AdaptiveLocationListenerPolicy(MIN, MAX, MIN_DISTANCE);
|
||||||
adocationListenerPolicy = new AdaptiveLocationListenerPolicy(MIN, MAX, MIN_DISTANCE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -48,25 +52,27 @@ public class AdaptiveLocationListenerPolicyTest extends TestCase {
|
|||||||
* <li>The newIdleTime is smaller than the smallest interval unit.</li>
|
* <li>The newIdleTime is smaller than the smallest interval unit.</li>
|
||||||
* </ul>
|
* </ul>
|
||||||
*/
|
*/
|
||||||
|
@Test
|
||||||
public void testGetDesiredPollingInterval() {
|
public void testGetDesiredPollingInterval() {
|
||||||
adocationListenerPolicy.updateIdleTime(NEW_IDLE_TIME_BIG);
|
adaptiveLocationListenerPolicy.updateIdleTime(NEW_IDLE_TIME_BIG);
|
||||||
assertEquals(MAX, adocationListenerPolicy.getDesiredPollingInterval());
|
Assert.assertEquals(MAX, adaptiveLocationListenerPolicy.getDesiredPollingInterval());
|
||||||
|
|
||||||
adocationListenerPolicy.updateIdleTime(NEW_IDLE_TIME_NORMAL);
|
adaptiveLocationListenerPolicy.updateIdleTime(NEW_IDLE_TIME_NORMAL);
|
||||||
// First get the half of NEW_IDLE_TIME_NORMAL, and then round it to the nearest second.
|
// First get the half of NEW_IDLE_TIME_NORMAL, and then round it to the nearest second.
|
||||||
assertEquals((NEW_IDLE_TIME_NORMAL / 2 / 1000) * 1000, adocationListenerPolicy.getDesiredPollingInterval());
|
Assert.assertEquals((NEW_IDLE_TIME_NORMAL / 2 / 1000) * 1000, adaptiveLocationListenerPolicy.getDesiredPollingInterval());
|
||||||
|
|
||||||
adocationListenerPolicy.updateIdleTime(NEW_IDLE_TIME_SMALL);
|
adaptiveLocationListenerPolicy.updateIdleTime(NEW_IDLE_TIME_SMALL);
|
||||||
assertEquals(MIN, adocationListenerPolicy.getDesiredPollingInterval());
|
Assert.assertEquals(MIN, adaptiveLocationListenerPolicy.getDesiredPollingInterval());
|
||||||
|
|
||||||
adocationListenerPolicy.updateIdleTime(NEW_IDLE_TIME_LESS_THAN_MIN);
|
adaptiveLocationListenerPolicy.updateIdleTime(NEW_IDLE_TIME_LESS_THAN_MIN);
|
||||||
assertEquals(MIN, adocationListenerPolicy.getDesiredPollingInterval());
|
Assert.assertEquals(MIN, adaptiveLocationListenerPolicy.getDesiredPollingInterval());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests the method {@link AdaptiveLocationListenerPolicy#getMinDistance_m()}.
|
* Tests the method {@link AdaptiveLocationListenerPolicy#getMinDistance_m()}.
|
||||||
*/
|
*/
|
||||||
|
@Test
|
||||||
public void testGetMinDistance() {
|
public void testGetMinDistance() {
|
||||||
assertEquals(MIN_DISTANCE, adocationListenerPolicy.getMinDistance_m());
|
Assert.assertEquals(MIN_DISTANCE, adaptiveLocationListenerPolicy.getMinDistance_m());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,11 @@
|
|||||||
*/
|
*/
|
||||||
package de.dennisguse.opentracks.stats;
|
package de.dennisguse.opentracks.stats;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import org.junit.Assert;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.junit.runners.JUnit4;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for {@link TripStatistics}.
|
* Tests for {@link TripStatistics}.
|
||||||
@@ -23,17 +27,17 @@ import junit.framework.TestCase;
|
|||||||
*
|
*
|
||||||
* @author Rodrigo Damazio
|
* @author Rodrigo Damazio
|
||||||
*/
|
*/
|
||||||
public class TripStatisticsTest extends TestCase {
|
@RunWith(JUnit4.class)
|
||||||
|
public class TripStatisticsTest {
|
||||||
|
|
||||||
private TripStatistics statistics;
|
private TripStatistics statistics;
|
||||||
|
|
||||||
@Override
|
@Before
|
||||||
protected void setUp() throws Exception {
|
public void setUp() {
|
||||||
super.setUp();
|
|
||||||
|
|
||||||
statistics = new TripStatistics();
|
statistics = new TripStatistics();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testMerge() {
|
public void testMerge() {
|
||||||
TripStatistics statistics2 = new TripStatistics();
|
TripStatistics statistics2 = new TripStatistics();
|
||||||
statistics.setStartTime(1000L); // Resulting start time
|
statistics.setStartTime(1000L); // Resulting start time
|
||||||
@@ -61,28 +65,30 @@ public class TripStatisticsTest extends TestCase {
|
|||||||
|
|
||||||
statistics.merge(statistics2);
|
statistics.merge(statistics2);
|
||||||
|
|
||||||
assertEquals(1000L, statistics.getStartTime());
|
Assert.assertEquals(1000L, statistics.getStartTime());
|
||||||
assertEquals(4000L, statistics.getStopTime());
|
Assert.assertEquals(4000L, statistics.getStopTime());
|
||||||
assertEquals(2500L, statistics.getTotalTime());
|
Assert.assertEquals(2500L, statistics.getTotalTime());
|
||||||
assertEquals(1300L, statistics.getMovingTime());
|
Assert.assertEquals(1300L, statistics.getMovingTime());
|
||||||
assertEquals(1100.0, statistics.getTotalDistance());
|
Assert.assertEquals(1100.0, statistics.getTotalDistance(), 0.001);
|
||||||
assertEquals(900.0, statistics.getTotalElevationGain());
|
Assert.assertEquals(900.0, statistics.getTotalElevationGain(), 0.001);
|
||||||
assertEquals(statistics.getTotalDistance() / (statistics.getMovingTime() / 1000.0), statistics.getMaxSpeed());
|
Assert.assertEquals(statistics.getTotalDistance() / (statistics.getMovingTime() / 1000.0), statistics.getMaxSpeed(), 0.001);
|
||||||
assertEquals(1200.0, statistics.getMinElevation());
|
Assert.assertEquals(1200.0, statistics.getMinElevation(), 0.001);
|
||||||
assertEquals(3575.0, statistics.getMaxElevation());
|
Assert.assertEquals(3575.0, statistics.getMaxElevation(), 0.001);
|
||||||
assertEquals(-25.0, statistics.getMinGrade());
|
Assert.assertEquals(-25.0, statistics.getMinGrade(), 0.001);
|
||||||
assertEquals(35.0, statistics.getMaxGrade());
|
Assert.assertEquals(35.0, statistics.getMaxGrade(), 0.001);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testGetAverageSpeed() {
|
public void testGetAverageSpeed() {
|
||||||
statistics.setTotalDistance(1000.0);
|
statistics.setTotalDistance(1000.0);
|
||||||
statistics.setTotalTime(50000); // in milliseconds
|
statistics.setTotalTime(50000); // in milliseconds
|
||||||
assertEquals(20.0, statistics.getAverageSpeed());
|
Assert.assertEquals(20.0, statistics.getAverageSpeed(), 0.001);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testGetAverageMovingSpeed() {
|
public void testGetAverageMovingSpeed() {
|
||||||
statistics.setTotalDistance(1000.0);
|
statistics.setTotalDistance(1000.0);
|
||||||
statistics.setMovingTime(20000); // in milliseconds
|
statistics.setMovingTime(20000); // in milliseconds
|
||||||
assertEquals(50.0, statistics.getAverageMovingSpeed());
|
Assert.assertEquals(50.0, statistics.getAverageMovingSpeed(), 0.001);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,10 @@ package de.dennisguse.opentracks.util;
|
|||||||
|
|
||||||
import android.os.Environment;
|
import android.os.Environment;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import org.junit.Assert;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.junit.runners.JUnit4;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
@@ -26,83 +29,93 @@ import java.io.File;
|
|||||||
*
|
*
|
||||||
* @author Rodrigo Damazio
|
* @author Rodrigo Damazio
|
||||||
*/
|
*/
|
||||||
public class FileUtilsTest extends TestCase {
|
@RunWith(JUnit4.class)
|
||||||
|
public class FileUtilsTest {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests {@link FileUtils#getPath(String...)}.
|
* Tests {@link FileUtils#getPath(String...)}.
|
||||||
*/
|
*/
|
||||||
|
@Test
|
||||||
public void testBuildExternalDirectoryPath() {
|
public void testBuildExternalDirectoryPath() {
|
||||||
String expectedName = Environment.getExternalStorageDirectory() + File.separator + FileUtils.SDCARD_TOP_DIR + File.separator + "a" + File.separator + "b" + File.separator + "c";
|
String expectedName = Environment.getExternalStorageDirectory() + File.separator + FileUtils.SDCARD_TOP_DIR + File.separator + "a" + File.separator + "b" + File.separator + "c";
|
||||||
String dirName = FileUtils.getPath("a", "b", "c");
|
String dirName = FileUtils.getPath("a", "b", "c");
|
||||||
assertEquals(expectedName, dirName);
|
Assert.assertEquals(expectedName, dirName);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests {@link FileUtils#buildUniqueFileName(File, String, String)} when the file is new.
|
* Tests {@link FileUtils#buildUniqueFileName(File, String, String)} when the file is new.
|
||||||
*/
|
*/
|
||||||
|
@Test
|
||||||
public void testBuildUniqueFileName_new() {
|
public void testBuildUniqueFileName_new() {
|
||||||
String filename = FileUtils.buildUniqueFileName(new File("/dir"), "Filename", "ext");
|
String filename = FileUtils.buildUniqueFileName(new File("/dir"), "Filename", "ext");
|
||||||
assertEquals("Filename.ext", filename);
|
Assert.assertEquals("Filename.ext", filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests {@link FileUtils#buildUniqueFileName(File, String, String)} when the file exists already.
|
* Tests {@link FileUtils#buildUniqueFileName(File, String, String)} when the file exists already.
|
||||||
*/
|
*/
|
||||||
|
@Test
|
||||||
public void testBuildUniqueFileName_exist() {
|
public void testBuildUniqueFileName_exist() {
|
||||||
// Expect "/default.prop" to exist on the phone/emulator
|
// Expect "/default.prop" to exist on the phone/emulator
|
||||||
String filename = FileUtils.buildUniqueFileName(new File("/"), "default", "prop");
|
String filename = FileUtils.buildUniqueFileName(new File("/"), "default", "prop");
|
||||||
assertEquals("default(1).prop", filename);
|
Assert.assertEquals("default(1).prop", filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests {@link FileUtils#sanitizeFileName(String)} with special characters.
|
* Tests {@link FileUtils#sanitizeFileName(String)} with special characters.
|
||||||
* Verifies that they are sanitized.
|
* Verifies that they are sanitized.
|
||||||
*/
|
*/
|
||||||
|
@Test
|
||||||
public void testSanitizeFileName() {
|
public void testSanitizeFileName() {
|
||||||
String name = "Swim\10ming-^across:/the/ pacific (ocean).";
|
String name = "Swim\10ming-^across:/the/ pacific (ocean).";
|
||||||
String expected = "Swim_ming-^across_the_ pacific (ocean).";
|
String expected = "Swim_ming-^across_the_ pacific (ocean).";
|
||||||
assertEquals(expected, FileUtils.sanitizeFileName(name));
|
Assert.assertEquals(expected, FileUtils.sanitizeFileName(name));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testSanitizeFileNameWithSuffix() {
|
public void testSanitizeFileNameWithSuffix() {
|
||||||
String name = "FileName.jpeg";
|
String name = "FileName.jpeg";
|
||||||
assertEquals(name, FileUtils.sanitizeFileName(name));
|
Assert.assertEquals(name, FileUtils.sanitizeFileName(name));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests {@link FileUtils#sanitizeFileName(String)} with i18n characters (in Chinese and Russian).
|
* Tests {@link FileUtils#sanitizeFileName(String)} with i18n characters (in Chinese and Russian).
|
||||||
* Verifies that they are allowed.
|
* Verifies that they are allowed.
|
||||||
*/
|
*/
|
||||||
|
@Test
|
||||||
public void testSanitizeFileName_i18n() {
|
public void testSanitizeFileName_i18n() {
|
||||||
String name = "您好-привет";
|
String name = "您好-привет";
|
||||||
String expected = "您好-привет";
|
String expected = "您好-привет";
|
||||||
assertEquals(expected, FileUtils.sanitizeFileName(name));
|
Assert.assertEquals(expected, FileUtils.sanitizeFileName(name));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests {@link FileUtils#sanitizeFileName(String)} with special FAT32 characters.
|
* Tests {@link FileUtils#sanitizeFileName(String)} with special FAT32 characters.
|
||||||
* Verifies that they are allowed.
|
* Verifies that they are allowed.
|
||||||
*/
|
*/
|
||||||
|
@Test
|
||||||
public void testSanitizeFileName_special_characters() {
|
public void testSanitizeFileName_special_characters() {
|
||||||
String name = "$%'-_@~`!(){}^#&+,;=[] ";
|
String name = "$%'-_@~`!(){}^#&+,;=[] ";
|
||||||
String expected = "$%'-_@~`!(){}^#&+,;=[] ";
|
String expected = "$%'-_@~`!(){}^#&+,;=[] ";
|
||||||
assertEquals(expected, FileUtils.sanitizeFileName(name));
|
Assert.assertEquals(expected, FileUtils.sanitizeFileName(name));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests {@link FileUtils#sanitizeFileName(String)} with multiple escaped characters in a row.
|
* Tests {@link FileUtils#sanitizeFileName(String)} with multiple escaped characters in a row.
|
||||||
* Verifies that they are collapsed into one underscore.
|
* Verifies that they are collapsed into one underscore.
|
||||||
*/
|
*/
|
||||||
|
@Test
|
||||||
public void testSanitizeFileName_collapse() {
|
public void testSanitizeFileName_collapse() {
|
||||||
String name = "hello//there";
|
String name = "hello//there";
|
||||||
String expected = "hello_there";
|
String expected = "hello_there";
|
||||||
assertEquals(expected, FileUtils.sanitizeFileName(name));
|
Assert.assertEquals(expected, FileUtils.sanitizeFileName(name));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests {@link FileUtils#truncateFileName(File, String, String)}.
|
* Tests {@link FileUtils#truncateFileName(File, String, String)}.
|
||||||
* Verifies the a long file name is truncated.
|
* Verifies the a long file name is truncated.
|
||||||
*/
|
*/
|
||||||
|
@Test
|
||||||
public void testTruncateFileName() {
|
public void testTruncateFileName() {
|
||||||
File directory = new File("/dir1/dir2/");
|
File directory = new File("/dir1/dir2/");
|
||||||
String suffix = ".gpx";
|
String suffix = ".gpx";
|
||||||
@@ -114,8 +127,8 @@ public class FileUtilsTest extends TestCase {
|
|||||||
String truncated = FileUtils.truncateFileName(directory, nameString, suffix);
|
String truncated = FileUtils.truncateFileName(directory, nameString, suffix);
|
||||||
|
|
||||||
for (int i = 0; i < truncated.length(); i++) {
|
for (int i = 0; i < truncated.length(); i++) {
|
||||||
assertEquals('a', truncated.charAt(i));
|
Assert.assertEquals('a', truncated.charAt(i));
|
||||||
}
|
}
|
||||||
assertEquals(FileUtils.MAX_FAT32_PATH_LENGTH, new File(directory, truncated + suffix).getPath().length());
|
Assert.assertEquals(FileUtils.MAX_FAT32_PATH_LENGTH, new File(directory, truncated + suffix).getPath().length());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user