aboutsummaryrefslogtreecommitdiffstats
path: root/tests/src/cgeo/geocaching/utils
diff options
context:
space:
mode:
Diffstat (limited to 'tests/src/cgeo/geocaching/utils')
-rw-r--r--tests/src/cgeo/geocaching/utils/AngleUtilsTest.java16
-rw-r--r--tests/src/cgeo/geocaching/utils/CryptUtilsTest.java26
-rw-r--r--tests/src/cgeo/geocaching/utils/DateUtilsTest.java28
-rw-r--r--tests/src/cgeo/geocaching/utils/HtmlUtilsTest.java10
-rw-r--r--tests/src/cgeo/geocaching/utils/LazyInitializedListTest.java14
-rw-r--r--tests/src/cgeo/geocaching/utils/LeastRecentlyUsedMapTest.java42
-rw-r--r--tests/src/cgeo/geocaching/utils/LeastRecentlyUsedSetTest.java32
-rw-r--r--tests/src/cgeo/geocaching/utils/LogTemplateProviderTest.java4
-rw-r--r--tests/src/cgeo/geocaching/utils/MiscUtilsTest.java11
-rw-r--r--tests/src/cgeo/geocaching/utils/ProcessUtilsTest.java9
-rw-r--r--tests/src/cgeo/geocaching/utils/TextUtilsTest.java6
-rw-r--r--tests/src/cgeo/geocaching/utils/XmlUtilsTest.java4
12 files changed, 125 insertions, 77 deletions
diff --git a/tests/src/cgeo/geocaching/utils/AngleUtilsTest.java b/tests/src/cgeo/geocaching/utils/AngleUtilsTest.java
index e214d84..7ab3909 100644
--- a/tests/src/cgeo/geocaching/utils/AngleUtilsTest.java
+++ b/tests/src/cgeo/geocaching/utils/AngleUtilsTest.java
@@ -1,17 +1,19 @@
package cgeo.geocaching.utils;
+import static org.assertj.core.api.Assertions.assertThat;
+
import android.test.AndroidTestCase;
public class AngleUtilsTest extends AndroidTestCase {
public static void testNormalize() {
- assertEquals(0.0f, AngleUtils.normalize(0));
- assertEquals(0.0f, AngleUtils.normalize(360));
- assertEquals(0.0f, AngleUtils.normalize(720));
- assertEquals(0.0f, AngleUtils.normalize(-360));
- assertEquals(0.0f, AngleUtils.normalize(-720));
- assertEquals(1.0f, AngleUtils.normalize(721));
- assertEquals(359.0f, AngleUtils.normalize(-721));
+ assertThat(AngleUtils.normalize(0)).isEqualTo(0.0f);
+ assertThat(AngleUtils.normalize(360)).isEqualTo(0.0f);
+ assertThat(AngleUtils.normalize(720)).isEqualTo(0.0f);
+ assertThat(AngleUtils.normalize(-360)).isEqualTo(0.0f);
+ assertThat(AngleUtils.normalize(-720)).isEqualTo(0.0f);
+ assertThat(AngleUtils.normalize(721)).isEqualTo(1.0f);
+ assertThat(AngleUtils.normalize(-721)).isEqualTo(359.0f);
}
public static void testDifference() {
diff --git a/tests/src/cgeo/geocaching/utils/CryptUtilsTest.java b/tests/src/cgeo/geocaching/utils/CryptUtilsTest.java
index 9a74167..7175f3d 100644
--- a/tests/src/cgeo/geocaching/utils/CryptUtilsTest.java
+++ b/tests/src/cgeo/geocaching/utils/CryptUtilsTest.java
@@ -1,32 +1,34 @@
package cgeo.geocaching.utils;
+import static org.assertj.core.api.Assertions.assertThat;
+
import cgeo.geocaching.connector.gc.GCConstants;
import junit.framework.TestCase;
public class CryptUtilsTest extends TestCase {
public static void testROT13() {
- assertEquals("", CryptUtils.rot13(""));
- assertEquals("", CryptUtils.rot13((String) null));
- assertEquals("Pnpur uvag", CryptUtils.rot13("Cache hint"));
- assertEquals("Pnpur [plain] uvag", CryptUtils.rot13("Cache [plain] hint"));
- assertEquals("[all plain]", CryptUtils.rot13("[all plain]"));
- assertEquals("123", CryptUtils.rot13("123"));
+ assertThat(CryptUtils.rot13("")).isEqualTo("");
+ assertThat(CryptUtils.rot13((String) null)).isEqualTo("");
+ assertThat(CryptUtils.rot13("Cache hint")).isEqualTo("Pnpur uvag");
+ assertThat(CryptUtils.rot13("Cache [plain] hint")).isEqualTo("Pnpur [plain] uvag");
+ assertThat(CryptUtils.rot13("[all plain]")).isEqualTo("[all plain]");
+ assertThat(CryptUtils.rot13("123")).isEqualTo("123");
}
public static void testConvertToGcBase31() {
- assertEquals(1186660, GCConstants.gccodeToGCId("GC1PKK9"));
- assertEquals(4660, GCConstants.gccodeToGCId("GC1234"));
- assertEquals(61731, GCConstants.gccodeToGCId("GCF123"));
+ assertThat(GCConstants.gccodeToGCId("GC1PKK9")).isEqualTo(1186660);
+ assertThat(GCConstants.gccodeToGCId("GC1234")).isEqualTo(4660);
+ assertThat(GCConstants.gccodeToGCId("GCF123")).isEqualTo(61731);
}
public static void testIssue1902() {
- assertEquals("ƖƖlƖƖƖƖ", CryptUtils.rot13("ƖƖyƖƖƖƖ"));
+ assertThat(CryptUtils.rot13("ƖƖyƖƖƖƖ")).isEqualTo("ƖƖlƖƖƖƖ");
}
public static void testMd5() {
- assertEquals("d41d8cd98f00b204e9800998ecf8427e", CryptUtils.md5(""));
+ assertThat(CryptUtils.md5("")).isEqualTo("d41d8cd98f00b204e9800998ecf8427e");
// expected value taken from debugger. should assure every developer uses UTF-8
- assertEquals("a7f4e3ec08f09be2ef7ecb4eea5f8981", CryptUtils.md5("äöü"));
+ assertThat(CryptUtils.md5("äöü")).isEqualTo("a7f4e3ec08f09be2ef7ecb4eea5f8981");
}
}
diff --git a/tests/src/cgeo/geocaching/utils/DateUtilsTest.java b/tests/src/cgeo/geocaching/utils/DateUtilsTest.java
index 0a9d3e3..d0a2b4a 100644
--- a/tests/src/cgeo/geocaching/utils/DateUtilsTest.java
+++ b/tests/src/cgeo/geocaching/utils/DateUtilsTest.java
@@ -1,5 +1,10 @@
package cgeo.geocaching.utils;
+import static org.assertj.core.api.Assertions.assertThat;
+
+import cgeo.geocaching.Geocache;
+import cgeo.geocaching.enumerations.CacheType;
+
import java.util.Calendar;
import junit.framework.TestCase;
@@ -10,8 +15,29 @@ public class DateUtilsTest extends TestCase {
final Calendar start = Calendar.getInstance();
for (int hour = 0; hour < 24; hour++) {
start.set(Calendar.HOUR_OF_DAY, hour);
- assertEquals(0, DateUtils.daysSince(start.getTimeInMillis()));
+ assertThat(DateUtils.daysSince(start.getTimeInMillis())).isEqualTo(0);
}
}
+ public static void testIsPastEvent() {
+ final Calendar start = Calendar.getInstance();
+ start.set(Calendar.HOUR_OF_DAY, 0);
+ start.set(Calendar.MINUTE, 10);
+ assertPastEvent(start, false);
+
+ start.set(Calendar.HOUR_OF_DAY, 23);
+ assertPastEvent(start, false);
+
+ start.add(Calendar.DAY_OF_MONTH, -1);
+ assertPastEvent(start, true);
+ }
+
+ private static void assertPastEvent(final Calendar start, boolean expectedPast) {
+ final Geocache cache = new Geocache();
+ cache.setType(CacheType.EVENT);
+
+ cache.setHidden(start.getTime());
+ assertThat(DateUtils.isPastEvent(cache)).isEqualTo(expectedPast);
+ }
+
}
diff --git a/tests/src/cgeo/geocaching/utils/HtmlUtilsTest.java b/tests/src/cgeo/geocaching/utils/HtmlUtilsTest.java
index 5f2070d..65e86b8 100644
--- a/tests/src/cgeo/geocaching/utils/HtmlUtilsTest.java
+++ b/tests/src/cgeo/geocaching/utils/HtmlUtilsTest.java
@@ -1,5 +1,7 @@
package cgeo.geocaching.utils;
+import static org.assertj.core.api.Assertions.assertThat;
+
import org.apache.commons.lang3.StringUtils;
import junit.framework.TestCase;
@@ -7,10 +9,10 @@ import junit.framework.TestCase;
public class HtmlUtilsTest extends TestCase {
public static void testExtractText() {
- assertEquals(StringUtils.EMPTY, HtmlUtils.extractText(null));
- assertEquals(StringUtils.EMPTY, HtmlUtils.extractText(StringUtils.EMPTY));
- assertEquals(StringUtils.EMPTY, HtmlUtils.extractText(" "));
- assertEquals("bold", HtmlUtils.extractText("<b>bold</b>"));
+ assertThat(HtmlUtils.extractText(null)).isEqualTo(StringUtils.EMPTY);
+ assertThat(HtmlUtils.extractText(StringUtils.EMPTY)).isEqualTo(StringUtils.EMPTY);
+ assertThat(HtmlUtils.extractText(" ")).isEqualTo(StringUtils.EMPTY);
+ assertThat(HtmlUtils.extractText("<b>bold</b>")).isEqualTo("bold");
}
}
diff --git a/tests/src/cgeo/geocaching/utils/LazyInitializedListTest.java b/tests/src/cgeo/geocaching/utils/LazyInitializedListTest.java
index c0be156..9338d10 100644
--- a/tests/src/cgeo/geocaching/utils/LazyInitializedListTest.java
+++ b/tests/src/cgeo/geocaching/utils/LazyInitializedListTest.java
@@ -1,10 +1,12 @@
package cgeo.geocaching.utils;
-import junit.framework.TestCase;
+import static org.assertj.core.api.Assertions.assertThat;
import java.util.ArrayList;
import java.util.List;
+import junit.framework.TestCase;
+
public class LazyInitializedListTest extends TestCase {
private static final class MockedLazyInitializedList extends LazyInitializedList<String> {
@@ -16,16 +18,16 @@ public class LazyInitializedListTest extends TestCase {
public static void testAccess() {
final LazyInitializedList<String> list = new MockedLazyInitializedList();
- assertTrue(list.isEmpty());
+ assertThat(list.isEmpty()).isTrue();
list.add("Test");
- assertFalse(list.isEmpty());
- assertEquals(1, list.size());
+ assertThat(list.isEmpty()).isFalse();
+ assertThat(list).hasSize(1);
int iterations = 0;
for (String element : list) {
- assertEquals("Test", element);
+ assertThat(element).isEqualTo("Test");
iterations++;
}
- assertEquals(1, iterations);
+ assertThat(iterations).isEqualTo(1);
}
}
diff --git a/tests/src/cgeo/geocaching/utils/LeastRecentlyUsedMapTest.java b/tests/src/cgeo/geocaching/utils/LeastRecentlyUsedMapTest.java
index 11088e2..c3f563c 100644
--- a/tests/src/cgeo/geocaching/utils/LeastRecentlyUsedMapTest.java
+++ b/tests/src/cgeo/geocaching/utils/LeastRecentlyUsedMapTest.java
@@ -1,5 +1,7 @@
package cgeo.geocaching.utils;
+import static org.assertj.core.api.Assertions.assertThat;
+
import cgeo.geocaching.Geocache;
import java.util.Map;
@@ -47,39 +49,39 @@ public class LeastRecentlyUsedMapTest extends AbstractLRUTest {
public static void testRemoveEldestEntry() {
final LeastRecentlyUsedMap<String, Geocache> cache = new LeastRecentlyUsedMap.LruCache<String, Geocache>(10);
final Geocache first = new Geocache();
- assertNull(cache.put("1", first));
+ assertThat(cache.put("1", first)).isNull();
final Geocache second = new Geocache();
- assertNull(cache.put("2", second));
+ assertThat(cache.put("2", second)).isNull();
- assertEquals(2, cache.size());
- assertTrue(cache.containsKey("1"));
- assertTrue(cache.containsValue(first));
- assertTrue(cache.containsKey("2"));
- assertTrue(cache.containsValue(second));
+ assertThat(cache).hasSize(2);
+ assertThat(cache.containsKey("1")).isTrue();
+ assertThat(cache.containsValue(first)).isTrue();
+ assertThat(cache.containsKey("2")).isTrue();
+ assertThat(cache.containsValue(second)).isTrue();
for (int i = 3; i <= 10; i++) {
- assertNull(cache.put(Integer.toString(i), new Geocache()));
+ assertThat(cache.put(Integer.toString(i), new Geocache())).isNull();
}
- assertEquals(10, cache.size());
- assertTrue(cache.containsKey("1"));
- assertTrue(cache.containsValue(first));
- assertTrue(cache.containsKey("2"));
- assertTrue(cache.containsValue(second));
+ assertThat(cache).hasSize(10);
+ assertThat(cache.containsKey("1")).isTrue();
+ assertThat(cache.containsValue(first)).isTrue();
+ assertThat(cache.containsKey("2")).isTrue();
+ assertThat(cache.containsValue(second)).isTrue();
- assertNotNull(cache.remove("1")); // just replacing the old entry would not work
- assertNull(cache.put("1", new Geocache()));
- assertNull(cache.put("11", new Geocache()));
+ assertThat(cache.remove("1")).isNotNull(); // just replacing the old entry would not work
+ assertThat(cache.put("1", new Geocache())).isNull();
+ assertThat(cache.put("11", new Geocache())).isNull();
- assertEquals(10, cache.size());
+ assertThat(cache).hasSize(10);
// first has been overwritten by new value, but key must be in, because it is very new
- assertTrue(cache.containsKey("1"));
+ assertThat(cache.containsKey("1")).isTrue();
// second has been overwritten by 11
- assertFalse(cache.containsKey("2"));
- assertTrue(cache.containsKey("11"));
+ assertThat(cache.containsKey("2")).isFalse();
+ assertThat(cache.containsKey("11")).isTrue();
}
}
diff --git a/tests/src/cgeo/geocaching/utils/LeastRecentlyUsedSetTest.java b/tests/src/cgeo/geocaching/utils/LeastRecentlyUsedSetTest.java
index 7e06b83..2b6f8a0 100644
--- a/tests/src/cgeo/geocaching/utils/LeastRecentlyUsedSetTest.java
+++ b/tests/src/cgeo/geocaching/utils/LeastRecentlyUsedSetTest.java
@@ -1,5 +1,7 @@
package cgeo.geocaching.utils;
+import static org.assertj.core.api.Assertions.assertThat;
+
import cgeo.geocaching.Geocache;
import java.util.Set;
@@ -29,38 +31,38 @@ public class LeastRecentlyUsedSetTest extends AbstractLRUTest {
final LeastRecentlyUsedSet<Geocache> caches = new LeastRecentlyUsedSet<Geocache>(10);
final Geocache first = new Geocache();
first.setGeocode("1");
- assertTrue(caches.add(first));
+ assertThat(caches.add(first)).isTrue();
final Geocache second = new Geocache();
second.setGeocode("2");
- assertTrue(caches.add(second));
+ assertThat(caches.add(second)).isTrue();
- assertEquals(2, caches.size());
- assertTrue(caches.contains(first));
- assertTrue(caches.contains(second));
+ assertThat(caches).hasSize(2);
+ assertThat(caches.contains(first)).isTrue();
+ assertThat(caches.contains(second)).isTrue();
// adding first cache again does not change set
- assertFalse(caches.add(first));
- assertEquals(2, caches.size());
+ assertThat(caches.add(first)).isFalse();
+ assertThat(caches).hasSize(2);
for (int i = 3; i <= 10; i++) {
final Geocache cache = new Geocache();
cache.setGeocode(Integer.toString(i));
- assertTrue(caches.add(cache));
+ assertThat(caches.add(cache)).isTrue();
}
- assertEquals(10, caches.size());
- assertTrue(caches.contains(first));
- assertTrue(caches.contains(second));
+ assertThat(caches).hasSize(10);
+ assertThat(caches.contains(first)).isTrue();
+ assertThat(caches.contains(second)).isTrue();
final Geocache c11 = new Geocache();
c11.setGeocode("11");
- assertTrue(caches.add(c11));
+ assertThat(caches.add(c11)).isTrue();
- assertEquals(10, caches.size());
+ assertThat(caches).hasSize(10);
// first was used again, there second is the oldest and has been overwritten by 11
- assertTrue(caches.contains(first));
- assertFalse(caches.contains(second));
+ assertThat(caches.contains(first)).isTrue();
+ assertThat(caches.contains(second)).isFalse();
}
} \ No newline at end of file
diff --git a/tests/src/cgeo/geocaching/utils/LogTemplateProviderTest.java b/tests/src/cgeo/geocaching/utils/LogTemplateProviderTest.java
index 249cbb1..a7dcb2b 100644
--- a/tests/src/cgeo/geocaching/utils/LogTemplateProviderTest.java
+++ b/tests/src/cgeo/geocaching/utils/LogTemplateProviderTest.java
@@ -1,5 +1,7 @@
package cgeo.geocaching.utils;
+import static org.assertj.core.api.Assertions.assertThat;
+
import cgeo.geocaching.utils.LogTemplateProvider.LogContext;
import java.util.Calendar;
@@ -14,7 +16,7 @@ public class LogTemplateProviderTest extends TestCase {
// This test can occasionally fail if the current year changes right after the next line.
final String currentYear = Integer.toString(Calendar.YEAR);
- assertTrue(LogTemplateProvider.applyTemplates("[DATE]", new LogContext(null, null, true)).contains(currentYear));
+ assertThat(LogTemplateProvider.applyTemplates("[DATE]", new LogContext(null, null, true)).contains(currentYear)).isTrue();
}
}
diff --git a/tests/src/cgeo/geocaching/utils/MiscUtilsTest.java b/tests/src/cgeo/geocaching/utils/MiscUtilsTest.java
index 2ee99c4..8678d75 100644
--- a/tests/src/cgeo/geocaching/utils/MiscUtilsTest.java
+++ b/tests/src/cgeo/geocaching/utils/MiscUtilsTest.java
@@ -1,14 +1,17 @@
package cgeo.geocaching.utils;
-import junit.framework.TestCase;
+import static org.assertj.core.api.Assertions.assertThat;
import java.util.LinkedList;
import java.util.List;
+import junit.framework.TestCase;
+
public class MiscUtilsTest extends TestCase {
public static void testBufferEmpty() {
- for (final List<String> s: MiscUtils.buffer(new LinkedList<String>(), 10)) {
+ for (@SuppressWarnings("unused")
+ final List<String> s : MiscUtils.buffer(new LinkedList<String>(), 10)) {
fail("empty collection should not iterate");
}
}
@@ -20,7 +23,7 @@ public class MiscUtilsTest extends TestCase {
}
int count = 0;
for (final List<Integer> subList: MiscUtils.buffer(list, 10)) {
- assertEquals("each sublist has the right size", 10, subList.size());
+ assertThat(subList).hasSize(10);
assertEquals("sublist has the right content", count * 10, (int) subList.get(0));
count++;
}
@@ -34,7 +37,7 @@ public class MiscUtilsTest extends TestCase {
}
int count = 0;
for (final List<Integer> subList: MiscUtils.buffer(list, 10)) {
- assertTrue("each sublist has no more than the allowed number of arguments", subList.size() <= 10);
+ assertThat(subList.size()).overridingErrorMessage("each sublist has no more than the allowed number of arguments").isLessThanOrEqualTo(10);
count += subList.size();
}
assertEquals("all the elements were seen", 48, count);
diff --git a/tests/src/cgeo/geocaching/utils/ProcessUtilsTest.java b/tests/src/cgeo/geocaching/utils/ProcessUtilsTest.java
index f34faa6..2c6ed18 100644
--- a/tests/src/cgeo/geocaching/utils/ProcessUtilsTest.java
+++ b/tests/src/cgeo/geocaching/utils/ProcessUtilsTest.java
@@ -1,21 +1,22 @@
package cgeo.geocaching.utils;
+import static org.assertj.core.api.Assertions.assertThat;
import junit.framework.TestCase;
public class ProcessUtilsTest extends TestCase {
public static void testIsInstalled() {
- assertTrue(ProcessUtils.isInstalled("com.android.launcher"));
+ assertThat(ProcessUtils.isInstalled("com.android.launcher")).isTrue();
}
public static void testIsInstalledNotLaunchable() {
final String packageName = "com.android.systemui";
- assertTrue(ProcessUtils.isInstalled(packageName));
- assertFalse(ProcessUtils.isLaunchable(packageName));
+ assertThat(ProcessUtils.isInstalled(packageName)).isTrue();
+ assertThat(ProcessUtils.isLaunchable(packageName)).isFalse();
}
public static void testIsLaunchable() {
- assertTrue(ProcessUtils.isInstalled("com.android.settings"));
+ assertThat(ProcessUtils.isInstalled("com.android.settings")).isTrue();
}
}
diff --git a/tests/src/cgeo/geocaching/utils/TextUtilsTest.java b/tests/src/cgeo/geocaching/utils/TextUtilsTest.java
index 2093383..d1dba84 100644
--- a/tests/src/cgeo/geocaching/utils/TextUtilsTest.java
+++ b/tests/src/cgeo/geocaching/utils/TextUtilsTest.java
@@ -1,5 +1,7 @@
package cgeo.geocaching.utils;
+import static org.assertj.core.api.Assertions.assertThat;
+
import cgeo.geocaching.connector.gc.GCConstants;
import cgeo.geocaching.connector.gc.GCConstantsTest;
import cgeo.geocaching.test.mock.MockedCache;
@@ -12,11 +14,11 @@ public class TextUtilsTest extends AndroidTestCase {
public static void testRegEx() {
final String page = MockedCache.readCachePage("GC2CJPF");
assertEquals(GCConstantsTest.MOCK_LOGIN_NAME, TextUtils.getMatch(page, GCConstants.PATTERN_LOGIN_NAME, true, "???"));
- assertTrue(page.contains("id=\"ctl00_hlRenew\"") || GCConstants.MEMBER_STATUS_PM.equals(TextUtils.getMatch(page, GCConstants.PATTERN_MEMBER_STATUS, true, "???")));
+ assertThat(page.contains("id=\"ctl00_hlRenew\"") || GCConstants.MEMBER_STATUS_PM.equals(TextUtils.getMatch(page, GCConstants.PATTERN_MEMBER_STATUS, true, "???"))).isTrue();
}
public static void testReplaceWhitespaces() {
- assertEquals("foo bar baz ", TextUtils.replaceWhitespace(" foo\n\tbar \r baz "));
+ assertThat(TextUtils.replaceWhitespace(" foo\n\tbar \r baz ")).isEqualTo("foo bar baz ");
}
public static void testControlCharactersCleanup() {
diff --git a/tests/src/cgeo/geocaching/utils/XmlUtilsTest.java b/tests/src/cgeo/geocaching/utils/XmlUtilsTest.java
index a089ee0..71f3100 100644
--- a/tests/src/cgeo/geocaching/utils/XmlUtilsTest.java
+++ b/tests/src/cgeo/geocaching/utils/XmlUtilsTest.java
@@ -1,5 +1,7 @@
package cgeo.geocaching.utils;
+import static org.assertj.core.api.Assertions.assertThat;
+
import cgeo.org.kxml2.io.KXmlSerializer;
import org.apache.commons.lang3.CharEncoding;
@@ -37,7 +39,7 @@ public class XmlUtilsTest extends TestCase {
private void assertXmlEquals(final String expected) throws IOException {
xml.endDocument();
xml.flush();
- assertEquals("<?xml version='1.0' encoding='UTF-8' ?>" + expected, stringWriter.toString());
+ assertThat(stringWriter.toString()).isEqualTo("<?xml version='1.0' encoding='UTF-8' ?>" + expected);
}
public void testMultipleTexts() throws Exception {