|
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.text.DateFormat; |
|
23
|
|
import java.text.ParseException; |
|
24
|
|
import java.text.SimpleDateFormat; |
|
25
|
|
import java.util.Date; |
|
26
|
|
|
|
27
|
|
/** |
|
28
|
|
* Formatter for {@link java.util.Date} data. |
|
29
|
|
* The formatting and parsing is perfomed by using an instance of the {@link SimpleDateFormat} class. |
|
30
|
|
* |
|
31
|
|
* @author Jacob von Eyben - <a href="https://eybenconsult.com">https://eybenconsult.com</a> |
|
32
|
|
* @since 1.0.0 |
|
33
|
|
*/ |
|
34
|
|
public class DateFormatter extends AbstractPatternFormatter<Date> { |
|
35
|
|
|
|
36
|
|
@Override |
|
37
|
|
protected int computeFormattedLengthForPattern(String pattern) { |
|
38
|
6
1. computeFormattedLengthForPattern : Substituted 0 with 1 → SURVIVED
2. computeFormattedLengthForPattern : removed call to com/ancientprogramming/fixedformat4j/format/impl/DateFormatter::getFormatter → SURVIVED
3. computeFormattedLengthForPattern : removed call to java/text/DateFormat::format → SURVIVED
4. computeFormattedLengthForPattern : replaced int return with 0 for com/ancientprogramming/fixedformat4j/format/impl/DateFormatter::computeFormattedLengthForPattern → SURVIVED
5. computeFormattedLengthForPattern : removed call to java/util/Date::<init> → SURVIVED
6. computeFormattedLengthForPattern : removed call to java/lang/String::length → SURVIVED
|
return getFormatter(pattern).format(new Date(0)).length(); |
|
39
|
|
} |
|
40
|
|
|
|
41
|
|
/** {@inheritDoc} */ |
|
42
|
|
public Date asObject(String string, FormatInstructions instructions) throws FixedFormatException { |
|
43
|
|
Date result = null; |
|
44
|
|
|
|
45
|
4
1. asObject : removed call to org/apache/commons/lang3/StringUtils::isEmpty → KILLED
2. asObject : removed conditional - replaced equality check with true → KILLED
3. asObject : negated conditional → KILLED
4. asObject : removed conditional - replaced equality check with false → KILLED
|
if (!StringUtils.isEmpty(string)) { |
|
46
|
|
try { |
|
47
|
4
1. asObject : removed call to com/ancientprogramming/fixedformat4j/format/FormatInstructions::getFixedFormatPatternData → KILLED
2. asObject : removed call to com/ancientprogramming/fixedformat4j/format/impl/DateFormatter::getFormatter → KILLED
3. asObject : removed call to java/text/DateFormat::parse → KILLED
4. asObject : removed call to com/ancientprogramming/fixedformat4j/format/data/FixedFormatPatternData::getPattern → KILLED
|
result = getFormatter(instructions.getFixedFormatPatternData().getPattern()).parse(string); |
|
48
|
|
} catch (ParseException e) { |
|
49
|
10
1. asObject : removed call to java/lang/Class::getName → SURVIVED
2. asObject : Substituted 3 with 4 → SURVIVED
3. asObject : removed call to com/ancientprogramming/fixedformat4j/format/FormatInstructions::getFixedFormatPatternData → KILLED
4. asObject : removed call to java/lang/String::format → KILLED
5. asObject : Substituted 1 with 0 → KILLED
6. asObject : removed call to com/ancientprogramming/fixedformat4j/exception/FixedFormatException::<init> → KILLED
7. asObject : Substituted 0 with 1 → KILLED
8. asObject : removed call to com/ancientprogramming/fixedformat4j/format/data/FixedFormatPatternData::getPattern → KILLED
9. asObject : replaced call to java/lang/String::format with argument → KILLED
10. asObject : Substituted 2 with 3 → KILLED
|
throw new FixedFormatException(String.format("Could not parse value[%s] by pattern[%s] to %s", string, instructions.getFixedFormatPatternData().getPattern(), Date.class.getName())); |
|
50
|
|
} |
|
51
|
|
} |
|
52
|
1
1. asObject : replaced return value with null for com/ancientprogramming/fixedformat4j/format/impl/DateFormatter::asObject → KILLED
|
return result; |
|
53
|
|
} |
|
54
|
|
|
|
55
|
|
/** {@inheritDoc} */ |
|
56
|
|
public String asString(Date date, FormatInstructions instructions) { |
|
57
|
|
String result = null; |
|
58
|
3
1. asString : removed conditional - replaced equality check with true → KILLED
2. asString : negated conditional → KILLED
3. asString : removed conditional - replaced equality check with false → KILLED
|
if (date != null) { |
|
59
|
4
1. asString : removed call to com/ancientprogramming/fixedformat4j/format/data/FixedFormatPatternData::getPattern → KILLED
2. asString : removed call to com/ancientprogramming/fixedformat4j/format/impl/DateFormatter::getFormatter → KILLED
3. asString : removed call to com/ancientprogramming/fixedformat4j/format/FormatInstructions::getFixedFormatPatternData → KILLED
4. asString : removed call to java/text/DateFormat::format → KILLED
|
result = getFormatter(instructions.getFixedFormatPatternData().getPattern()).format(date); |
|
60
|
|
} |
|
61
|
1
1. asString : replaced return value with "" for com/ancientprogramming/fixedformat4j/format/impl/DateFormatter::asString → KILLED
|
return result; |
|
62
|
|
} |
|
63
|
|
|
|
64
|
|
DateFormat getFormatter(String pattern) { |
|
65
|
2
1. getFormatter : replaced return value with null for com/ancientprogramming/fixedformat4j/format/impl/DateFormatter::getFormatter → KILLED
2. getFormatter : removed call to java/text/SimpleDateFormat::<init> → KILLED
|
return new SimpleDateFormat(pattern); |
|
66
|
|
} |
|
67
|
|
} |
| | Mutations |
| 38 |
|
1.1 Location : computeFormattedLengthForPattern Killed by : none Substituted 0 with 1 → SURVIVED
Covering tests
2.2 Location : computeFormattedLengthForPattern Killed by : none removed call to com/ancientprogramming/fixedformat4j/format/impl/DateFormatter::getFormatter → SURVIVED
Covering tests
3.3 Location : computeFormattedLengthForPattern Killed by : none removed call to java/text/DateFormat::format → SURVIVED
Covering tests
4.4 Location : computeFormattedLengthForPattern Killed by : none replaced int return with 0 for com/ancientprogramming/fixedformat4j/format/impl/DateFormatter::computeFormattedLengthForPattern → SURVIVED
Covering tests
5.5 Location : computeFormattedLengthForPattern Killed by : none removed call to java/util/Date::<init> → SURVIVED
Covering tests
6.6 Location : computeFormattedLengthForPattern Killed by : none removed call to java/lang/String::length → SURVIVED
Covering tests
|
| 45 |
|
1.1 Location : asObject Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestDateFormatter.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestDateFormatter]/[method:testNullInputParseReturnsNull()] removed call to org/apache/commons/lang3/StringUtils::isEmpty → KILLED
2.2 Location : asObject Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestDateFormatter.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestDateFormatter]/[method:testNullInputParseReturnsNull()] removed conditional - replaced equality check with true → KILLED
3.3 Location : asObject Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestDateFormatter.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestDateFormatter]/[method:testNullInputParseReturnsNull()] negated conditional → KILLED
4.4 Location : asObject Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestDateFormatter.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestDateFormatter]/[method:rightAlignedZeroPaddingDoesNotStripLeadingZeroInDateComponents()] removed conditional - replaced equality check with false → KILLED
|
| 47 |
|
1.1 Location : asObject Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestDateFormatter.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestDateFormatter]/[method:rightAlignedZeroPaddingDoesNotStripLeadingZeroInDateComponents()] removed call to com/ancientprogramming/fixedformat4j/format/FormatInstructions::getFixedFormatPatternData → KILLED
2.2 Location : asObject Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestDateFormatter.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestDateFormatter]/[method:rightAlignedZeroPaddingDoesNotStripLeadingZeroInDateComponents()] removed call to com/ancientprogramming/fixedformat4j/format/impl/DateFormatter::getFormatter → KILLED
3.3 Location : asObject Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestDateFormatter.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestDateFormatter]/[method:rightAlignedZeroPaddingDoesNotStripLeadingZeroInDateComponents()] removed call to java/text/DateFormat::parse → KILLED
4.4 Location : asObject Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestDateFormatter.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestDateFormatter]/[method:rightAlignedZeroPaddingDoesNotStripLeadingZeroInDateComponents()] removed call to com/ancientprogramming/fixedformat4j/format/data/FixedFormatPatternData::getPattern → KILLED
|
| 49 |
|
1.1 Location : asObject Killed by : none removed call to java/lang/Class::getName → SURVIVED
Covering tests
2.2 Location : asObject Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestDateFormatter.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestDateFormatter]/[method:testInvalidDateStringThrowsFixedFormatExceptionWithMessage()] removed call to com/ancientprogramming/fixedformat4j/format/FormatInstructions::getFixedFormatPatternData → KILLED
3.3 Location : asObject Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestDateFormatter.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestDateFormatter]/[method:testInvalidDateStringThrowsFixedFormatExceptionWithMessage()] removed call to java/lang/String::format → KILLED
4.4 Location : asObject Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestDateFormatter.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestDateFormatter]/[method:testInvalidDateStringThrowsFixedFormatExceptionWithMessage()] Substituted 1 with 0 → KILLED
5.5 Location : asObject Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestDateFormatter.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestDateFormatter]/[method:testInvalidDateStringThrowsFixedFormatExceptionWithMessage()] removed call to com/ancientprogramming/fixedformat4j/exception/FixedFormatException::<init> → KILLED
6.6 Location : asObject Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestDateFormatter.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestDateFormatter]/[method:testInvalidDateStringThrowsFixedFormatExceptionWithMessage()] Substituted 0 with 1 → KILLED
7.7 Location : asObject Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestDateFormatter.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestDateFormatter]/[method:testInvalidDateStringThrowsFixedFormatExceptionWithMessage()] removed call to com/ancientprogramming/fixedformat4j/format/data/FixedFormatPatternData::getPattern → KILLED
8.8 Location : asObject Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestDateFormatter.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestDateFormatter]/[method:testInvalidDateStringThrowsFixedFormatExceptionWithMessage()] replaced call to java/lang/String::format with argument → KILLED
9.9 Location : asObject Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestDateFormatter.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestDateFormatter]/[method:testInvalidDateStringThrowsFixedFormatExceptionWithMessage()] Substituted 2 with 3 → KILLED
10.10 Location : asObject Killed by : none Substituted 3 with 4 → SURVIVED
Covering tests
|
| 52 |
|
1.1 Location : asObject Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestDateFormatter.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestDateFormatter]/[method:rightAlignedZeroPaddingDoesNotStripLeadingZeroInDateComponents()] replaced return value with null for com/ancientprogramming/fixedformat4j/format/impl/DateFormatter::asObject → KILLED
|
| 58 |
|
1.1 Location : asString Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestDateFormatter.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestDateFormatter]/[method:testNullFormatReturnsSpaces()] removed conditional - replaced equality check with true → KILLED
2.2 Location : asString Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestDateFormatter.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestDateFormatter]/[method:testNullFormatReturnsSpaces()] negated conditional → KILLED
3.3 Location : asString Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestDateFormatter.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestDateFormatter]/[method:testFormat()] removed conditional - replaced equality check with false → KILLED
|
| 59 |
|
1.1 Location : asString Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestDateFormatter.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestDateFormatter]/[method:testFormat()] removed call to com/ancientprogramming/fixedformat4j/format/data/FixedFormatPatternData::getPattern → KILLED
2.2 Location : asString Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestDateFormatter.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestDateFormatter]/[method:testFormat()] removed call to com/ancientprogramming/fixedformat4j/format/impl/DateFormatter::getFormatter → KILLED
3.3 Location : asString Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestDateFormatter.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestDateFormatter]/[method:testFormat()] removed call to com/ancientprogramming/fixedformat4j/format/FormatInstructions::getFixedFormatPatternData → KILLED
4.4 Location : asString Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestDateFormatter.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestDateFormatter]/[method:testFormat()] removed call to java/text/DateFormat::format → KILLED
|
| 61 |
|
1.1 Location : asString Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestDateFormatter.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestDateFormatter]/[method:testFormat()] replaced return value with "" for com/ancientprogramming/fixedformat4j/format/impl/DateFormatter::asString → KILLED
|
| 65 |
|
1.1 Location : getFormatter Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestDateFormatter.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestDateFormatter]/[method:testFormat()] replaced return value with null for com/ancientprogramming/fixedformat4j/format/impl/DateFormatter::getFormatter → KILLED
2.2 Location : getFormatter Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestDateFormatter.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestDateFormatter]/[method:testFormat()] removed call to java/text/SimpleDateFormat::<init> → KILLED
|