PatternValidator.java

1
package com.ancientprogramming.fixedformat4j.format.impl;
2
3
import com.ancientprogramming.fixedformat4j.exception.FixedFormatException;
4
5
import java.text.SimpleDateFormat;
6
import java.time.LocalDate;
7
import java.time.LocalDateTime;
8
import java.time.format.DateTimeFormatter;
9
import java.util.Date;
10
11
/**
12
 * Validates date/time pattern strings for the types supported by this library.
13
 *
14
 * <p>Validation is performed eagerly — before any data is parsed or formatted — so that
15
 * configuration errors surface immediately when a record class is first used, rather than
16
 * at the point a specific field is processed.
17
 *
18
 * @author Jacob von Eyben - <a href="https://eybenconsult.com">https://eybenconsult.com</a>
19
 * @since 1.6.0
20
 */
21
class PatternValidator {
22
23
  /**
24
   * Validates that {@code pattern} is a legal format pattern for {@code datatype}.
25
   *
26
   * <p>Validation is performed only for date/time types ({@link Date}, {@link LocalDate},
27
   * {@link LocalDateTime}). For all other types the method returns immediately.
28
   *
29
   * @param datatype the field's Java type
30
   * @param pattern  the pattern string from {@link com.ancientprogramming.fixedformat4j.annotation.FixedFormatPattern}
31
   * @throws FixedFormatException if the pattern is invalid for the given type
32
   */
33
  static void validate(Class<?> datatype, String pattern) {
34 4 1. validate : negated conditional → KILLED
2. validate : removed conditional - replaced equality check with false → KILLED
3. validate : removed conditional - replaced equality check with true → KILLED
4. validate : removed call to java/lang/Object::equals → KILLED
    if (Date.class.equals(datatype)) {
35 1 1. validate : removed call to com/ancientprogramming/fixedformat4j/format/impl/PatternValidator::validateSimpleDateFormat → KILLED
      validateSimpleDateFormat(pattern);
36 8 1. validate : negated conditional → KILLED
2. validate : removed call to java/lang/Object::equals → KILLED
3. validate : removed conditional - replaced equality check with true → KILLED
4. validate : removed call to java/lang/Object::equals → KILLED
5. validate : removed conditional - replaced equality check with true → KILLED
6. validate : removed conditional - replaced equality check with false → KILLED
7. validate : negated conditional → KILLED
8. validate : removed conditional - replaced equality check with false → KILLED
    } else if (LocalDate.class.equals(datatype) || LocalDateTime.class.equals(datatype)) {
37 1 1. validate : removed call to com/ancientprogramming/fixedformat4j/format/impl/PatternValidator::validateDateTimeFormatter → KILLED
      validateDateTimeFormatter(pattern);
38
    }
39
  }
40
41
  private static void validateSimpleDateFormat(String pattern) {
42
    try {
43 1 1. validateSimpleDateFormat : removed call to java/text/SimpleDateFormat::<init> → KILLED
      new SimpleDateFormat(pattern);
44
    } catch (IllegalArgumentException e) {
45 7 1. validateSimpleDateFormat : Substituted 1 with 0 → SURVIVED
2. validateSimpleDateFormat : replaced call to java/lang/String::format with argument → SURVIVED
3. validateSimpleDateFormat : removed call to java/lang/IllegalArgumentException::getMessage → SURVIVED
4. validateSimpleDateFormat : Substituted 0 with 1 → SURVIVED
5. validateSimpleDateFormat : removed call to java/lang/String::format → SURVIVED
6. validateSimpleDateFormat : Substituted 2 with 3 → KILLED
7. validateSimpleDateFormat : removed call to com/ancientprogramming/fixedformat4j/exception/FixedFormatException::<init> → KILLED
      throw new FixedFormatException(String.format("Invalid date pattern '%s': %s", pattern, e.getMessage()), e);
46
    }
47
  }
48
49
  private static void validateDateTimeFormatter(String pattern) {
50
    try {
51 1 1. validateDateTimeFormatter : removed call to java/time/format/DateTimeFormatter::ofPattern → KILLED
      DateTimeFormatter.ofPattern(pattern);
52
    } catch (IllegalArgumentException e) {
53 7 1. validateDateTimeFormatter : removed call to java/lang/IllegalArgumentException::getMessage → SURVIVED
2. validateDateTimeFormatter : removed call to java/lang/String::format → SURVIVED
3. validateDateTimeFormatter : Substituted 2 with 3 → KILLED
4. validateDateTimeFormatter : replaced call to java/lang/String::format with argument → KILLED
5. validateDateTimeFormatter : removed call to com/ancientprogramming/fixedformat4j/exception/FixedFormatException::<init> → KILLED
6. validateDateTimeFormatter : Substituted 0 with 1 → KILLED
7. validateDateTimeFormatter : Substituted 1 with 0 → KILLED
      throw new FixedFormatException(String.format("Invalid date/time pattern '%s': %s", pattern, e.getMessage()), e);
54
    }
55
  }
56
}

Mutations

34

1.1
Location : validate
Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestFixedFormatManagerImpl.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestFixedFormatManagerImpl]/[method:testInvalidLocalDateTimePatternOnExportThrowsFixedFormatException()]
negated conditional → KILLED

2.2
Location : validate
Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestFixedFormatManagerImpl.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestFixedFormatManagerImpl]/[method:testInvalidLocalDateTimePatternOnExportThrowsFixedFormatException()]
removed conditional - replaced equality check with false → KILLED

3.3
Location : validate
Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestFixedFormatManagerImpl.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestFixedFormatManagerImpl]/[method:testInvalidLocalDateTimePatternOnExportThrowsFixedFormatException()]
removed conditional - replaced equality check with true → KILLED

4.4
Location : validate
Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestFixedFormatManagerImpl.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestFixedFormatManagerImpl]/[method:testInvalidLocalDateTimePatternOnExportThrowsFixedFormatException()]
removed call to java/lang/Object::equals → KILLED

35

1.1
Location : validate
Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestFixedFormatManagerImpl.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestFixedFormatManagerImpl]/[method:testInvalidDatePatternOnExportThrowsFixedFormatException()]
removed call to com/ancientprogramming/fixedformat4j/format/impl/PatternValidator::validateSimpleDateFormat → KILLED

36

1.1
Location : validate
Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestFixedFormatManagerImpl.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestFixedFormatManagerImpl]/[method:testInvalidLocalDateTimePatternOnExportThrowsFixedFormatException()]
negated conditional → KILLED

2.2
Location : validate
Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestFixedFormatManagerImpl.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestFixedFormatManagerImpl]/[method:testInvalidLocalDateTimePatternOnExportThrowsFixedFormatException()]
removed call to java/lang/Object::equals → KILLED

3.3
Location : validate
Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestFixedFormatManagerImpl.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestFixedFormatManagerImpl]/[method:testInvalidLocalDateTimePatternOnExportThrowsFixedFormatException()]
removed conditional - replaced equality check with true → KILLED

4.4
Location : validate
Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestFixedFormatManagerImpl.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestFixedFormatManagerImpl]/[method:testInvalidLocalDateTimePatternOnExportThrowsFixedFormatException()]
removed call to java/lang/Object::equals → KILLED

5.5
Location : validate
Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestFixedFormatManagerImpl.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestFixedFormatManagerImpl]/[method:testInvalidLocalDateTimePatternOnExportThrowsFixedFormatException()]
removed conditional - replaced equality check with true → KILLED

6.6
Location : validate
Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestFixedFormatManagerImpl.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestFixedFormatManagerImpl]/[method:testInvalidLocalDateTimePatternOnExportThrowsFixedFormatException()]
removed conditional - replaced equality check with false → KILLED

7.7
Location : validate
Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestFixedFormatManagerImpl.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestFixedFormatManagerImpl]/[method:testInvalidLocalDateTimePatternOnExportThrowsFixedFormatException()]
negated conditional → KILLED

8.8
Location : validate
Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestFixedFormatManagerImpl.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestFixedFormatManagerImpl]/[method:testInvalidLocalDateTimePatternOnExportThrowsFixedFormatException()]
removed conditional - replaced equality check with false → KILLED

37

1.1
Location : validate
Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestFixedFormatManagerImpl.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestFixedFormatManagerImpl]/[method:testInvalidLocalDateTimePatternOnExportThrowsFixedFormatException()]
removed call to com/ancientprogramming/fixedformat4j/format/impl/PatternValidator::validateDateTimeFormatter → KILLED

43

1.1
Location : validateSimpleDateFormat
Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestFixedFormatManagerImpl.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestFixedFormatManagerImpl]/[method:testInvalidDatePatternOnExportThrowsFixedFormatException()]
removed call to java/text/SimpleDateFormat::<init> → KILLED

45

1.1
Location : validateSimpleDateFormat
Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestFixedFormatManagerImpl.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestFixedFormatManagerImpl]/[method:testInvalidDatePatternOnExportThrowsFixedFormatException()]
Substituted 2 with 3 → KILLED

2.2
Location : validateSimpleDateFormat
Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestFixedFormatManagerImpl.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestFixedFormatManagerImpl]/[method:testInvalidDatePatternOnExportThrowsFixedFormatException()]
removed call to com/ancientprogramming/fixedformat4j/exception/FixedFormatException::<init> → KILLED

3.3
Location : validateSimpleDateFormat
Killed by : none
Substituted 1 with 0 → SURVIVED
Covering tests

4.4
Location : validateSimpleDateFormat
Killed by : none
replaced call to java/lang/String::format with argument → SURVIVED Covering tests

5.5
Location : validateSimpleDateFormat
Killed by : none
removed call to java/lang/IllegalArgumentException::getMessage → SURVIVED Covering tests

6.6
Location : validateSimpleDateFormat
Killed by : none
Substituted 0 with 1 → SURVIVED Covering tests

7.7
Location : validateSimpleDateFormat
Killed by : none
removed call to java/lang/String::format → SURVIVED Covering tests

51

1.1
Location : validateDateTimeFormatter
Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestFixedFormatManagerImpl.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestFixedFormatManagerImpl]/[method:testInvalidLocalDateTimePatternOnExportThrowsFixedFormatException()]
removed call to java/time/format/DateTimeFormatter::ofPattern → KILLED

53

1.1
Location : validateDateTimeFormatter
Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestFixedFormatManagerImpl.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestFixedFormatManagerImpl]/[method:testInvalidLocalDateTimePatternOnExportThrowsFixedFormatException()]
Substituted 2 with 3 → KILLED

2.2
Location : validateDateTimeFormatter
Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestFixedFormatManagerImpl.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestFixedFormatManagerImpl]/[method:testInvalidLocalDateTimePatternOnExportThrowsFixedFormatException()]
replaced call to java/lang/String::format with argument → KILLED

3.3
Location : validateDateTimeFormatter
Killed by : none
removed call to java/lang/IllegalArgumentException::getMessage → SURVIVED
Covering tests

4.4
Location : validateDateTimeFormatter
Killed by : none
removed call to java/lang/String::format → SURVIVED Covering tests

5.5
Location : validateDateTimeFormatter
Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestFixedFormatManagerImpl.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestFixedFormatManagerImpl]/[method:testInvalidLocalDateTimePatternOnExportThrowsFixedFormatException()]
removed call to com/ancientprogramming/fixedformat4j/exception/FixedFormatException::<init> → KILLED

6.6
Location : validateDateTimeFormatter
Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestFixedFormatManagerImpl.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestFixedFormatManagerImpl]/[method:testInvalidLocalDateTimePatternOnExportThrowsFixedFormatException()]
Substituted 0 with 1 → KILLED

7.7
Location : validateDateTimeFormatter
Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestFixedFormatManagerImpl.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestFixedFormatManagerImpl]/[method:testInvalidLocalDateTimePatternOnExportThrowsFixedFormatException()]
Substituted 1 with 0 → KILLED

Active mutators

Tests examined


Report generated by PIT 1.23.1 support