aboutsummaryrefslogtreecommitdiffstats
path: root/tests/src/cgeo/geocaching/twitter/TwitterTest.java
blob: 9de5e2fe1fbe6ff4c92d1ee3185b5aeeb1c2c334 (plain)
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package cgeo.geocaching.twitter;

import cgeo.geocaching.Geocache;
import cgeo.geocaching.LogEntry;
import cgeo.geocaching.Trackable;
import cgeo.geocaching.enumerations.LogType;
import cgeo.geocaching.settings.Settings;
import cgeo.geocaching.settings.TestSettings;

import junit.framework.TestCase;

public class TwitterTest extends TestCase {

    public static void testTrackableMessage() {
        final String oldMessage = Settings.getTrackableTwitterMessage();
        try {
            TestSettings.setTrackableTwitterMessage("I touched [NAME] ([URL]).");
            Trackable tb = new Trackable();
            tb.setName("Travel bug");
            tb.setGeocode("TB1234");
            assertEquals("I touched Travel bug (http://www.geocaching.com//track/details.aspx?tracker=TB1234). #cgeo #geocaching", Twitter.getStatusMessage(tb, null));
        } finally {
            TestSettings.setTrackableTwitterMessage(oldMessage);
        }
    }

    public static void testCacheMessage() {
        final String oldMessage = Settings.getCacheTwitterMessage();
        try {
            TestSettings.setCacheTwitterMessage("I found [NAME] ([URL]).");
            Geocache cache = new Geocache();
            cache.setGeocode("GC1234");
            cache.setName("TwitterTest");
            assertEquals("I found TwitterTest (http://coord.info/GC1234). #cgeo #geocaching", Twitter.getStatusMessage(cache, null));
        } finally {
            TestSettings.setCacheTwitterMessage(oldMessage);
        }
    }

    public static void testCacheMessageWithLogContent() {
        final String oldMessage = Settings.getCacheTwitterMessage();
        try {
            TestSettings.setCacheTwitterMessage("[LOG]");
            Geocache cache = new Geocache();
            LogEntry log = new LogEntry(0, LogType.FOUND_IT, "log text");
            assertEquals("log text #cgeo #geocaching", Twitter.getStatusMessage(cache, log));
        } finally {
            TestSettings.setCacheTwitterMessage(oldMessage);
        }
    }

    public static void testTrackableMessageWithLogContent() {
        final String oldMessage = Settings.getCacheTwitterMessage();
        try {
            TestSettings.setTrackableTwitterMessage("[LOG]");
            Trackable trackable = new Trackable();
            LogEntry log = new LogEntry(0, LogType.FOUND_IT, "trackable log text");
            assertEquals("trackable log text #cgeo #geocaching", Twitter.getStatusMessage(trackable, log));
        } finally {
            TestSettings.setTrackableTwitterMessage(oldMessage);
        }
    }

    public static void testAvoidDuplicateTags() {
        final String oldMessage = Settings.getCacheTwitterMessage();
        try {
            TestSettings.setCacheTwitterMessage("[NAME] #cgeo #mytag");
            Geocache cache = new Geocache();
            cache.setGeocode("GC1234");
            cache.setName("TwitterTest");
            assertEquals("TwitterTest #cgeo #mytag #geocaching", Twitter.getStatusMessage(cache, null));
        } finally {
            TestSettings.setCacheTwitterMessage(oldMessage);
        }
    }
}