aboutsummaryrefslogtreecommitdiffstats
path: root/tests/src/cgeo/geocaching/gcvote/GCVoteTest.java
blob: c1b5e75c8bc9165cf6e35687a0aa0d58edeefcb9 (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
package cgeo.geocaching.gcvote;

import static org.assertj.core.api.Assertions.assertThat;

import cgeo.geocaching.test.AbstractResourceInstrumentationTestCase;
import cgeo.geocaching.test.R;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Map;

public class GCVoteTest extends AbstractResourceInstrumentationTestCase {

    private InputStream responseStream;

    @Override
    protected void setUp() throws Exception {
        super.setUp();
        responseStream = new ByteArrayInputStream(getFileContent(R.raw.gcvote).getBytes());
        responseStream.mark(getFileContent(R.raw.gcvote).getBytes().length + 1);
    }

    private InputStream responseStream() {
        try {
            responseStream.reset();
        } catch (final IOException ignored) {
            // Cannot happen
        }
        return responseStream;
    }

    public void testGetRatingsByGeocode() {
        final Map<String, GCVoteRating> ratings = GCVote.getRatingsFromXMLResponse(responseStream(), false);
        assertThat(ratings).hasSize(10);
        assertThat(ratings).containsKey("GCKF13");
        assertThat(ratings.get("GC1WEVZ")).isEqualToComparingFieldByField(new GCVoteRating(3.75f, 2, 0));
    }

    public void testGetRatingsByGuid() {
        final Map<String, GCVoteRating> ratings = GCVote.getRatingsFromXMLResponse(responseStream(), true);
        assertThat(ratings).hasSize(10);
        assertThat(ratings).containsKey("a02894bb-4a08-4c09-a73c-25939894ba15");
        assertThat(ratings.get("5520c33b-3941-45ca-9056-ea655dbaadf7")).isEqualToComparingFieldByField(new GCVoteRating(3.75f, 2, 0));
    }

}