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.ResourceValidator;
8   import com.qulice.spi.Violation;
9   import java.io.File;
10  import java.util.Collection;
11  import java.util.Collections;
12  import java.util.concurrent.atomic.AtomicInteger;
13  
14  /**
15   * A test fake {@link ResourceValidator} that records how many times
16   * {@code validate} was invoked and reports a configurable name and
17   * rule count through {@link #name()} and {@link #rules()}. The validate
18   * call always returns an empty collection, so {@code CheckMojo} treats
19   * the run as clean.
20   *
21   * @since 0.27.0
22   */
23  final class FakeResourceValidator implements ResourceValidator {
24  
25      /**
26       * Resource validator name.
27       */
28      private final String label;
29  
30      /**
31       * How many rules this validator pretends to apply.
32       */
33      private final int total;
34  
35      /**
36       * Method calls counter.
37       */
38      private final AtomicInteger cnt;
39  
40      FakeResourceValidator(final String name) {
41          this(name, 0);
42      }
43  
44      FakeResourceValidator(final String name, final int rules) {
45          this.label = name;
46          this.total = rules;
47          this.cnt = new AtomicInteger(0);
48      }
49  
50      @Override
51      public Collection<Violation> validate(final Collection<File> files) {
52          this.cnt.incrementAndGet();
53          return Collections.emptyList();
54      }
55  
56      @Override
57      public String name() {
58          return this.label;
59      }
60  
61      @Override
62      public int rules() {
63          return this.total;
64      }
65  
66      int count() {
67          return this.cnt.get();
68      }
69  }