Fix buck test in standalone BUCK build

Change-Id: I12df8adba2fde44fc29feb38af195e6d1b6b20a6
diff --git a/BUCK b/BUCK
index e0ae59e..26aafae 100644
--- a/BUCK
+++ b/BUCK
@@ -1,5 +1,17 @@
 include_defs('//bucklets/gerrit_plugin.bucklet')
 
+if STANDALONE_MODE:
+  TEST_DEPS = GERRIT_PLUGIN_API
+else:
+  TEST_DEPS = [
+    '//gerrit-common:server',
+    '//gerrit-reviewdb:server',
+    '//gerrit-server:server',
+    '//lib/jgit:jgit',
+    '//lib:guava',
+    '//lib:gwtorm',
+   ]
+
 gerrit_plugin(
   name = 'ref-protection',
   srcs = glob(['src/main/java/**/*.java']),
@@ -20,15 +32,10 @@
 java_test(
   name = 'ref-protection_tests',
   srcs = glob(['src/test/java/**/*.java']),
-  deps = [
+  labels = ['ref-protection'],
+  deps = TEST_DEPS + [
     ':ref-protection__plugin',
-    '//gerrit-common:server',
-    '//gerrit-reviewdb:server',
-    '//gerrit-server:server',
-    '//lib:guava',
-    '//lib:gwtorm',
     '//lib:junit',
     '//lib:truth',
-    '//lib/jgit:jgit',
   ],
 )
diff --git a/lib/BUCK b/lib/BUCK
new file mode 100644
index 0000000..f501067
--- /dev/null
+++ b/lib/BUCK
@@ -0,0 +1,27 @@
+include_defs('//bucklets/maven_jar.bucklet')
+
+maven_jar(
+  name = 'junit',
+  id = 'junit:junit:4.10',
+  sha1 = 'e4f1766ce7404a08f45d859fb9c226fc9e41a861',
+  license = 'DO_NOT_DISTRIBUTE',
+  deps = [':hamcrest-core'],
+)
+
+maven_jar(
+  name = 'hamcrest-core',
+  id = 'org.hamcrest:hamcrest-core:1.3',
+  sha1 = '42a25dc3219429f0e5d060061f71acb49bf010a0',
+  license = 'DO_NOT_DISTRIBUTE',
+  visibility = ['//lib:junit'],
+)
+
+maven_jar(
+  name = 'truth',
+  id = 'com.google.truth:truth:0.26',
+  sha1 = 'b5802815625d82f39c33219299771f3d64301b06',
+  license = 'DO_NOT_DISTRIBUTE',
+  deps = [
+    ':junit',
+  ],
+)
diff --git a/src/main/resources/Documentation/build.md b/src/main/resources/Documentation/build.md
index 4c31765..c1ea124 100644
--- a/src/main/resources/Documentation/build.md
+++ b/src/main/resources/Documentation/build.md
@@ -36,7 +36,6 @@
 
 To build the plugin, issue the following command:
 
-
 ```
   buck build plugin
 ```
@@ -47,6 +46,12 @@
   buck-out/gen/ref-protection.jar
 ```
 
+To run unit tests, issue the following command:
+
+```
+  buck test
+```
+
 Build in Gerrit tree
 --------------------
 
@@ -69,5 +74,11 @@
   ./tools/eclipse/project.py
 ```
 
+To run the unit tests and restrict to run only the tests from this plugin:
+
+```
+  buck test --include ref-protection
+```
+
 How to build the Gerrit Plugin API is described in the [Gerrit
 documentation](../../../Documentation/dev-buck.html#_extension_and_plugin_api_jar_files).