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/LogTemplateProviderTest.java46
-rw-r--r--tests/src/cgeo/geocaching/utils/TextUtilsTest.java6
2 files changed, 46 insertions, 6 deletions
diff --git a/tests/src/cgeo/geocaching/utils/LogTemplateProviderTest.java b/tests/src/cgeo/geocaching/utils/LogTemplateProviderTest.java
index a7dcb2b..77832b0 100644
--- a/tests/src/cgeo/geocaching/utils/LogTemplateProviderTest.java
+++ b/tests/src/cgeo/geocaching/utils/LogTemplateProviderTest.java
@@ -2,6 +2,8 @@ package cgeo.geocaching.utils;
import static org.assertj.core.api.Assertions.assertThat;
+import cgeo.geocaching.settings.Settings;
+import cgeo.geocaching.settings.TestSettings;
import cgeo.geocaching.utils.LogTemplateProvider.LogContext;
import java.util.Calendar;
@@ -10,13 +12,51 @@ import junit.framework.TestCase;
public class LogTemplateProviderTest extends TestCase {
- public static void testApplyTemplates() {
+ public static void testApplyTemplatesNone() {
final String noTemplates = " no templates ";
- assertEquals(noTemplates, LogTemplateProvider.applyTemplates(noTemplates, new LogContext(null, null, true)));
+ final String signature = LogTemplateProvider.applyTemplates(noTemplates, new LogContext(null, null, true));
+ assertThat(signature).isEqualTo(noTemplates);
+ }
+ public static void testApplyTemplates() {
// This test can occasionally fail if the current year changes right after the next line.
final String currentYear = Integer.toString(Calendar.YEAR);
- assertThat(LogTemplateProvider.applyTemplates("[DATE]", new LogContext(null, null, true)).contains(currentYear)).isTrue();
+ final String signature = LogTemplateProvider.applyTemplates("[DATE]", new LogContext(null, null, true));
+ assertThat(signature).contains(currentYear);
+ }
+
+ /**
+ * signature itself can contain templates, therefore nested applying is necessary
+ */
+ public static void testApplySignature() {
+ String oldSignature = Settings.getSignature();
+ try {
+ TestSettings.setSignature("[DATE]");
+ String currentDate = LogTemplateProvider.applyTemplates(Settings.getSignature(), new LogContext(null, null, true));
+ final String signatureTemplate = "Signature [SIGNATURE]";
+ final String signature = LogTemplateProvider.applyTemplates(signatureTemplate, new LogContext(null, null, true));
+ assertThat(signature).isEqualTo("Signature " + currentDate);
+
+ final String currentYear = Integer.toString(Calendar.YEAR);
+ assertThat(signature).contains(currentYear);
+ } finally {
+ TestSettings.setSignature(oldSignature);
+ }
+ }
+
+ /**
+ * signature must not contain itself as template
+ */
+ public static void testApplyInvalidSignature() {
+ String oldSignature = Settings.getSignature();
+ try {
+ final String signatureTemplate = "[SIGNATURE]";
+ TestSettings.setSignature(signatureTemplate);
+ final String signature = LogTemplateProvider.applyTemplates(signatureTemplate, new LogContext(null, null, true));
+ assertThat(signature).isEqualTo("invalid signature template");
+ } finally {
+ TestSettings.setSignature(oldSignature);
+ }
}
}
diff --git a/tests/src/cgeo/geocaching/utils/TextUtilsTest.java b/tests/src/cgeo/geocaching/utils/TextUtilsTest.java
index d1dba84..29c4864 100644
--- a/tests/src/cgeo/geocaching/utils/TextUtilsTest.java
+++ b/tests/src/cgeo/geocaching/utils/TextUtilsTest.java
@@ -13,7 +13,7 @@ import java.util.regex.Pattern;
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, "???"));
+ assertThat(TextUtils.getMatch(page, GCConstants.PATTERN_LOGIN_NAME, true, "???")).isEqualTo(GCConstantsTest.MOCK_LOGIN_NAME);
assertThat(page.contains("id=\"ctl00_hlRenew\"") || GCConstants.MEMBER_STATUS_PM.equals(TextUtils.getMatch(page, GCConstants.PATTERN_MEMBER_STATUS, true, "???"))).isTrue();
}
@@ -23,7 +23,7 @@ public class TextUtilsTest extends AndroidTestCase {
public static void testControlCharactersCleanup() {
final Pattern patternAll = Pattern.compile("(.*)", Pattern.DOTALL);
- assertEquals("some control characters removed", TextUtils.getMatch("some" + "\u001C" + "control" + (char) 0x1D + "characters removed", patternAll, ""));
- assertEquals("newline also removed", TextUtils.getMatch("newline\nalso\nremoved", patternAll, ""));
+ assertThat(TextUtils.getMatch("some" + "\u001C" + "control" + (char) 0x1D + "characters removed", patternAll, "")).isEqualTo("some control characters removed");
+ assertThat(TextUtils.getMatch("newline\nalso\nremoved", patternAll, "")).isEqualTo("newline also removed");
}
}