View Javadoc
1   /*
2    * SPDX-FileCopyrightText: Copyright (c) 2011-2026 Yegor Bugayenko
3    * SPDX-License-Identifier: MIT
4    */
5   package com.qulice.maven;
6   
7   import java.io.File;
8   import java.nio.charset.StandardCharsets;
9   import java.util.Collections;
10  import org.apache.commons.io.FileUtils;
11  import org.cactoos.io.ResourceOf;
12  import org.cactoos.text.TextOf;
13  import org.junit.jupiter.api.Assertions;
14  import org.junit.jupiter.api.Test;
15  
16  /**
17   * Test case for {@link PomXpathValidator} class.
18   *
19   * @since 0.6
20   */
21  final class PomXpathValidatorTest {
22  
23      /**
24       * PomXpathValidator can validate pom.xml with xpath.
25       *
26       * @throws Exception If something wrong happens inside
27       */
28      @Test
29      void canValidatePomWithXpath() throws Exception {
30          final MavenEnvironment env = new MavenEnvironmentMocker().withAsserts(
31              Collections.singletonList(
32                  "/pom:project/pom:dependencies/pom:dependency[pom:artifactId='commons-io']/pom:version[.='1.2.5']/text()"
33              )
34          ).mock();
35          FileUtils.write(
36              new File(
37                  String.format(
38                      "%s%spom.xml", env.basedir(), File.separator
39                  )
40              ),
41              new TextOf(
42                  new ResourceOf("com/qulice/maven/PomXpathValidator/pom.xml")
43              ).asString(),
44              StandardCharsets.UTF_8
45          );
46          Assertions.assertDoesNotThrow(
47              () -> new PomXpathValidator().validate(env)
48          );
49      }
50  }