src/test/java/org/jenkinsci/plugins/pretestedintegrationmercurial/MercurialTest.java
public void testShouldCommitChanges() throws Exception {
		setup();
		File dir = createTempDirectory();
		System.out.println("Creating test repository at repository: " + dir.getAbsolutePath());
		
		MercurialBridge plugin = new MercurialBridge(false,"test","default");
		plugin.setWorkingDirectory(new FilePath(dir));
		
		hg(dir, "init");
		shell(dir,"touch","foo");
		hg(dir, "add","foo");
		hg(dir, "commit","-m","added foo");
		hg(dir, "branch","test");
		String revision = hg(dir,"tip","--template","{node}").toString();
		shell(dir,"touch","bar");
		hg(dir, "add","bar");
		hg(dir, "commit","-m","added bar");
		hg(dir, "update","default");
		hg(dir, "merge","test");
		
		MercurialSCM scm = new MercurialSCM(null,dir.getAbsolutePath(),"test",null,null,null, true);
		FreeStyleProject project = Hudson.getInstance().createProject(FreeStyleProject.class, "testproject");
		project.setScm(scm);

		Future<FreeStyleBuild> b = project.scheduleBuild2(0);
		FreeStyleBuild build = spy(b.get());
		when(build.getResult()).thenReturn(Result.SUCCESS);


		OutputStream out = new ByteArrayOutputStream();
		BuildListener bListener = new StreamBuildListener(out);
		assertTrue(hg(dir,"branch").toString().startsWith("default"));
		assertTrue(hg(dir,"status").toString().startsWith("M bar"));
		assertNotNull(build.getResult());
		
		plugin.nextCommit(build, launcher, bListener, null);
		
		plugin.handlePostBuild(build, launcher, bListener);
		
		assertTrue(hg(dir,"branch").toString().startsWith("default"));
		assertTrue(hg(dir,"status").toString().isEmpty());
		
		assertTrue(hg(dir,"log","-rtip","--template","{desc}").
				toString()
				.startsWith("Merge of revision"));

		cleanup(dir);
	}
/**
	 * Given that there are uncomitted changes in the integration branch
	 * And that the build is marked successful
	 * When handlePostBuild has been invoked
	 * Then there should be no more changes on the integration branch
	 * And the integration branch has a new commit with the changes
	 * @throws Exception
	 */
Given that there are uncomitted changes in the integration branch
And that the build is marked successful
When handlePostBuild has been invoked
Then there should be no more changes on the integration branch
And the integration branch has a new commit with the changes
@throws Exception
Given that there are uncomitted changes in the integration branch And that the build is marked successful When handlePostBuild has been invoked Then there should be no more changes on the integration branch And the integration branch has a new commit with the changes @throws Exception
public void testShouldCommitChanges() throws Exception {
		setup();
		File dir = createTempDirectory();
		System.out.println("Creating test repository at repository: " + dir.getAbsolutePath());
		MercurialBridge plugin = new MercurialBridge(false,"test","default");
		plugin.setWorkingDirectory(new FilePath(dir));
		hg(dir, "init");
		shell(dir,"touch","foo");
		hg(dir, "add","foo");
		hg(dir, "commit","-m","added foo");
		hg(dir, "branch","test");
		String revision = hg(dir,"tip","--template","{node}").toString();
		shell(dir,"touch","bar");
		hg(dir, "add","bar");
		hg(dir, "commit","-m","added bar");
		hg(dir, "update","default");
		hg(dir, "merge","test");
		MercurialSCM scm = new MercurialSCM(null,dir.getAbsolutePath(),"test",null,null,null, true);
		FreeStyleProject project = Hudson.getInstance().createProject(FreeStyleProject.class, "testproject");
		project.setScm(scm);
		Future<FreeStyleBuild> b = project.scheduleBuild2(0);
		FreeStyleBuild build = spy(b.get());
		when(build.getResult()).thenReturn(Result.SUCCESS);
		OutputStream out = new ByteArrayOutputStream();
		BuildListener bListener = new StreamBuildListener(out);
		assertTrue(hg(dir,"branch").toString().startsWith("default"));
		assertTrue(hg(dir,"status").toString().startsWith("M bar"));
		assertNotNull(build.getResult());
		plugin.nextCommit(build, launcher, bListener, null);
		plugin.handlePostBuild(build, launcher, bListener);
		assertTrue(hg(dir,"branch").toString().startsWith("default"));
		assertTrue(hg(dir,"status").toString().isEmpty());
		assertTrue(hg(dir,"log","-rtip","--template","{desc}").
				toString()
				.startsWith("Merge of revision"));
		cleanup(dir);
	}
public void testShouldCommitChanges ( ) throws Exception { setup ( ) ; File dir = createTempDirectory ( ) ; System . out . println ( "Creating test repository at repository: " + dir . getAbsolutePath ( ) ) ; MercurialBridge plugin = new MercurialBridge ( false , "test" , "default" ) ; plugin . setWorkingDirectory ( new FilePath ( dir ) ) ; hg ( dir , "init" ) ; shell ( dir , "touch" , "foo" ) ; hg ( dir , "add" , "foo" ) ; hg ( dir , "commit" , "-m" , "added foo" ) ; hg ( dir , "branch" , "test" ) ; String revision = hg ( dir , "tip" , "--template" , "{node}" ) . toString ( ) ; shell ( dir , "touch" , "bar" ) ; hg ( dir , "add" , "bar" ) ; hg ( dir , "commit" , "-m" , "added bar" ) ; hg ( dir , "update" , "default" ) ; hg ( dir , "merge" , "test" ) ; MercurialSCM scm = new MercurialSCM ( null , dir . getAbsolutePath ( ) , "test" , null , null , null , true ) ; FreeStyleProject project = Hudson . getInstance ( ) . createProject ( FreeStyleProject . class , "testproject" ) ; project . setScm ( scm ) ; Future < FreeStyleBuild > b = project . scheduleBuild2 ( 0 ) ; FreeStyleBuild build = spy ( b . get ( ) ) ; when ( build . getResult ( ) ) . thenReturn ( Result . SUCCESS ) ; OutputStream out = new ByteArrayOutputStream ( ) ; BuildListener bListener = new StreamBuildListener ( out ) ; assertTrue ( hg ( dir , "branch" ) . toString ( ) . startsWith ( "default" ) ) ; assertTrue ( hg ( dir , "status" ) . toString ( ) . startsWith ( "M bar" ) ) ; assertNotNull ( build . getResult ( ) ) ; plugin . nextCommit ( build , launcher , bListener , null ) ; plugin . handlePostBuild ( build , launcher , bListener ) ; assertTrue ( hg ( dir , "branch" ) . toString ( ) . startsWith ( "default" ) ) ; assertTrue ( hg ( dir , "status" ) . toString ( ) . isEmpty ( ) ) ; assertTrue ( hg ( dir , "log" , "-rtip" , "--template" , "{desc}" ) . toString ( ) . startsWith ( "Merge of revision" ) ) ; cleanup ( dir ) ; }
Given that there are uncomitted changes in the integration branch
 And that the build is marked successful
 When handlePostBuild has been invoked
 Then there should be no more changes on the integration branch
 And the integration branch has a new commit with the changes
 @throws Exception
Given that there are uncomitted changes in the integration branch And that the build is marked successful When handlePostBuild has been invoked Then there should be no more changes on the integration branch And the integration branch has a new commit with the changes @throws Exception