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 com.qulice.spi.Environment;
8   import org.junit.jupiter.api.Assertions;
9   import org.junit.jupiter.api.Test;
10  
11  /**
12   * Test case for {@link EnforcerValidator} class.
13   *
14   * @since 0.70.0
15   */
16  final class EnforcerValidatorTest {
17  
18      /**
19       * EnforcerValidator can skip validation when the enforcer
20       * check is excluded.
21       *
22       * @throws Exception If something wrong happens inside
23       */
24      @Test
25      void skipsWhenEnforcerIsExcluded() throws Exception {
26          Assertions.assertDoesNotThrow(
27              () -> new EnforcerValidator().validate(
28                  new MavenEnvironment.Wrap(
29                      new EnforcerExcludedEnvironment(new Environment.Mock()),
30                      new MavenEnvironmentMocker().mock()
31                  )
32              ),
33              "Enforcer validator must not invoke executor when check is excluded"
34          );
35      }
36  
37      /**
38       * EnforcerValidator attempts to execute the plugin when the check
39       * is not excluded.
40       *
41       * @throws Exception If something wrong happens inside
42       */
43      @Test
44      void invokesExecutorWhenNotExcluded() throws Exception {
45          Assertions.assertThrows(
46              UnsupportedOperationException.class,
47              () -> new EnforcerValidator()
48                  .validate(new MavenEnvironmentMocker().mock()),
49              "Enforcer validator must call executor when check is not excluded"
50          );
51      }
52  }