View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.commons.release.plugin.velocity;
18  
19  import org.junit.Test;
20  
21  import java.io.IOException;
22  import java.io.StringWriter;
23  import java.io.Writer;
24  
25  import static junit.framework.TestCase.assertTrue;
26  
27  /**
28   * Unit tests for {@link ReadmeHtmlVelocityDelegate}.
29   */
30  public class ReadmeHtmlVelocityDelegateTest {
31  
32      @Test
33      public void testSuccessfulRun() throws IOException {
34          final ReadmeHtmlVelocityDelegate delegate = ReadmeHtmlVelocityDelegate.builder()
35                  .withArtifactId("commons-text")
36                  .withVersion("1.4")
37                  .withSiteUrl("https://commons.apache.org/text")
38                  .build();
39          try (Writer writer = delegate.render(new StringWriter())) {
40              final String filledOutTemplate = writer.toString();
41              assertTrue(filledOutTemplate.contains("<h1>Commons-TEXT v1.4.</h1>"));
42          }
43      }
44  
45      @Test
46      public void testSuccessfulRunLang3() throws IOException {
47          final ReadmeHtmlVelocityDelegate delegate = ReadmeHtmlVelocityDelegate.builder()
48                  .withArtifactId("commons-lang3")
49                  .withVersion("3.8.1")
50                  .withSiteUrl("https://commons.apache.org/text")
51                  .build();
52          try (Writer writer = delegate.render(new StringWriter())) {
53              final String filledOutTemplate = writer.toString();
54              assertTrue(filledOutTemplate.contains("<h1>Commons-LANG v3.8.1.</h1>"));
55          }
56      }
57  
58  
59  
60      @Test
61      public void testSuccessfulRunBcel() throws IOException {
62          final ReadmeHtmlVelocityDelegate delegate = ReadmeHtmlVelocityDelegate.builder()
63                  .withArtifactId("bcel")
64                  .withVersion("1.5")
65                  .withSiteUrl("https://commons.apache.org/text")
66                  .build();
67          try (Writer writer = delegate.render(new StringWriter())) {
68              final String filledOutTemplate = writer.toString();
69              assertTrue(filledOutTemplate.contains("<h1>Commons-BCEL v1.5.</h1>"));
70          }
71      }
72  }