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.Test;
14  
15  /**
16   * Test case for {@link PomXpathValidator} class.
17   * @since 0.6
18   */
19  final class PomXpathValidatorTest {
20  
21      /**
22       * PomXpathValidator can validate pom.xml with xpath.
23       * @throws Exception If something wrong happens inside
24       */
25      @Test
26      void canValidatePomWithXpath() throws Exception {
27          final MavenEnvironment env = new MavenEnvironmentMocker()
28              .withAsserts(
29                  Collections.singletonList(
30                  "/pom:project/pom:dependencies/pom:dependency[pom:artifactId='commons-io']/pom:version[.='1.2.5']/text()"
31              )
32          ).mock();
33          final String pom = new TextOf(
34              new ResourceOf("com/qulice/maven/PomXpathValidator/pom.xml")
35          ).asString();
36          FileUtils.write(
37              new File(
38                  String.format(
39                      "%s%spom.xml", env.basedir(), File.separator
40                  )
41              ),
42              pom,
43              StandardCharsets.UTF_8
44          );
45          new PomXpathValidator().validate(env);
46      }
47  }