summaryrefslogtreecommitdiff
path: root/python/edu/learn-python/tests/JsonParserTest.java
blob: 903f0a539acf87597b0598a0244578e14250f2eb (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
import com.google.gson.FieldNamingPolicy;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import org.junit.Before;
import org.junit.Test;
import com.jetbrains.python.edu.StudyUtils;
import com.jetbrains.python.edu.course.Course;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStreamReader;
import java.io.Reader;

import static org.junit.Assert.assertEquals;

/**
 * author: liana
 * data: 7/4/14.
 */
public class JsonParserTest {
  private Course myCourse = null;
  @Before
  public void setUp() throws FileNotFoundException {
    Reader reader = new InputStreamReader(new FileInputStream("EDIDE/testData/course.json"));
    Gson gson = new GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES).create();
    myCourse = gson.fromJson(reader, Course.class);
  }

  @Test
  public void testCourseLevel() {
    assertEquals(myCourse.getName(), "Python для начинающих");
    assertEquals(StudyUtils.getFirst(myCourse.getLessons().get(1).getTaskList().get(0).getUserTests()).getInput(), "sum-input.txt");
    assertEquals(myCourse.getLessons().size(), 2);
    assertEquals(myCourse.getLessons().get(0).getTaskList().size(), 2);
    assertEquals(myCourse.getLessons().get(1).getTaskList().size(), 1);
  }
}