xdocs: Add a unit test for the MarkdownFormatter

Change-Id: Ib41322474fb4df9fdfe1a3da98a58ee65dc7be23
diff --git a/BUCK b/BUCK
index 2bd5f04..46cc0f6 100644
--- a/BUCK
+++ b/BUCK
@@ -38,3 +38,12 @@
   deps = [':x-docs__plugin'],
 )
 
+java_test(
+  name = 'x-docs_tests',
+  srcs = glob(['src/test/java/**/*.java']),
+  labels = ['xdocs'],
+  source_under_test = [':x-docs__plugin'],
+  deps = GERRIT_PLUGIN_API + GERRIT_TESTS + [
+    ':x-docs__plugin',
+  ],
+)
diff --git a/src/test/java/com/googlesource/gerrit/plugins/x-docs/MarkdownFormatterTest.java b/src/test/java/com/googlesource/gerrit/plugins/x-docs/MarkdownFormatterTest.java
new file mode 100644
index 0000000..d2c62c5
--- /dev/null
+++ b/src/test/java/com/googlesource/gerrit/plugins/x-docs/MarkdownFormatterTest.java
@@ -0,0 +1,67 @@
+// 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.googlesource.gerrit.plugins.xdocs.formatter;
+
+import static org.easymock.EasyMock.*;
+import static org.junit.Assert.assertEquals;
+
+import com.googlesource.gerrit.plugins.xdocs.ConfigSection;
+
+import java.io.IOException;
+
+import org.junit.Before;
+import org.junit.Test;
+
+public class MarkdownFormatterTest {
+
+  private static final String PROLOG = "<html><head><style type=\"text/css\">\n\n</style></head><body>\n<p>";
+  private static final String EPILOG = "</p>\n</body></html>";
+
+  private FormatterUtil util;
+  private ConfigSection cfg;
+  private Formatters formatters;
+  private MarkdownFormatter formatter;
+
+  @Before
+  public void setUp() throws IOException {
+    util = createNiceMock(FormatterUtil.class);
+
+    // For easier result comparison, avoid the internal MarkdownFormatter to apply the default CSS.
+    expect(util.getInheritedCss(anyString(), anyString(), anyString(), anyString())).andReturn("");
+
+    replay(util);
+
+    cfg = createNiceMock(ConfigSection.class);
+
+    // Do not expect any behavior from the ConfigSection itself.
+    replay(cfg);
+
+    formatters = createNiceMock(Formatters.class);
+
+    // Avoid a NPE by just returning the ConfigSection mock object.
+    expect(formatters.getFormatterConfig(anyString(), anyString())).andReturn(cfg);
+
+    replay(formatters);
+
+    formatter = new MarkdownFormatter(util, formatters);
+  }
+
+  @Test
+  public void basicTextFormattingWorks() throws IOException {
+    String raw = "*italic* **bold** `monospace`";
+    String formatted = PROLOG + "<em>italic</em> <strong>bold</strong> <code>monospace</code>" + EPILOG;
+    assertEquals(formatter.format(null, null, null, null, cfg, raw), formatted);
+  }
+}