diff test/org/tmatesoft/hg/test/TestStorePath.java @ 101:777ab7034c1b

Switch to JUnit for tests
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Fri, 28 Jan 2011 03:07:25 +0100
parents a5275143664c
children a3a2e5deb320
line wrap: on
line diff
--- a/test/org/tmatesoft/hg/test/TestStorePath.java	Fri Jan 28 02:15:12 2011 +0100
+++ b/test/org/tmatesoft/hg/test/TestStorePath.java	Fri Jan 28 03:07:25 2011 +0100
@@ -16,6 +16,11 @@
  */
 package org.tmatesoft.hg.test;
 
+import static org.hamcrest.CoreMatchers.equalTo;
+import junit.framework.Assert;
+
+import org.junit.Rule;
+import org.junit.Test;
 import org.tmatesoft.hg.internal.Internals;
 import org.tmatesoft.hg.util.PathRewrite;
 
@@ -26,12 +31,16 @@
  */
 public class TestStorePath {
 	
+	@Rule
+	public ErrorCollectorExt errorCollector = new ErrorCollectorExt();
+	
 	private PathRewrite storePathHelper;
 
-	public static void main(String[] args) {
+	public static void main(String[] args) throws Throwable {
 		final TestStorePath test = new TestStorePath();
 		test.testWindowsFilenames();
 		test.testHashLongPath();
+		test.errorCollector.verify();
 	}
 	
 	public TestStorePath() {
@@ -40,13 +49,15 @@
 		storePathHelper = i.buildDataFilesHelper();
 	}
 
+	@Test
 	public void testWindowsFilenames() {
 		// see http://mercurial.selenic.com/wiki/fncacheRepoFormat#Encoding_of_Windows_reserved_names
 		String n1 = "aux.bla/bla.aux/prn/PRN/lpt/com3/nul/coma/foo.NUL/normal.c";
 		String r1 = "store/data/au~78.bla/bla.aux/pr~6e/_p_r_n/lpt/co~6d3/nu~6c/coma/foo._n_u_l/normal.c.i";
-		report("Windows filenames are ", n1, r1);
+		Assert.assertEquals("Windows filenames are ", r1, storePathHelper.rewrite(n1));
 	}
 
+	@Test
 	public void testHashLongPath() {
 		String n1 = "AUX/SECOND/X.PRN/FOURTH/FI:FTH/SIXTH/SEVENTH/EIGHTH/NINETH/TENTH/ELEVENTH/LOREMIPSUM.TXT";
 		String r1 = "store/dh/au~78/second/x.prn/fourth/fi~3afth/sixth/seventh/eighth/nineth/tenth/loremia20419e358ddff1bf8751e38288aff1d7c32ec05.i";
@@ -55,18 +66,8 @@
 		String n3 = "AUX.THE-QUICK-BROWN-FOX-JU:MPS-OVER-THE-LAZY-DOG-THE-QUICK-BROWN-FOX-JUMPS-OVER-THE-LAZY-DOG.TXT";
 		String r3 = "store/dh/au~78.the-quick-brown-fox-ju~3amps-over-the-lazy-dog-the-quick-brown-fox-jud4dcadd033000ab2b26eb66bae1906bcb15d4a70.i";
 		// TODO segment[8] == [. ], segment[8] in the middle of windows reserved name or character (to see if ~xx is broken)
-		report("1", n1, r1);
-		report("2", n2, r2);
-		report("3", n3, r3);
-	}
-
-	private void report(String msg, String name, String expected) {
-		String res = check(name, expected);
-		System.out.println(msg + (res == null ? "OK" : "WRONG:" + res));
-	}
-
-	private String check(String name, String expected) {
-		String result = storePathHelper.rewrite(name);
-		return expected.equals(result) ? null : result;
+		errorCollector.checkThat(storePathHelper.rewrite(n1), equalTo(r1));
+		errorCollector.checkThat(storePathHelper.rewrite(n2), equalTo(r2));
+		errorCollector.checkThat(storePathHelper.rewrite(n3), equalTo(r3));
 	}
 }