Refactor MarkdownToHtml with Builder pattern

This refactoring simplifies how we access information about the
document being rendered, which makes the navbar.md, README.md and
normal markdown files all more consistent.

MarkdownConfig is now a JGit SectionParser managed object, which
allows caching the immutable MarkdownConfig inside the JGit Config.
This consolidates the key references from all over the code to one
location, and may improve performance for servers that reuse the
Config object across requests.

Change-Id: Id85130d1bc7351f125bf3b0f8bf3c6e028272b30
diff --git a/gitiles-servlet/src/test/java/com/google/gitiles/doc/PathResolverTest.java b/gitiles-servlet/src/test/java/com/google/gitiles/doc/PathResolverTest.java
new file mode 100644
index 0000000..d788f43
--- /dev/null
+++ b/gitiles-servlet/src/test/java/com/google/gitiles/doc/PathResolverTest.java
@@ -0,0 +1,41 @@
+// Copyright (C) 2016 The Android Open Source Project
+//
+// 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.gitiles.doc;
+
+import static com.google.common.truth.Truth.assertThat;
+import static com.google.gitiles.doc.PathResolver.resolve;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+@RunWith(JUnit4.class)
+public class PathResolverTest {
+  @Test
+  public void resolveTests() {
+    assertThat(resolve(null, "/foo.md")).isEqualTo("foo.md");
+    assertThat(resolve(null, "////foo.md")).isEqualTo("foo.md");
+    assertThat(resolve("/index.md", "/foo.md")).isEqualTo("foo.md");
+    assertThat(resolve("index.md", "/foo.md")).isEqualTo("foo.md");
+    assertThat(resolve("index.md", "foo.md")).isEqualTo("foo.md");
+    assertThat(resolve(null, "foo.md")).isNull();
+
+    assertThat(resolve("doc/index.md", "../foo.md")).isEqualTo("foo.md");
+    assertThat(resolve("/doc/index.md", "../foo.md")).isEqualTo("foo.md");
+    assertThat(resolve("/doc/index.md", ".././foo.md")).isEqualTo("foo.md");
+    assertThat(resolve("/a/b/c/index.md", "../../foo.md")).isEqualTo("a/foo.md");
+    assertThat(resolve("/a/index.md", "../../../foo.md")).isNull();
+  }
+}