|
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.LocalDateTime; |
|
22
|
|
import java.time.format.DateTimeParseException; |
|
23
|
|
|
|
24
|
|
/** |
|
25
|
|
* Formatter for {@link java.time.LocalDateTime} data. |
|
26
|
|
* The formatting and parsing is performed using {@link java.time.format.DateTimeFormatter}. |
|
27
|
|
* The pattern is configured via {@link com.ancientprogramming.fixedformat4j.annotation.FixedFormatPattern}. |
|
28
|
|
* The default pattern is {@code yyyy-MM-dd'T'HH:mm:ss} (ISO-8601 local date-time). |
|
29
|
|
* |
|
30
|
|
* @author Jacob von Eyben - <a href="https://eybenconsult.com">https://eybenconsult.com</a> |
|
31
|
|
* @since 1.6.0 |
|
32
|
|
*/ |
|
33
|
|
public class LocalDateTimeFormatter extends AbstractPatternFormatter<LocalDateTime> { |
|
34
|
|
|
|
35
|
|
@Override |
|
36
|
|
protected int computeFormattedLengthForPattern(String pattern) { |
|
37
|
11
1. computeFormattedLengthForPattern : Substituted 1970 with 1971 → SURVIVED
2. computeFormattedLengthForPattern : Substituted 0 with 1 → SURVIVED
3. computeFormattedLengthForPattern : Substituted 0 with 1 → SURVIVED
4. computeFormattedLengthForPattern : Substituted 0 with 1 → SURVIVED
5. computeFormattedLengthForPattern : Substituted 1 with 0 → KILLED
6. computeFormattedLengthForPattern : removed call to java/time/LocalDateTime::of → KILLED
7. computeFormattedLengthForPattern : removed call to java/lang/String::length → KILLED
8. computeFormattedLengthForPattern : replaced int return with 0 for com/ancientprogramming/fixedformat4j/format/impl/LocalDateTimeFormatter::computeFormattedLengthForPattern → KILLED
9. computeFormattedLengthForPattern : removed call to java/time/format/DateTimeFormatter::format → KILLED
10. computeFormattedLengthForPattern : Substituted 1 with 0 → KILLED
11. computeFormattedLengthForPattern : removed call to com/ancientprogramming/fixedformat4j/format/impl/LocalDateTimeFormatter::formatterForPattern → KILLED
|
return formatterForPattern(pattern).format(LocalDateTime.of(1970, 1, 1, 0, 0, 0)).length(); |
|
38
|
|
} |
|
39
|
|
|
|
40
|
|
/** {@inheritDoc} */ |
|
41
|
|
public LocalDateTime asObject(String string, FormatInstructions instructions) throws FixedFormatException { |
|
42
|
7
1. asObject : removed conditional - replaced equality check with true → SURVIVED
2. asObject : negated conditional → KILLED
3. asObject : removed conditional - replaced equality check with false → KILLED
4. asObject : removed call to java/lang/String::isEmpty → 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()) { |
|
43
|
|
return null; |
|
44
|
|
} |
|
45
|
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(); |
|
46
|
|
try { |
|
47
|
3
1. asObject : removed call to java/time/LocalDateTime::parse → KILLED
2. asObject : removed call to com/ancientprogramming/fixedformat4j/format/impl/LocalDateTimeFormatter::formatterForPattern → KILLED
3. asObject : replaced return value with null for com/ancientprogramming/fixedformat4j/format/impl/LocalDateTimeFormatter::asObject → KILLED
|
return LocalDateTime.parse(string, formatterForPattern(pattern)); |
|
48
|
|
} catch (DateTimeParseException e) { |
|
49
|
8
1. asObject : Substituted 3 with 4 → SURVIVED
2. asObject : removed call to com/ancientprogramming/fixedformat4j/exception/FixedFormatException::<init> → KILLED
3. asObject : Substituted 1 with 0 → KILLED
4. asObject : replaced call to java/lang/String::format with argument → KILLED
5. asObject : Substituted 2 with 3 → KILLED
6. asObject : Substituted 0 with 1 → KILLED
7. asObject : removed call to java/lang/Class::getName → KILLED
8. asObject : removed call to java/lang/String::format → KILLED
|
throw new FixedFormatException(String.format("Could not parse value[%s] by pattern[%s] to %s", string, pattern, LocalDateTime.class.getName()), e); |
|
50
|
|
} |
|
51
|
|
} |
|
52
|
|
|
|
53
|
|
/** {@inheritDoc} */ |
|
54
|
|
public String asString(LocalDateTime dateTime, FormatInstructions instructions) { |
|
55
|
3
1. asString : negated conditional → KILLED
2. asString : removed conditional - replaced equality check with true → KILLED
3. asString : removed conditional - replaced equality check with false → KILLED
|
if (dateTime == null) { |
|
56
|
1
1. asString : replaced return value with "" for com/ancientprogramming/fixedformat4j/format/impl/LocalDateTimeFormatter::asString → SURVIVED
|
return null; |
|
57
|
|
} |
|
58
|
5
1. asString : replaced return value with "" for com/ancientprogramming/fixedformat4j/format/impl/LocalDateTimeFormatter::asString → KILLED
2. asString : removed call to com/ancientprogramming/fixedformat4j/format/data/FixedFormatPatternData::getPattern → KILLED
3. asString : removed call to com/ancientprogramming/fixedformat4j/format/impl/LocalDateTimeFormatter::formatterForPattern → KILLED
4. asString : removed call to com/ancientprogramming/fixedformat4j/format/FormatInstructions::getFixedFormatPatternData → KILLED
5. asString : removed call to java/time/format/DateTimeFormatter::format → KILLED
|
return formatterForPattern(instructions.getFixedFormatPatternData().getPattern()).format(dateTime); |
|
59
|
|
} |
|
60
|
|
} |
| | Mutations |
| 37 |
|
1.1 Location : computeFormattedLengthForPattern Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateTimeFormatter.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateTimeFormatter]/[method:computeFormattedLengthForPattern_compactPattern_returnsFourteen()] Substituted 1 with 0 → KILLED
2.2 Location : computeFormattedLengthForPattern Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateTimeFormatter.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateTimeFormatter]/[method:computeFormattedLengthForPattern_compactPattern_returnsFourteen()] removed call to java/time/LocalDateTime::of → KILLED
3.3 Location : computeFormattedLengthForPattern Killed by : none Substituted 1970 with 1971 → SURVIVED
Covering tests
4.4 Location : computeFormattedLengthForPattern Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateTimeFormatter.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateTimeFormatter]/[method:computeFormattedLengthForPattern_compactPattern_returnsFourteen()] removed call to java/lang/String::length → KILLED
5.5 Location : computeFormattedLengthForPattern Killed by : none Substituted 0 with 1 → SURVIVED
Covering tests
6.6 Location : computeFormattedLengthForPattern Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateTimeFormatter.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateTimeFormatter]/[method:computeFormattedLengthForPattern_compactPattern_returnsFourteen()] replaced int return with 0 for com/ancientprogramming/fixedformat4j/format/impl/LocalDateTimeFormatter::computeFormattedLengthForPattern → KILLED
7.7 Location : computeFormattedLengthForPattern Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateTimeFormatter.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateTimeFormatter]/[method:computeFormattedLengthForPattern_compactPattern_returnsFourteen()] removed call to java/time/format/DateTimeFormatter::format → KILLED
8.8 Location : computeFormattedLengthForPattern Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateTimeFormatter.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateTimeFormatter]/[method:computeFormattedLengthForPattern_compactPattern_returnsFourteen()] Substituted 1 with 0 → KILLED
9.9 Location : computeFormattedLengthForPattern Killed by : none Substituted 0 with 1 → SURVIVED
Covering tests
10.10 Location : computeFormattedLengthForPattern Killed by : none Substituted 0 with 1 → SURVIVED
Covering tests
11.11 Location : computeFormattedLengthForPattern Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateTimeFormatter.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateTimeFormatter]/[method:computeFormattedLengthForPattern_compactPattern_returnsFourteen()] removed call to com/ancientprogramming/fixedformat4j/format/impl/LocalDateTimeFormatter::formatterForPattern → KILLED
|
| 42 |
|
1.1 Location : asObject Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateTimeFormatter.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateTimeFormatter]/[method:testInvalidDateTimeStringExceptionContainsBadInput()] negated conditional → KILLED
2.2 Location : asObject Killed by : none removed conditional - replaced equality check with true → SURVIVED
Covering tests
3.3 Location : asObject Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateTimeFormatter.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateTimeFormatter]/[method:testInvalidDateTimeStringExceptionContainsBadInput()] removed conditional - replaced equality check with false → KILLED
4.4 Location : asObject Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateTimeFormatter.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateTimeFormatter]/[method:testAllSpaceInputParsesToNull()] removed call to java/lang/String::isEmpty → KILLED
5.5 Location : asObject Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateTimeFormatter.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateTimeFormatter]/[method:testInvalidDateTimeStringExceptionContainsBadInput()] removed conditional - replaced equality check with true → KILLED
6.6 Location : asObject Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateTimeFormatter.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateTimeFormatter]/[method:testAllSpaceInputParsesToNull()] negated conditional → KILLED
7.7 Location : asObject Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateTimeFormatter.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateTimeFormatter]/[method:testAllSpaceInputParsesToNull()] removed conditional - replaced equality check with false → KILLED
|
| 45 |
|
1.1 Location : asObject Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateTimeFormatter.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateTimeFormatter]/[method:testInvalidDateTimeStringExceptionContainsBadInput()] removed call to com/ancientprogramming/fixedformat4j/format/FormatInstructions::getFixedFormatPatternData → KILLED
2.2 Location : asObject Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateTimeFormatter.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateTimeFormatter]/[method:testInvalidDateTimeStringExceptionContainsBadInput()] removed call to com/ancientprogramming/fixedformat4j/format/data/FixedFormatPatternData::getPattern → KILLED
|
| 47 |
|
1.1 Location : asObject Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateTimeFormatter.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateTimeFormatter]/[method:testInvalidDateTimeStringExceptionContainsBadInput()] removed call to java/time/LocalDateTime::parse → KILLED
2.2 Location : asObject Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateTimeFormatter.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateTimeFormatter]/[method:testInvalidDateTimeStringExceptionContainsBadInput()] removed call to com/ancientprogramming/fixedformat4j/format/impl/LocalDateTimeFormatter::formatterForPattern → KILLED
3.3 Location : asObject Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateTimeFormatter.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateTimeFormatter]/[method:testLeapDayDateTime()] replaced return value with null for com/ancientprogramming/fixedformat4j/format/impl/LocalDateTimeFormatter::asObject → KILLED
|
| 49 |
|
1.1 Location : asObject Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateTimeFormatter.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateTimeFormatter]/[method:testInvalidDateTimeStringExceptionContainsBadInput()] removed call to com/ancientprogramming/fixedformat4j/exception/FixedFormatException::<init> → KILLED
2.2 Location : asObject Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateTimeFormatter.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateTimeFormatter]/[method:testInvalidDateTimeStringExceptionContainsBadInput()] Substituted 1 with 0 → KILLED
3.3 Location : asObject Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateTimeFormatter.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateTimeFormatter]/[method:testInvalidDateTimeStringExceptionContainsBadInput()] replaced call to java/lang/String::format with argument → KILLED
4.4 Location : asObject Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateTimeFormatter.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateTimeFormatter]/[method:testInvalidDateTimeStringExceptionContainsBadInput()] Substituted 2 with 3 → KILLED
5.5 Location : asObject Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateTimeFormatter.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateTimeFormatter]/[method:testInvalidDateTimeStringExceptionContainsBadInput()] Substituted 0 with 1 → KILLED
6.6 Location : asObject Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateTimeFormatter.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateTimeFormatter]/[method:testInvalidDateTimeStringExceptionContainsTypeName()] removed call to java/lang/Class::getName → KILLED
7.7 Location : asObject Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateTimeFormatter.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateTimeFormatter]/[method:testInvalidDateTimeStringExceptionContainsBadInput()] removed call to java/lang/String::format → KILLED
8.8 Location : asObject Killed by : none Substituted 3 with 4 → SURVIVED
Covering tests
|
| 55 |
|
1.1 Location : asString Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateTimeFormatter.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateTimeFormatter]/[method:testNullFormatReturnsSpaces()] negated conditional → KILLED
2.2 Location : asString Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateTimeFormatter.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateTimeFormatter]/[method:testFormatIsoPattern()] removed conditional - replaced equality check with true → KILLED
3.3 Location : asString Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateTimeFormatter.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateTimeFormatter]/[method:testNullFormatReturnsSpaces()] removed conditional - replaced equality check with false → KILLED
|
| 56 |
|
1.1 Location : asString Killed by : none replaced return value with "" for com/ancientprogramming/fixedformat4j/format/impl/LocalDateTimeFormatter::asString → SURVIVED
Covering tests
|
| 58 |
|
1.1 Location : asString Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateTimeFormatter.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateTimeFormatter]/[method:testFormatIsoPattern()] replaced return value with "" for com/ancientprogramming/fixedformat4j/format/impl/LocalDateTimeFormatter::asString → KILLED
2.2 Location : asString Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateTimeFormatter.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateTimeFormatter]/[method:testFormatIsoPattern()] removed call to com/ancientprogramming/fixedformat4j/format/data/FixedFormatPatternData::getPattern → KILLED
3.3 Location : asString Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateTimeFormatter.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateTimeFormatter]/[method:testFormatIsoPattern()] removed call to com/ancientprogramming/fixedformat4j/format/impl/LocalDateTimeFormatter::formatterForPattern → KILLED
4.4 Location : asString Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateTimeFormatter.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateTimeFormatter]/[method:testFormatIsoPattern()] removed call to com/ancientprogramming/fixedformat4j/format/FormatInstructions::getFixedFormatPatternData → KILLED
5.5 Location : asString Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateTimeFormatter.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateTimeFormatter]/[method:testFormatIsoPattern()] removed call to java/time/format/DateTimeFormatter::format → KILLED
|