src/test/java/org/jenkinsci/plugins/pretestedintegrationmercurial/MercurialTest.java
public void testShouldRevertChanges() throws Exception {
		setup();
		File dir = createTempDirectory();
		System.out.println("Creating test repository at repository: " + dir.getAbsolutePath());
		
		MercurialBridge plugin = new MercurialBridge(false,"test","");
		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");
		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(),null,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.UNSTABLE);
		assertNotNull(build);
		
		String head = hg(dir,"tip","--template","{node}").toString();
		

		OutputStream out = new ByteArrayOutputStream();
		BuildListener blistener = new StreamBuildListener(out);
		
		assertTrue(hg(dir,"branch").toString().startsWith("default"));
		assertTrue(hg(dir,"status").toString().startsWith("M bar"));
		
		plugin.handlePostBuild(build, launcher, blistener);
		
		assertTrue(hg(dir,"branch").toString().startsWith("default"));
		assertTrue(hg(dir,"status").toString().isEmpty());
		assertTrue(hg(dir,"tip","--template","{node}").
				toString().equals(head));
		cleanup(dir);
	}
/**
	 * Given that there are uncomitted changes in the integration branch
	 * And that the build is marked unsuccessful
	 * When handlePostBuild has been invoked
	 * Then the changes should no longer exist in the working tree
	 * And the history of the integation branch should be unchanged
	 * @param launcher
	 * @return
	 */
Given that there are uncomitted changes in the integration branch
And that the build is marked unsuccessful
When handlePostBuild has been invoked
Then the changes should no longer exist in the working tree
And the history of the integation branch should be unchanged
@param launcher
@return
Given that there are uncomitted changes in the integration branch And that the build is marked unsuccessful When handlePostBuild has been invoked Then the changes should no longer exist in the working tree And the history of the integation branch should be unchanged @param launcher @return
public void testShouldRevertChanges() throws Exception {
		setup();
		File dir = createTempDirectory();
		System.out.println("Creating test repository at repository: " + dir.getAbsolutePath());
		MercurialBridge plugin = new MercurialBridge(false,"test","");
		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");
		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(),null,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.UNSTABLE);
		assertNotNull(build);
		String head = hg(dir,"tip","--template","{node}").toString();
		OutputStream out = new ByteArrayOutputStream();
		BuildListener blistener = new StreamBuildListener(out);
		assertTrue(hg(dir,"branch").toString().startsWith("default"));
		assertTrue(hg(dir,"status").toString().startsWith("M bar"));
		plugin.handlePostBuild(build, launcher, blistener);
		assertTrue(hg(dir,"branch").toString().startsWith("default"));
		assertTrue(hg(dir,"status").toString().isEmpty());
		assertTrue(hg(dir,"tip","--template","{node}").
				toString().equals(head));
		cleanup(dir);
	}
public void testShouldRevertChanges ( ) throws Exception { setup ( ) ; File dir = createTempDirectory ( ) ; System . out . println ( "Creating test repository at repository: " + dir . getAbsolutePath ( ) ) ; MercurialBridge plugin = new MercurialBridge ( false , "test" , "" ) ; 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" ) ; 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 ( ) , null , 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 . UNSTABLE ) ; assertNotNull ( build ) ; String head = hg ( dir , "tip" , "--template" , "{node}" ) . toString ( ) ; OutputStream out = new ByteArrayOutputStream ( ) ; BuildListener blistener = new StreamBuildListener ( out ) ; assertTrue ( hg ( dir , "branch" ) . toString ( ) . startsWith ( "default" ) ) ; assertTrue ( hg ( dir , "status" ) . toString ( ) . startsWith ( "M bar" ) ) ; plugin . handlePostBuild ( build , launcher , blistener ) ; assertTrue ( hg ( dir , "branch" ) . toString ( ) . startsWith ( "default" ) ) ; assertTrue ( hg ( dir , "status" ) . toString ( ) . isEmpty ( ) ) ; assertTrue ( hg ( dir , "tip" , "--template" , "{node}" ) . toString ( ) . equals ( head ) ) ; cleanup ( dir ) ; }
Given that there are uncomitted changes in the integration branch
 And that the build is marked unsuccessful
 When handlePostBuild has been invoked
 Then the changes should no longer exist in the working tree
 And the history of the integation branch should be unchanged
 @param launcher
 @return
Given that there are uncomitted changes in the integration branch And that the build is marked unsuccessful When handlePostBuild has been invoked Then the changes should no longer exist in the working tree And the history of the integation branch should be unchanged @param launcher @return