aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test/java/com/google/devtools/build/lib
diff options
context:
space:
mode:
authorGravatar Googler <noreply@google.com>2016-05-20 21:57:56 +0000
committerGravatar Yue Gan <yueg@google.com>2016-05-23 08:24:57 +0000
commita3d40da13395cb728604b0989d9472311db9a6a2 (patch)
tree63e60ce9427813e99edae647972880d47ce87090 /src/test/java/com/google/devtools/build/lib
parentf2652b2048947eb614829876051b27f1a753bd06 (diff)
Roll forward just the new unit test from commit 8375185ee11d573562f98de14bed79a77fcfd728 that applies to
already-existing code. -- MOS_MIGRATED_REVID=122869862
Diffstat (limited to 'src/test/java/com/google/devtools/build/lib')
-rw-r--r--src/test/java/com/google/devtools/build/lib/rules/java/JavaUtilTest.java78
1 files changed, 78 insertions, 0 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/rules/java/JavaUtilTest.java b/src/test/java/com/google/devtools/build/lib/rules/java/JavaUtilTest.java
new file mode 100644
index 0000000000..e93453c0b1
--- /dev/null
+++ b/src/test/java/com/google/devtools/build/lib/rules/java/JavaUtilTest.java
@@ -0,0 +1,78 @@
+// Copyright 2015 The Bazel Authors. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package com.google.devtools.build.lib.rules.java;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import com.google.devtools.build.lib.vfs.PathFragment;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+/**
+ * Tests for {@link JavaUtil} methods.
+ */
+@RunWith(JUnit4.class)
+public class JavaUtilTest {
+
+ private String getRootPath(String path) {
+ return JavaUtil.getJavaRoot(new PathFragment(path)).getPathString();
+ }
+
+ @Test
+ public void testGetJavaRoot() {
+ assertThat(
+ JavaUtil.getJavaRoot(new PathFragment("path/without/Java/or/Javatests/or/Src/lowercase")))
+ .isNull();
+ assertThat(getRootPath("java/com/google/common/case")).isEqualTo("java");
+ assertThat(getRootPath("javatests/com/google/common/case")).isEqualTo("javatests");
+ assertThat(getRootPath("project/java")).isEqualTo("project/java");
+ assertThat(getRootPath("project/java/anything")).isEqualTo("project/java");
+ assertThat(getRootPath("project/javatests")).isEqualTo("project/javatests");
+ assertThat(getRootPath("project/javatests/anything")).isEqualTo("project/javatests");
+ assertThat(getRootPath("third_party/java_src/project/src/main/java/foo"))
+ .isEqualTo("third_party/java_src/project/src/main/java");
+ assertThat(getRootPath("third_party/java_src/project/src/test/java/foo"))
+ .isEqualTo("third_party/java_src/project/src/test/java");
+ assertThat(getRootPath("third_party/java_src/project/javatests/foo"))
+ .isEqualTo("third_party/java_src/project/javatests");
+ }
+
+ @Test
+ public void testGetJavaPackageName() {
+ assertThat(JavaUtil.getJavaPackageName(new PathFragment("java/com/google/foo/FooModule.java")))
+ .isEqualTo("com.google.foo");
+ assertThat(JavaUtil.getJavaPackageName(new PathFragment("org/foo/FooUtil.java")))
+ .isEqualTo("org.foo");
+ }
+
+ @Test
+ public void testGetJavaFullClassname() {
+ assertThat(
+ JavaUtil.getJavaFullClassname(new PathFragment("java/com/google/foo/FooModule.java")))
+ .isEqualTo("com.google.foo.FooModule.java");
+ assertThat(JavaUtil.getJavaFullClassname(new PathFragment("org/foo/FooUtil.java"))).isNull();
+ }
+
+ @Test
+ public void testGetJavaPath() {
+ assertThat(
+ JavaUtil.getJavaPath(
+ new PathFragment("java/com/google/foo/FooModule.java")).getPathString())
+ .isEqualTo("com/google/foo/FooModule.java");
+ assertThat(JavaUtil.getJavaPath(new PathFragment("org/foo/FooUtil.java"))).isNull();
+ }
+}