google-nomulus/docs/src/test/java/google/registry/documentation/FlowDocumentationTest.java
Ben McIlwain 0164bceb95
Fix some low-hanging code quality issue fruits (#1047)
* Fix some low-hanging code quality issue fruits

These include problems such as: use of raw types, unnecessary throw clauses,
unused variables, and more.
2021-04-01 18:04:21 -04:00

51 lines
2 KiB
Java

// Copyright 2017 The Nomulus 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 google.registry.documentation;
import static com.google.common.truth.Truth.assertWithMessage;
import static google.registry.util.BuildPathUtils.getProjectRoot;
import com.google.common.base.Joiner;
import java.nio.file.Files;
import java.nio.file.Path;
import org.junit.jupiter.api.Test;
/** Tests to ensure that generated flow documentation matches the expected documentation. */
class FlowDocumentationTest {
private static final Path GOLDEN_MARKDOWN_FILEPATH = getProjectRoot().resolve("docs/flows.md");
private static final String UPDATE_COMMAND = "./gradlew :docs:flowDocsTool";
private static final String UPDATE_INSTRUCTIONS =
Joiner.on('\n')
.join(
"",
"-----------------------------------------------------------------------------------",
"Your changes affect the flow API documentation output. To update the golden version "
+ "of the documentation, run:",
UPDATE_COMMAND,
"");
@Test
void testGeneratedMatchesGolden() throws Exception {
// Read the markdown file.
String goldenMarkdown = Files.readString(GOLDEN_MARKDOWN_FILEPATH);
// Don't use Truth's isEqualTo() because the output is huge and unreadable for large files.
DocumentationGenerator generator = new DocumentationGenerator();
if (!generator.generateMarkdown().equals(goldenMarkdown)) {
assertWithMessage(UPDATE_INSTRUCTIONS).fail();
}
}
}