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   * @since 0.6
19   */
20  final class PomXpathValidatorTest {
21  
22      /**
23       * PomXpathValidator can validate pom.xml with xpath.
24       * @throws Exception If something wrong happens inside
25       */
26      @Test
27      void canValidatePomWithXpath() throws Exception {
28          final MavenEnvironment env = new MavenEnvironmentMocker().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          FileUtils.write(
34              new File(
35                  String.format(
36                      "%s%spom.xml", env.basedir(), File.separator
37                  )
38              ),
39              new TextOf(
40                  new ResourceOf("com/qulice/maven/PomXpathValidator/pom.xml")
41              ).asString(),
42              StandardCharsets.UTF_8
43          );
44          Assertions.assertDoesNotThrow(
45              () -> new PomXpathValidator().validate(env)
46          );
47      }
48  }