• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

devonfw / IDEasy / 12084195088

29 Nov 2024 11:46AM UTC coverage: 67.412% (-0.005%) from 67.417%
12084195088

push

github

web-flow
#569: improve Validation (added JavaDoc, etc.) (#817)

2500 of 4050 branches covered (61.73%)

Branch coverage included in aggregate %.

6515 of 9323 relevant lines covered (69.88%)

3.08 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

94.59
cli/src/main/java/com/devonfw/tools/ide/validation/ValidationState.java
1
package com.devonfw.tools.ide.validation;
2

3
/**
4
 * Implementation of {@link ValidationResult} as a mutable state that can collect errors dynamically.
5
 */
6
public class ValidationState implements ValidationResult {
7

8
  private final String propertyName;
9

10
  private StringBuilder errorMessage;
11

12
  /**
13
   * The default constructor for no property.
14
   */
15
  public ValidationState() {
16
    this(null);
×
17
  }
×
18

19
  /**
20
   * @param propertyName the name of the property to validate.
21
   */
22
  public ValidationState(String propertyName) {
2✔
23
    this.propertyName = propertyName;
3✔
24
  }
1✔
25

26
  @Override
27
  public boolean isValid() {
28
    return (this.errorMessage == null);
7✔
29
  }
30

31
  @Override
32
  public String getErrorMessage() {
33
    if (this.errorMessage == null) {
3✔
34
      return null;
2✔
35
    }
36
    return this.errorMessage.toString();
4✔
37
  }
38

39
  /**
40
   * @param error the error message to add to this {@link ValidationState}.
41
   */
42
  public void addErrorMessage(String error) {
43
    if (this.errorMessage == null) {
3✔
44
      if (this.propertyName == null) {
3✔
45
        this.errorMessage = new StringBuilder(error.length() + 1);
9✔
46
        this.errorMessage.append('\n');
6✔
47
      } else {
48
        this.errorMessage = new StringBuilder(error.length() + propertyName.length() + 21); // 21 for the static text below
13✔
49
        this.errorMessage.append(String.format("Error in property %s:", propertyName));
13✔
50
        this.errorMessage.append('\n');
6✔
51
      }
52
    } else {
53
      this.errorMessage.append('\n');
5✔
54
    }
55
    this.errorMessage.append(error);
5✔
56
  }
1✔
57

58
  /**
59
   * @param result the {@link ValidationResult} to add to this {@link ValidationState}.
60
   */
61
  public void add(ValidationResult result) {
62
    if (!result.isValid()) {
3✔
63
      if (this.errorMessage == null) {
3✔
64
        this.errorMessage = new StringBuilder(result.getErrorMessage().length());
8✔
65
        this.errorMessage.append(result.getErrorMessage());
7✔
66
      } else {
67
        addErrorMessage(result.getErrorMessage());
4✔
68
      }
69
    }
70
  }
1✔
71
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc