/**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 sortByScore use case
	 * @return	void
	 */
	public void sortByScoreTest() {
		// 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);
	}
	
	/**
	 * Test AddFavorite use case
	 * @ return void
	 */
	public void addFavoriteTest() {
		// For the actual test, this topic needs to be populated.
		TopicModel topic = new TopicModel();
		UserModel user = new UserModel();
		
		user.setName("bob");
		
		// Bob is going to favorite the parent thread
		user.addFavoriteThread(topic.getThreads().get(0));

		assertEqual("Users most recent favorite should be the same as the thread",
				user.getFavorites().getLast(), topic.getThreads().get(0));
	}
}

@@ -1,12 +1,11 @@
 /**
-a
 %0A * @aut
@@ -2562,25 +2562,24 @@
 before%0A%09 * @
- 
 return%09void%0A
@@ -2570,32 +2570,32 @@
  * @return%09void%0A
+
 %09 */%0A%09public voi
@@ -3076,17 +3076,16 @@
 se%0A%09 * @
- 
 return v
@@ -3469,16 +3469,16 @@
 hread%22,%0A
-
 %09%09%09%09user
@@ -3535,10 +3535,874 @@
 0));%0A%09%7D%0A
+%09%0A%09/**%0A%09 * Test EditComment use case%0A%09 * @return void %0A%09 */%0A%09public void editCommentTest() %7B%0A%09%09// Initial test is the same as addTopLevelCommentTest()%0A%09%09TopicModel topic = new TopicModel();%0A%09%09ThreadModel thread = new ThreadModel();%0A%09%09UserModel user = new UserModel();%0A%09%09%0A%09%09// TODO Maybe have a helper class so we aren't creating a new user for each Test.%0A%09%09user.setName(%22Bob%22);%0A%09%09%0A%09%09thread.setComment(%22This is my comment%22);%0A%09%09thread.setLocation();%0A%09%09thread.setAuthor(CommentAuthor author = new CommentAuthor(user));%0A%09%09topic.addThread(thread);%0A%09%09%0A%09%09assertTrue(%22Comment is top level for edit comment%22, topic.threads.contains(thread));%0A%09%09%0A%09%09thread = topic.getThreads().getLast();%0A%09%09thread.setComment(%22Updated comment%22);%0A%09%09%09%09%0A%09%09assertEquals(%22Edited thread should represent the new comment%22,%0A%09%09%09%09%22updated comment%22,%0A%09%09%09%09topic.getThreads().getLast().getComment());%0A%09%09%0A%09%7D%0A
 %7D%0A

Edit Comment Test Case