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 com.qulice.spi.Validator;
9   import java.util.concurrent.atomic.AtomicReference;
10  
11  /**
12   * A test fake {@link Validator} that remembers the value one
13   * {@link Environment} parameter had when the validator was called.
14   *
15   * @since 1.0
16   */
17  final class RecordingValidator implements Validator {
18  
19      /**
20       * Name of the parameter to remember.
21       */
22      private final String param;
23  
24      /**
25       * What the parameter was, or empty if the validator was never called.
26       */
27      private final AtomicReference<String> value;
28  
29      RecordingValidator(final String name) {
30          this.param = name;
31          this.value = new AtomicReference<>("");
32      }
33  
34      @Override
35      public void validate(final Environment env) {
36          this.value.set(env.param(this.param, ""));
37      }
38  
39      @Override
40      public String name() {
41          return "Recording";
42      }
43  
44      String seen() {
45          return this.value.get();
46      }
47  }