Reland: Add jni_libs property to java tests

Add jni_libs property to java tests and treat it as test data that
should be copied to the lib or lib64 directory in the test directory.

This relands I3a118b933ab30dcd731c6dc2708da9bc63ab5520 with fixes for
the test on mac.

Fixes: 176593487
Test: java_test.go
Change-Id: I2f8c46643cff7a7ae6dc4d4dbad58f0396e45f09
diff --git a/java/java_test.go b/java/java_test.go
index 0523458..e7ea4ef 100644
--- a/java/java_test.go
+++ b/java/java_test.go
@@ -20,6 +20,7 @@
 	"path/filepath"
 	"reflect"
 	"regexp"
+	"runtime"
 	"strconv"
 	"strings"
 	"testing"
@@ -462,6 +463,38 @@
 	}
 }
 
+func TestTest(t *testing.T) {
+	ctx, _ := testJava(t, `
+		java_test_host {
+			name: "foo",
+			srcs: ["a.java"],
+			jni_libs: ["libjni"],
+		}
+
+		cc_library_shared {
+			name: "libjni",
+			host_supported: true,
+			device_supported: false,
+			stl: "none",
+		}
+	`)
+
+	buildOS := android.BuildOs.String()
+
+	foo := ctx.ModuleForTests("foo", buildOS+"_common").Module().(*TestHost)
+
+	expected := "lib64/libjni.so"
+	if runtime.GOOS == "darwin" {
+		expected = "lib64/libjni.dylib"
+	}
+
+	fooTestData := foo.data
+	if len(fooTestData) != 1 || fooTestData[0].Rel() != expected {
+		t.Errorf(`expected foo test data relative path [%q], got %q`,
+			expected, fooTestData.Strings())
+	}
+}
+
 func TestHostBinaryNoJavaDebugInfoOverride(t *testing.T) {
 	bp := `
 		java_library {