/**
 *	MovieHelperTest.java
 *
 *	@author Johan Brook
 *	@copyright (c) 2012 Johan Brook
 *	@license MIT
 */

package se.chalmers.watchmetest.util;

import java.util.List;
import org.json.JSONArray;
import org.json.JSONException;

import junit.framework.TestCase;
import se.chalmers.watchme.model.Movie;
import se.chalmers.watchme.model.Tag;
import se.chalmers.watchme.utils.MovieHelper;


public class MovieHelperTest extends TestCase {
	
	public void testStringArrayToTagList() {
		
		String[] tagStrings = {"tag1", "tag2", "tag3", "tag4", "tag5"};
		
		List<Tag> tags = MovieHelper.stringArrayToTagList(tagStrings);
		
		for(String tagString : tagStrings) {
			assertTrue(tags.contains(new Tag(tagString)));
		}
		
	}
	
	public void testJsonArrayToMovieList() {
		String json = "[{\""+ Movie.JSON_KEY_NAME +"\": \"James Bond\", "+ 
						"\""+ Movie.JSON_KEY_ID + "\": 202929}]";
		
		try {
			JSONArray array = new JSONArray(json);
			
			assertNotNull(array);
			assertTrue(array.length() == 1);
			
			List<Movie> movies = MovieHelper.jsonArrayToMovieList(array);
			
			assertEquals(array.length(), movies.size());
			
			Movie movie = movies.get(0);
			
			assertEquals("James Bond", movie.getTitle());
			assertEquals(202929, movie.getApiID());
			
		} catch (JSONException e) {
			e.printStackTrace();
		}
		
		
	}
	
}

@@ -716,16 +716,432 @@
 %09%09%0A%09%7D%0A%09%0A
+%09public void testJsonArrayToList() %7B%0A%09%09String json = %22%5B%5C%22james%5C%22, %5C%22bond%5C%22%5D%22;%0A%09%09%0A%09%09try %7B%0A%09%09%09JSONArray array = new JSONArray(json);%0A%09%09%09assertNotNull(array);%0A%09%09%09%0A%09%09%09List%3CString%3E list = MovieHelper.jsonArrayToList(array);%0A%09%09%09%0A%09%09%09assertEquals(array.length(), list.size());%0A%09%09%09assertEquals(%22james%22, list.get(0));%0A%09%09%09assertEquals(%22bond%22, list.get(1));%0A%09%09%09%0A%09%09%7D catch (JSONException e) %7B%0A%09%09%09e.printStackTrace();%0A%09%09%7D%0A%09%09%0A%09%7D%0A%09%0A
 %09public 

Add tests for JsonArrayToList