Build a junit4-target library.

Bug 5826326

Change-Id: Iff8f25e2ab95f4eb4cfaaff215f7d608c9ae6fa6
diff --git a/Android.mk b/Android.mk
index b936a7d..1de665c 100644
--- a/Android.mk
+++ b/Android.mk
@@ -70,3 +70,32 @@
 
 endif
 
+#-------------------------------------------------------
+# build a junit4-target jar representing the
+# classes in external/junit that are not in the core public API 4
+# Note: 'core' here means excluding the classes that are contained
+# in the optional library android.test.runner. Developers who
+# build against this jar shouldn't have to also include android.test.runner
+
+include $(CLEAR_VARS)
+
+LOCAL_SRC_FILES := $(call all-java-files-under, src/org)
+LOCAL_SRC_FILES += $(call all-java-files-under, src/junit/extensions)
+LOCAL_SRC_FILES += $(call all-java-files-under, src/junit/runner)
+LOCAL_SRC_FILES += $(call all-java-files-under, src/junit/textui)
+LOCAL_SRC_FILES += \
+	src/junit/framework/ComparisonCompactor.java \
+	src/junit/framework/JUnit4TestAdapterCache.java \
+	src/junit/framework/JUnit4TestAdapter.java \
+	src/junit/framework/JUnit4TestCaseFacade.java
+
+LOCAL_MODULE := junit4-target
+LOCAL_MODULE_TAGS := optional
+LOCAL_SDK_VERSION := 4
+LOCAL_STATIC_JAVA_LIBRARIES := hamcrest
+include $(BUILD_STATIC_JAVA_LIBRARY)
+
+
+
+
+
diff --git a/src/junit/framework/ComparisonCompactor.java b/src/junit/framework/ComparisonCompactor.java
index 24ad42f..e540f03 100644
--- a/src/junit/framework/ComparisonCompactor.java
+++ b/src/junit/framework/ComparisonCompactor.java
@@ -23,14 +23,17 @@
 	}
 
 	public String compact(String message) {
-		if (fExpected == null || fActual == null || areStringsEqual())
-			return Assert.format(message, fExpected, fActual);
-
+		if (fExpected == null || fActual == null || areStringsEqual()) {
+			// android-changed use local method instead of Assert.format, since
+			// the later is not part of Android API till API 16
+			return format(message, fExpected, fActual);
+		}
 		findCommonPrefix();
 		findCommonSuffix();
 		String expected= compactString(fExpected);
 		String actual= compactString(fActual);
-		return Assert.format(message, expected, actual);
+		// android-changed use local format method
+		return format(message, expected, actual);
 	}
 
 	private String compactString(String source) {
@@ -73,4 +76,12 @@
 	private boolean areStringsEqual() {
 		return fExpected.equals(fActual);
 	}
+
+	// android-changed copy of Assert.format for reasons described above
+	private static String format(String message, Object expected, Object actual) {
+        	String formatted= "";
+        	if (message != null && message.length() > 0)
+            		formatted= message+" ";
+        	return formatted+"expected:<"+expected+"> but was:<"+actual+">";
+	}
 }