|
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
|
|
import org.apache.commons.lang3.StringUtils; |
|
21
|
|
|
|
22
|
|
import java.time.LocalDate; |
|
23
|
|
import java.time.format.DateTimeFormatter; |
|
24
|
|
import java.time.format.DateTimeParseException; |
|
25
|
|
|
|
26
|
|
/** |
|
27
|
|
* Formatter for {@link java.time.LocalDate} data. |
|
28
|
|
* The formatting and parsing is performed using {@link DateTimeFormatter}. |
|
29
|
|
* The pattern is configured via {@link com.ancientprogramming.fixedformat4j.annotation.FixedFormatPattern}. |
|
30
|
|
* The default pattern is {@code yyyyMMdd}. |
|
31
|
|
* |
|
32
|
|
* @author Jacob von Eyben - <a href="https://eybenconsult.com">https://eybenconsult.com</a> |
|
33
|
|
* @since 1.4.0 |
|
34
|
|
*/ |
|
35
|
|
public class LocalDateFormatter extends AbstractPatternFormatter<LocalDate> { |
|
36
|
|
|
|
37
|
|
@Override |
|
38
|
|
protected int computeFormattedLengthForPattern(String pattern) { |
|
39
|
8
1. computeFormattedLengthForPattern : Substituted 1970 with 1971 → SURVIVED
2. computeFormattedLengthForPattern : Substituted 1 with 0 → KILLED
3. computeFormattedLengthForPattern : removed call to java/time/format/DateTimeFormatter::ofPattern → KILLED
4. computeFormattedLengthForPattern : removed call to java/time/LocalDate::of → KILLED
5. computeFormattedLengthForPattern : removed call to java/time/format/DateTimeFormatter::format → KILLED
6. computeFormattedLengthForPattern : Substituted 1 with 0 → KILLED
7. computeFormattedLengthForPattern : replaced int return with 0 for com/ancientprogramming/fixedformat4j/format/impl/LocalDateFormatter::computeFormattedLengthForPattern → KILLED
8. computeFormattedLengthForPattern : removed call to java/lang/String::length → KILLED
|
return DateTimeFormatter.ofPattern(pattern).format(LocalDate.of(1970, 1, 1)).length(); |
|
40
|
|
} |
|
41
|
|
|
|
42
|
|
/** {@inheritDoc} */ |
|
43
|
|
public LocalDate asObject(String string, FormatInstructions instructions) throws FixedFormatException { |
|
44
|
4
1. asObject : negated conditional → KILLED
2. asObject : removed conditional - replaced equality check with false → KILLED
3. asObject : removed conditional - replaced equality check with true → KILLED
4. asObject : removed call to org/apache/commons/lang3/StringUtils::isEmpty → KILLED
|
if (StringUtils.isEmpty(string)) { |
|
45
|
|
return null; |
|
46
|
|
} |
|
47
|
2
1. asObject : removed call to com/ancientprogramming/fixedformat4j/format/data/FixedFormatPatternData::getPattern → KILLED
2. asObject : removed call to com/ancientprogramming/fixedformat4j/format/FormatInstructions::getFixedFormatPatternData → KILLED
|
String pattern = instructions.getFixedFormatPatternData().getPattern(); |
|
48
|
|
try { |
|
49
|
3
1. asObject : removed call to java/time/format/DateTimeFormatter::ofPattern → 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, DateTimeFormatter.ofPattern(pattern)); |
|
50
|
|
} catch (DateTimeParseException e) { |
|
51
|
8
1. asObject : Substituted 3 with 4 → SURVIVED
2. asObject : removed call to com/ancientprogramming/fixedformat4j/exception/FixedFormatException::<init> → KILLED
3. asObject : Substituted 0 with 1 → KILLED
4. asObject : Substituted 1 with 0 → KILLED
5. asObject : removed call to java/lang/Class::getName → KILLED
6. asObject : Substituted 2 with 3 → KILLED
7. asObject : removed call to java/lang/String::format → 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())); |
|
52
|
|
} |
|
53
|
|
} |
|
54
|
|
|
|
55
|
|
/** {@inheritDoc} */ |
|
56
|
|
public String asString(LocalDate date, FormatInstructions instructions) { |
|
57
|
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) { |
|
58
|
1
1. asString : replaced return value with "" for com/ancientprogramming/fixedformat4j/format/impl/LocalDateFormatter::asString → SURVIVED
|
return null; |
|
59
|
|
} |
|
60
|
2
1. asString : removed call to com/ancientprogramming/fixedformat4j/format/data/FixedFormatPatternData::getPattern → KILLED
2. asString : removed call to com/ancientprogramming/fixedformat4j/format/FormatInstructions::getFixedFormatPatternData → KILLED
|
String pattern = instructions.getFixedFormatPatternData().getPattern(); |
|
61
|
3
1. asString : removed call to java/time/format/DateTimeFormatter::format → KILLED
2. asString : removed call to java/time/format/DateTimeFormatter::ofPattern → KILLED
3. asString : replaced return value with "" for com/ancientprogramming/fixedformat4j/format/impl/LocalDateFormatter::asString → KILLED
|
return DateTimeFormatter.ofPattern(pattern).format(date); |
|
62
|
|
} |
|
63
|
|
} |
| | Mutations |
| 39 |
|
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 : none Substituted 1970 with 1971 → SURVIVED
Covering tests
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/time/format/DateTimeFormatter::ofPattern → 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 : 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
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()] replaced int return with 0 for com/ancientprogramming/fixedformat4j/format/impl/LocalDateFormatter::computeFormattedLengthForPattern → 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/lang/String::length → KILLED
|
| 44 |
|
1.1 Location : asObject Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateFormatter.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateFormatter]/[method:allZeroFieldWithZeroPaddingParsesToNull()] 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:allZeroFieldWithZeroPaddingParsesToNull()] removed conditional - replaced equality check with false → KILLED
3.3 Location : asObject Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateFormatter.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateFormatter]/[method:testParseDefaultPattern()] removed conditional - replaced equality check with true → KILLED
4.4 Location : asObject Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateFormatter.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateFormatter]/[method:allZeroFieldWithZeroPaddingParsesToNull()] removed call to org/apache/commons/lang3/StringUtils::isEmpty → KILLED
|
| 47 |
|
1.1 Location : asObject Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateFormatter.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateFormatter]/[method:testParseDefaultPattern()] removed call to com/ancientprogramming/fixedformat4j/format/data/FixedFormatPatternData::getPattern → 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()] removed call to com/ancientprogramming/fixedformat4j/format/FormatInstructions::getFixedFormatPatternData → KILLED
|
| 49 |
|
1.1 Location : asObject Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateFormatter.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateFormatter]/[method:testParseDefaultPattern()] removed call to java/time/format/DateTimeFormatter::ofPattern → 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:testParseDefaultPattern()] removed call to java/time/LocalDate::parse → KILLED
|
| 51 |
|
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:testInvalidMonthThrowsFixedFormatException()] removed call to com/ancientprogramming/fixedformat4j/exception/FixedFormatException::<init> → KILLED
3.3 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
4.4 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
5.5 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
6.6 Location : asObject Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateFormatter.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateFormatter]/[method:testInvalidMonthThrowsFixedFormatException()] Substituted 2 with 3 → KILLED
7.7 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
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
|
| 57 |
|
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:testFormatDefaultPattern()] removed conditional - replaced equality check with true → KILLED
|
| 58 |
|
1.1 Location : asString Killed by : none replaced return value with "" for com/ancientprogramming/fixedformat4j/format/impl/LocalDateFormatter::asString → SURVIVED
Covering tests
|
| 60 |
|
1.1 Location : asString Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateFormatter.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateFormatter]/[method:testFormatDefaultPattern()] removed call to com/ancientprogramming/fixedformat4j/format/data/FixedFormatPatternData::getPattern → KILLED
2.2 Location : asString Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateFormatter.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateFormatter]/[method:testFormatDefaultPattern()] removed call to com/ancientprogramming/fixedformat4j/format/FormatInstructions::getFixedFormatPatternData → KILLED
|
| 61 |
|
1.1 Location : asString Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateFormatter.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateFormatter]/[method:testFormatDefaultPattern()] 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:testFormatDefaultPattern()] removed call to java/time/format/DateTimeFormatter::ofPattern → KILLED
3.3 Location : asString Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateFormatter.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateFormatter]/[method:testFormatDefaultPattern()] replaced return value with "" for com/ancientprogramming/fixedformat4j/format/impl/LocalDateFormatter::asString → KILLED
|