/*******************************************************************************
 * Copyright (C) 2012, Maik Schreiber <blizzy@blizzy.de>
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *******************************************************************************/

package org.eclipse.egit.core.test.op;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import java.io.File;

import org.eclipse.egit.core.op.StashCreateOperation;
import org.eclipse.egit.core.test.GitTestCase;
import org.eclipse.egit.core.test.TestRepository;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.revwalk.RevWalk;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

public class StashCreateOperationTest extends GitTestCase {

	TestRepository testRepository;

	Repository repository;

	@Before
	public void setUp() throws Exception {
		super.setUp();
		gitDir = new File(project.getProject()
				.getLocationURI().getPath(), Constants.DOT_GIT);
		testRepository = new TestRepository(gitDir);
		repository = testRepository.getRepository();
		testRepository.connect(project.getProject());
		testRepository.commit("initial commit");
	}

	@After
	public void tearDown() throws Exception {
		testRepository.dispose();
		repository = null;
		super.tearDown();
	}

	@Test
	public void testDefaultMessage() throws Exception {
		testUtils.addFileToProject(project.getProject(), "foo/a.txt", "some text");
		StashCreateOperation stashCreateOperation = new StashCreateOperation(repository);
		stashCreateOperation.execute(null);

		RevWalk revWalk = new RevWalk(repository);
		RevCommit commit = revWalk.parseCommit(repository.resolve("stash@{0}"));
		assertTrue(commit.getFullMessage().length() > 0);
	}

	@Test
	public void testCustomMessage() throws Exception {
		testUtils.addFileToProject(project.getProject(), "foo/a.txt", "some text");
		String message = "stash message";
		StashCreateOperation stashCreateOperation = new StashCreateOperation(repository, message);
		stashCreateOperation.execute(null);

		RevWalk revWalk = new RevWalk(repository);
		RevCommit commit = revWalk.parseCommit(repository.resolve("stash@{0}"));
		assertEquals(message, commit.getFullMessage());
	}

}

@@ -96,16 +96,21 @@
 C) 2012,
+ 2013
  Maik Sc
@@ -135,16 +135,28 @@
 izzy.de%3E
+ and others.
 %0A *%0A * A
@@ -630,16 +630,135 @@
 o.File;%0A
+import java.util.Arrays;%0A%0Aimport org.eclipse.core.resources.IFile;%0Aimport org.eclipse.egit.core.op.AddToIndexOperation;
 %0Aimport 
@@ -1783,32 +1783,45 @@
 s Exception %7B%0A%09%09
+IFile file = 
 testUtils.addFil
@@ -1844,33 +1844,37 @@
 ct.getProject(),
- 
+%0A%09%09%09%09
 %22foo/a.txt%22, %22so
@@ -1880,24 +1880,86 @@
 ome text%22);%0A
+%09%09new AddToIndexOperation(Arrays.asList(file)).execute(null);%0A
 %09%09StashCreat
@@ -2302,24 +2302,37 @@
 ception %7B%0A%09%09
+IFile file = 
 testUtils.ad
@@ -2367,17 +2367,21 @@
 oject(),
- 
+%0A%09%09%09%09
 %22foo/a.t
@@ -2399,16 +2399,78 @@
 text%22);%0A
+%09%09new AddToIndexOperation(Arrays.asList(file)).execute(null);%0A
 %09%09String

Fix StashCreateOperationTest by adjusting test setup