package com.tandogan.android.xingsync.api;

import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsEqual.equalTo;
import static org.hamcrest.core.IsNull.notNullValue;
import static org.junit.Assert.assertThat;

import java.io.IOException;

import org.apache.commons.io.Charsets;
import org.apache.commons.io.IOUtils;
import org.json.JSONException;
import org.json.JSONObject;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

import android.provider.ContactsContract;

@RunWith(JUnit4.class)
public class ContactTest
{
	private JSONObject json;

	@Before
	public void populateJson() throws JSONException, IOException
	{
		// JSON is fetched from logcat and reformatted with
		// http://jsonformatter.curiousconcept.com/

		String data = IOUtils.toString(getClass().getResourceAsStream("ContactTest.json"), Charsets.UTF_8);

		JSONObject actual = new JSONObject(data);
		assertThat("JSON object could not be created", actual, is(notNullValue()));

		json = actual;
	}

	@Test
	public void parseMeCall() throws JSONException
	{
		Contact actual = Contact.fromJSON(json);
		assertThat("User could not be created", actual, is(notNullValue()));
		assertThat("Id not correctly parsed", actual.getId(), is("3382304"));
		assertThat("First Name not correctly parsed", actual.getFirstName(), is("Hakan"));
		assertThat("Last Name not correctly parsed", actual.getLastName(), is("Tandogan"));
		assertThat("Display Name not correctly parsed", actual.getDisplayName(), is("Hakan Tandogan"));
	}

	@Test
	public void data() throws JSONException
	{
		Contact actual = Contact.fromJSON(json);
		assertThat("User could not be created", actual, is(notNullValue()));

		actual.setData(ContactsContract.CommonDataKinds.Email.ADDRESS, "someone@somewhere.com");
		assertThat("Email Address could not be set", actual.getData(ContactsContract.CommonDataKinds.Email.ADDRESS),
		        is(equalTo("someone@somewhere.com")));
	}
}

@@ -41,47 +41,8 @@
 i;%0A%0A
-import static org.hamcrest.core.Is.is;%0A
 impo
@@ -86,16 +86,16 @@
 qualTo;%0A
+
 import s
@@ -954,35 +954,32 @@
 eated%22, actual, 
-is(
 notNullValue()))
@@ -973,25 +973,24 @@
 NullValue())
-)
 ;%0A%0A%09%09json = 
@@ -1144,35 +1144,32 @@
 eated%22, actual, 
-is(
 notNullValue()))
@@ -1167,17 +1167,16 @@
 Value())
-)
 ;%0A%09%09asse
@@ -1225,18 +1225,23 @@
 etId(), 
-is
+equalTo
 (%22338230
@@ -1313,26 +1313,31 @@
 irstName(), 
-is
+equalTo
 (%22Hakan%22));%0A
@@ -1405,18 +1405,23 @@
 Name(), 
-is
+equalTo
 (%22Tandog
@@ -1502,18 +1502,23 @@
 Name(), 
-is
+equalTo
 (%22Hakan 
@@ -1678,19 +1678,16 @@
 actual, 
-is(
 notNullV
@@ -1693,17 +1693,16 @@
 Value())
-)
 ;%0A%0A%09%09act
@@ -1898,16 +1898,16 @@
 DRESS),%0A
+
 %09%09      
@@ -1908,18 +1908,16 @@
         
-is
 (equalTo

Remove deprecated 'is' matcher