package ca.ualberta.cs.f14t07_application.test;

import ca.ualberta.cs.f14t07_application.ForumEntry;
import android.test.ActivityInstrumentationTestCase2;
import android.widget.Button;

/**
 * Test the fragment that displays options to up vote, down vote, or reply to an
 * answer or main question. The 'VoteAndReplyActivity' is the theoretical name for the 
 * activity class that will display these options. I am assuming that the options are
 * buttons.
 * 
 * The code in this test class has been heavily influenced by the android junit testing tutorial
 * provided at http://developer.android.com/tools/testing/activity_test.html
 * @author Brendan
 *
 */
/* TODO: More extensive tests of the chain of events that unfold when a button is pushed
 */
public class UpDownReplyTest extends ActivityInstrumentationTestCase2<VoteAndReplyActivity> {

	private VoteAndReplyActivity testActivity;
	private Button testButton;
	
	public UpDownReplyTest()
	{
		super(VoteAndReplyActivity.class);
	}
	
	@Override
	protected void setUp() throws Exception
	{
		super.setUp();
		
		/* Turns off the touch screen in the emulator. This must be done to test features that
		 * would require the user to touch something on the screen.
		 */
		setActivityInitialTouchMode(false);
		
		/* Get an instance of the activity which is running
		 */
		testActivity = getActivity();
		
		/* Reset the testButton - do this so consecutive tests don't accidentally test
		 * the same button.
		 */
		testButton = null;
	}
	
	/**
	 *Test upvoting a question
	 */
	public void upVoteQuestionTest()
	{
		setUp();
		ForumEntry TestEntry=ForumEntry();
		TestEntry.addAnswer(new Entry testEntry);
		upVoteButton = (Button) testActivity.findViewById(
					com.example.f14t07_application.activity_voteandreply.R.id.UpVoteQuestion);
		
		int initialValue=TestEntry.getQuestion().getUpVote();
		upVoteButton.performClick();
		int afterClick=TestEntry.getQuestion().getUpVote();
		assertTrue(initialValue,afterClick+1);
	}
	
	/**
	 * Test upvoting an answer
	 */
	public void downVoteTest()
	{
		upVoteButton = (Button) testActivity.findViewById(
				com.example.f14t07_application.activity_voteandreply.R.id.upVoteAnswer);
		
		assertTrue(testButton != null);
	}
	
	/**
	 * Tests that pushing the reply button will trigger a chain of events which
	 * results in the particular answer / main question having a reply logged.
	 * 
	 * This test assumes the name of the reply button and activity.xml it is in
	 */
	public void replyTest()
	{
		testButton = (Button) testActivity.findViewById(
				com.example.f14t07_application.activity_voteandreply.R.id.ReplyToForumPost);
	
		assertTrue(testButton != null);
	}
}

@@ -1579,16 +1579,839 @@
 Up();%0A%09%09
+String question = %22This is the question%22;%0A%09%09String author = %22This is the author%22;%0A%09%09ForumEntry testEntry = new ForumEntry(question, author);%0A%09%09int initialVote = testEntry.getQuestion().getUpVote();%0A%09%09DataManager dataM = new DataManager();%0A%09%09%0A%09%09testActivity.forumEntryController.addForumEntry(testEntry);%0A%09%09%0A%09%09Button upVoteButton = (Button) testActivity.findViewById(%0A%09%09%09%09%09com.example.f14t07_application.activity_voteandreply.R.id.UpVoteQuestion);%0A%09%09upVoteButton.performClick();%0A%09%09%0A%09%09ArrayList%3CForumEntry%3E testList = dataM.load();%0A%09%09Iterator iter = testList.iterator();%0A%09%09while(iter.hasNext())%0A%09%09%7B%0A%09%09%09ForumEntry temp = iter.next();%0A%09%09%09if(temp.getQuestion().getAuthorsName() == author && temp.getQuestion().getPost() == question)%0A%09%09%09%7B%0A%09%09%09%09assertTrue(temp.getQuestion().getUpVote(), initialVote+1);%0A%09%09%09%09break;%0A%09%09%09%7D%0A%09%09%7D%0A%09%09%0A%09%09/*
 ForumEnt
@@ -2798,16 +2798,18 @@
 lick+1);
+*/
 %0A%09%7D%0A%09%0A%09/

Update UpDownReplyTest.java