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