1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
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;
import junit.framework.TestCase;
public class LogTemplateProviderTest extends TestCase {
public static void testApplyTemplatesNone() {
final String noTemplates = " no templates ";
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);
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);
}
}
}
|