/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package vaeke.countrydata.rest;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

import vaeke.restcountries.domain.Country;

import com.eclipsesource.restfuse.HttpJUnitRunner;
import com.google.gson.Gson;
import com.google.gson.stream.JsonReader;

@RunWith(HttpJUnitRunner.class)
public class CountryDataTest {
	
	List<Country> countries;
	
	@Before
	public void before() throws IOException {
		InputStream is = this.getClass().getClassLoader().getResourceAsStream("countries.json");
		Gson gson = new Gson();
		JsonReader reader = new JsonReader(new InputStreamReader(is, "UTF-8"));
		countries = new ArrayList<Country>();
		reader.beginArray();
		while(reader.hasNext()) {
			Country country = gson.fromJson(reader, Country.class);
			countries.add(country);
		}
		reader.endArray();
        reader.close();
	}
	
	@Test
	public void emptyPopulation() {
		List<Country> result = new ArrayList<Country>();
		for(Country c : countries) {
			if(c.getPopulation() == null) {
				result.add(c);
			}
		}
		
		for(Country c : result) {
			System.out.println(c.getName());
		}
	}
}

@@ -227,24 +227,59 @@
 data.rest;%0A%0A
+import static org.junit.Assert.*;%0A%0A
 import java.
@@ -1483,10 +1483,309 @@
 %0A%09%09%7D%0A%09%7D%0A
+%09%0A%09@Test%0A%09public void emptyLanguages() throws Exception %7B%0A%09%09List%3CCountry%3E result = new ArrayList%3CCountry%3E();%0A%09%09for(Country c : countries) %7B%0A%09%09%09result.add(c);%0A%09%09%7D%0A%09%09%0A%09%09for(Country c : result) %7B%0A%09%09%09if(c.getLanguages() == null %7C%7C c.getLanguages().isEmpty())%0A%09%09%09%09System.out.println(c.getName());%0A%09%09%7D%0A%09%7D%0A
 %7D%0A

test case for empty languages