/**a
 * @author	Michael Raypold
 */
package ca.ualberta.team7project.test;

import java.util.Date;

import ca.ualberta.team7project.MainActivity;
import android.content.Context;
import android.location.Location;
import android.location.LocationManager;
import android.test.ActivityInstrumentationTestCase2;

public class useCaseValidation extends
		ActivityInstrumentationTestCase2<MainActivity> {

	public useCaseValidation(Class<MainActivity> name) {
		super(name);
	}

	protected void setUp() throws Exception {
		super.setUp();
	}

	/**
	 * Test CreateIdentity use case
	 * @return	void
	 */
	public void createIdentityTest() {
		UserPersistenceModel user = new UserPersistenceMode();
		UserModel newUser = null;
		
		if(user.exists() == false) {
			newUser = new UserModel("Bob");
		}
		else {
			newUser = user.getUser();
		}
		
		assertNotNull("User should be created or already exist", newUser);
	}
	
	/**
	 * Test SetLocation use case
	 * @return	void
	 */
	public void setLocationTest() {
		UserPersistenceModel user = new UserPersistenceMode();
		UserModel newUser = user.getUser();

		// TODO https://developer.android.com/training/location/location-testing.html
		newUser.setCurrentLocation();
		
		assertNotNull("Users location should now be set", newUser.getCurrentLocation());
	}
	
	/**
	 * Test AddTopLevelComment use case
	 * @return	void
	 */
	public void addTopLevelCommentTest() {
		TopicModel topic = new TopicModel();
		ThreadModel thread = new ThreadModel();
		UserModel user = new UserModel();
		
		// TODO Maybe have a helper class so we aren't creating a new user for each Test.
		user.setName("Bob");
		
		thread.setComment("This is my comment");
		thread.setLocation();
		thread.setAuthor(CommentAuthor author = new CommentAuthor(user));
		topic.addThread(thread);
		
		assertTrue("Comment is top level", topic.threads.contains(thread));
	}
	
	/**
	 * Test sortByRelevance use case
	 * @return	void
	 */
	public void sortByRelevanceTest() {
		// For the actual test, this topic needs to be populated.
		TopicModel topic = new TopicModel();
		Boolean ordered = true;
		Integer lastScore = null;
		
		topic.sortThreadsByRelevance();
		lastScore = topic.threads.get(0).getVotes();
		
		for(Thread t : topic.getThreads()) {
			if(lastScore < t.getVotes()) {
				ordered = false;
				break;
			}
			
			lastScore = t.getVotes();
		}
	
		assertTrue("Comments should be ordered by vote count", ordered);
	}
	
	/**
	 * Test DefaultCommentOrder use case
	 * <p>
	 * Comments are ordered based off date by default if the user has never seen the topic before
	 * @ return	void
	 */
	public void defaultCommentOrderTest() {
		// For the actual test, this topic needs to be populated.
		TopicModel topic = new TopicModel();
		Boolean ordered = true;
		Date lastDate = null;
		
		lastDate = topic.threads.get(0).getDate();
		
		for(Thread t : topic.getThreads()) {
			if(lastDate.compareTo(t.getDate()) < 0 ) {
				ordered = false;
				break;
			}

			lastDate = t.getDate();
		}
		
		assertTrue("Threads ordered by date", ordered);
	}
	
}

@@ -92,17 +92,16 @@
 l.Date;%0A
-%0A
 import c
@@ -1884,24 +1884,20 @@
 t sortBy
-Relevanc
+Scor
 e use ca
@@ -1940,24 +1940,20 @@
 d sortBy
-Relevanc
+Scor
 eTest() 
@@ -2410,25 +2410,26 @@
 dered);%0A%09%7D%0A%09
+%09
 %0A
-
 %09/**%0A%09 * Tes
@@ -3036,12 +3036,512 @@
 ed);%0A%09%7D%0A
-
 %09%0A
+%09/**%0A%09 * Test AddFavorite use case%0A%09 * @ return void%0A%09 */%0A%09public void addFavoriteTest() %7B%0A%09%09// For the actual test, this topic needs to be populated.%0A%09%09TopicModel topic = new TopicModel();%0A%09%09UserModel user = new UserModel();%0A%09%09%0A%09%09user.setName(%22bob%22);%0A%09%09%0A%09%09// Bob is going to favorite the parent thread%0A%09%09user.addFavoriteThread(topic.getThreads().get(0));%0A%0A%09%09assertEqual(%22Users most recent favorite should be the same as the thread%22,%0A%09%09%09%09user.getFavorites().getLast(), topic.getThreads().get(0));%0A%09%7D%0A
 %7D%0A

Add Favorite Test Case