summaryrefslogtreecommitdiff
path: root/src/test/java/com/p4square/ccbapi/model/XmlBinderTestBase.java
blob: 2422d39bafb4dbfcf76b07aaac0dcbfce6fde092 (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
package com.p4square.ccbapi.model;

import java.io.InputStream;
import com.p4square.ccbapi.CCBXmlBinder;
import org.junit.Before;

/**
 * Created by jesterpm on 3/14/16.
 */
public class XmlBinderTestBase {

    private CCBXmlBinder binder;

    @Before
    public void setUp() {
        binder = new CCBXmlBinder();
    }

    /**
     * Helper to test the response stored in a file.
     *
     * @param filename The name of the xml file containing the response.
     * @param clazz The class to bind to.
     * @param <T> The type of the return value.
     * @return The parsed response.
     * @throws Exception If something fails.
     */
    protected <T extends CCBAPIResponse> T parseFile(final String filename, final Class<T> clazz) throws Exception {
        InputStream in = getClass().getResourceAsStream(filename);
        if (in == null) {
            throw new AssertionError("Could not find file " + filename);
        }
        try {
            return binder.bindResponseXML(in, clazz);
        } finally {
            in.close();
        }
    }
}