LocalDateFormatter.java

1
/*
2
 * Copyright 2004 the original author or authors.
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *     http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
package com.ancientprogramming.fixedformat4j.format.impl;
17
18
import com.ancientprogramming.fixedformat4j.exception.FixedFormatException;
19
import com.ancientprogramming.fixedformat4j.format.FormatInstructions;
20
21
import java.time.LocalDate;
22
import java.time.format.DateTimeFormatter;
23
import java.time.format.DateTimeParseException;
24
25
/**
26
 * Formatter for {@link java.time.LocalDate} data.
27
 * The formatting and parsing is performed using {@link DateTimeFormatter}.
28
 * The pattern is configured via {@link com.ancientprogramming.fixedformat4j.annotation.FixedFormatPattern}.
29
 * The default pattern is {@code yyyyMMdd}.
30
 *
31
 * @author Jacob von Eyben - <a href="https://eybenconsult.com">https://eybenconsult.com</a>
32
 * @since 1.4.0
33
 */
34
public class LocalDateFormatter extends AbstractPatternFormatter<LocalDate> {
35
36
  @Override
37
  protected int computeFormattedLengthForPattern(String pattern) {
38 8 1. computeFormattedLengthForPattern : Substituted 1970 with 1971 → SURVIVED
2. computeFormattedLengthForPattern : Substituted 1 with 0 → KILLED
3. computeFormattedLengthForPattern : replaced int return with 0 for com/ancientprogramming/fixedformat4j/format/impl/LocalDateFormatter::computeFormattedLengthForPattern → KILLED
4. computeFormattedLengthForPattern : removed call to java/lang/String::length → KILLED
5. computeFormattedLengthForPattern : removed call to java/time/LocalDate::of → KILLED
6. computeFormattedLengthForPattern : Substituted 1 with 0 → KILLED
7. computeFormattedLengthForPattern : removed call to com/ancientprogramming/fixedformat4j/format/impl/LocalDateFormatter::formatterForPattern → KILLED
8. computeFormattedLengthForPattern : removed call to java/time/format/DateTimeFormatter::format → KILLED
    return formatterForPattern(pattern).format(LocalDate.of(1970, 1, 1)).length();
39
  }
40
41
  /** {@inheritDoc} */
42
  public LocalDate asObject(String string, FormatInstructions instructions) throws FixedFormatException {
43 7 1. asObject : removed conditional - replaced equality check with true → SURVIVED
2. asObject : negated conditional → KILLED
3. asObject : removed call to java/lang/String::isEmpty → KILLED
4. asObject : removed conditional - replaced equality check with false → KILLED
5. asObject : removed conditional - replaced equality check with true → KILLED
6. asObject : negated conditional → KILLED
7. asObject : removed conditional - replaced equality check with false → KILLED
    if (string == null || string.isEmpty()) {
44
      return null;
45
    }
46 2 1. asObject : removed call to com/ancientprogramming/fixedformat4j/format/FormatInstructions::getFixedFormatPatternData → KILLED
2. asObject : removed call to com/ancientprogramming/fixedformat4j/format/data/FixedFormatPatternData::getPattern → KILLED
    String pattern = instructions.getFixedFormatPatternData().getPattern();
47
    try {
48 3 1. asObject : removed call to com/ancientprogramming/fixedformat4j/format/impl/LocalDateFormatter::formatterForPattern → KILLED
2. asObject : replaced return value with null for com/ancientprogramming/fixedformat4j/format/impl/LocalDateFormatter::asObject → KILLED
3. asObject : removed call to java/time/LocalDate::parse → KILLED
      return LocalDate.parse(string, formatterForPattern(pattern));
49
    } catch (DateTimeParseException e) {
50 8 1. asObject : Substituted 3 with 4 → SURVIVED
2. asObject : Substituted 2 with 3 → KILLED
3. asObject : removed call to com/ancientprogramming/fixedformat4j/exception/FixedFormatException::<init> → KILLED
4. asObject : removed call to java/lang/String::format → KILLED
5. asObject : Substituted 0 with 1 → KILLED
6. asObject : Substituted 1 with 0 → KILLED
7. asObject : removed call to java/lang/Class::getName → KILLED
8. asObject : replaced call to java/lang/String::format with argument → KILLED
      throw new FixedFormatException(String.format("Could not parse value[%s] by pattern[%s] to %s", string, pattern, LocalDate.class.getName()), e);
51
    }
52
  }
53
54
  /** {@inheritDoc} */
55
  public String asString(LocalDate date, FormatInstructions instructions) {
56 3 1. asString : negated conditional → KILLED
2. asString : removed conditional - replaced equality check with false → KILLED
3. asString : removed conditional - replaced equality check with true → KILLED
    if (date == null) {
57 1 1. asString : replaced return value with "" for com/ancientprogramming/fixedformat4j/format/impl/LocalDateFormatter::asString → SURVIVED
      return null;
58
    }
59 5 1. asString : removed call to java/time/format/DateTimeFormatter::format → KILLED
2. asString : removed call to com/ancientprogramming/fixedformat4j/format/impl/LocalDateFormatter::formatterForPattern → KILLED
3. asString : removed call to com/ancientprogramming/fixedformat4j/format/FormatInstructions::getFixedFormatPatternData → KILLED
4. asString : replaced return value with "" for com/ancientprogramming/fixedformat4j/format/impl/LocalDateFormatter::asString → KILLED
5. asString : removed call to com/ancientprogramming/fixedformat4j/format/data/FixedFormatPatternData::getPattern → KILLED
    return formatterForPattern(instructions.getFixedFormatPatternData().getPattern()).format(date);
60
  }
61
}

Mutations

38

1.1
Location : computeFormattedLengthForPattern
Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateFormatter.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateFormatter]/[method:computeFormattedLengthForPattern_dashPattern_returnsTen()]
Substituted 1 with 0 → KILLED

2.2
Location : computeFormattedLengthForPattern
Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateFormatter.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateFormatter]/[method:computeFormattedLengthForPattern_dashPattern_returnsTen()]
replaced int return with 0 for com/ancientprogramming/fixedformat4j/format/impl/LocalDateFormatter::computeFormattedLengthForPattern → KILLED

3.3
Location : computeFormattedLengthForPattern
Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateFormatter.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateFormatter]/[method:computeFormattedLengthForPattern_dashPattern_returnsTen()]
removed call to java/lang/String::length → KILLED

4.4
Location : computeFormattedLengthForPattern
Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateFormatter.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateFormatter]/[method:computeFormattedLengthForPattern_dashPattern_returnsTen()]
removed call to java/time/LocalDate::of → KILLED

5.5
Location : computeFormattedLengthForPattern
Killed by : none
Substituted 1970 with 1971 → SURVIVED
Covering tests

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

7.7
Location : computeFormattedLengthForPattern
Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateFormatter.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateFormatter]/[method:computeFormattedLengthForPattern_dashPattern_returnsTen()]
removed call to com/ancientprogramming/fixedformat4j/format/impl/LocalDateFormatter::formatterForPattern → KILLED

8.8
Location : computeFormattedLengthForPattern
Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateFormatter.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateFormatter]/[method:computeFormattedLengthForPattern_dashPattern_returnsTen()]
removed call to java/time/format/DateTimeFormatter::format → KILLED

43

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

2.2
Location : asObject
Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateFormatter.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateFormatter]/[method:testAllSpaceInputParsesToNull()]
removed call to java/lang/String::isEmpty → KILLED

3.3
Location : asObject
Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateFormatter.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateFormatter]/[method:testAllSpaceInputParsesToNull()]
removed conditional - replaced equality check with false → KILLED

4.4
Location : asObject
Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateFormatter.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateFormatter]/[method:testInvalidDateStringExceptionChainsDateTimeParseExceptionCause()]
removed conditional - replaced equality check with true → KILLED

5.5
Location : asObject
Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateFormatter.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateFormatter]/[method:testInvalidDateStringExceptionChainsDateTimeParseExceptionCause()]
negated conditional → KILLED

6.6
Location : asObject
Killed by : none
removed conditional - replaced equality check with true → SURVIVED
Covering tests

7.7
Location : asObject
Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateFormatter.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateFormatter]/[method:testInvalidDateStringExceptionChainsDateTimeParseExceptionCause()]
removed conditional - replaced equality check with false → KILLED

46

1.1
Location : asObject
Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateFormatter.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateFormatter]/[method:testInvalidDateStringExceptionChainsDateTimeParseExceptionCause()]
removed call to com/ancientprogramming/fixedformat4j/format/FormatInstructions::getFixedFormatPatternData → KILLED

2.2
Location : asObject
Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateFormatter.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateFormatter]/[method:testInvalidDateStringExceptionChainsDateTimeParseExceptionCause()]
removed call to com/ancientprogramming/fixedformat4j/format/data/FixedFormatPatternData::getPattern → KILLED

48

1.1
Location : asObject
Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateFormatter.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateFormatter]/[method:testInvalidDateStringExceptionChainsDateTimeParseExceptionCause()]
removed call to com/ancientprogramming/fixedformat4j/format/impl/LocalDateFormatter::formatterForPattern → KILLED

2.2
Location : asObject
Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateFormatter.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateFormatter]/[method:testParseDefaultPattern()]
replaced return value with null for com/ancientprogramming/fixedformat4j/format/impl/LocalDateFormatter::asObject → KILLED

3.3
Location : asObject
Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateFormatter.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateFormatter]/[method:testInvalidDateStringExceptionChainsDateTimeParseExceptionCause()]
removed call to java/time/LocalDate::parse → KILLED

50

1.1
Location : asObject
Killed by : none
Substituted 3 with 4 → SURVIVED
Covering tests

2.2
Location : asObject
Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateFormatter.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateFormatter]/[method:testInvalidDateStringExceptionChainsDateTimeParseExceptionCause()]
Substituted 2 with 3 → KILLED

3.3
Location : asObject
Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateFormatter.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateFormatter]/[method:testInvalidDateStringExceptionChainsDateTimeParseExceptionCause()]
removed call to com/ancientprogramming/fixedformat4j/exception/FixedFormatException::<init> → KILLED

4.4
Location : asObject
Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateFormatter.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateFormatter]/[method:testInvalidDateStringExceptionContainsPattern()]
removed call to java/lang/String::format → KILLED

5.5
Location : asObject
Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateFormatter.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateFormatter]/[method:testInvalidDateStringExceptionContainsBadInput()]
Substituted 0 with 1 → KILLED

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

7.7
Location : asObject
Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateFormatter.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateFormatter]/[method:testInvalidDateStringExceptionContainsTypeName()]
removed call to java/lang/Class::getName → KILLED

8.8
Location : asObject
Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateFormatter.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateFormatter]/[method:testInvalidDateStringExceptionContainsPattern()]
replaced call to java/lang/String::format with argument → KILLED

56

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

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

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

57

1.1
Location : asString
Killed by : none
replaced return value with "" for com/ancientprogramming/fixedformat4j/format/impl/LocalDateFormatter::asString → SURVIVED
Covering tests

59

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

2.2
Location : asString
Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateFormatter.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateFormatter]/[method:testFormatAlternativePattern()]
removed call to com/ancientprogramming/fixedformat4j/format/impl/LocalDateFormatter::formatterForPattern → KILLED

3.3
Location : asString
Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateFormatter.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateFormatter]/[method:testFormatAlternativePattern()]
removed call to com/ancientprogramming/fixedformat4j/format/FormatInstructions::getFixedFormatPatternData → KILLED

4.4
Location : asString
Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateFormatter.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateFormatter]/[method:testFormatAlternativePattern()]
replaced return value with "" for com/ancientprogramming/fixedformat4j/format/impl/LocalDateFormatter::asString → KILLED

5.5
Location : asString
Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateFormatter.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateFormatter]/[method:testFormatAlternativePattern()]
removed call to com/ancientprogramming/fixedformat4j/format/data/FixedFormatPatternData::getPattern → KILLED

Active mutators

Tests examined


Report generated by PIT 1.23.1 support