CharacterFormatter.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.format.AbstractFixedFormatter;
19
import com.ancientprogramming.fixedformat4j.format.FormatInstructions;
20
import org.slf4j.Logger;
21
import org.slf4j.LoggerFactory;
22
import org.apache.commons.lang3.StringUtils;
23
24
/**
25
 * Formatter for {@link Character} data
26
 *
27
 * @author Jacob von Eyben - <a href="https://eybenconsult.com">https://eybenconsult.com</a>
28
 * @since 1.0.0
29
 */
30
public class CharacterFormatter extends AbstractFixedFormatter<Character> {
31
32
  private static final Logger LOG = LoggerFactory.getLogger(CharacterFormatter.class);
33
34
  /** {@inheritDoc} */
35
  public Character asObject(String string, FormatInstructions instructions) {
36
    Character result = null;
37 1 1. asObject : negated conditional → KILLED
    if (!StringUtils.isEmpty(string)) {
38
      result = string.charAt(0);
39 2 1. asObject : changed conditional boundary → SURVIVED
2. asObject : negated conditional → SURVIVED
      if (string.length() > 1) {
40
        LOG.warn("found more than one character[{}] after reading instructions from record. Will return first character[{}]", string, result);
41
      }
42
    }
43 1 1. asObject : replaced Character return value with 0 for com/ancientprogramming/fixedformat4j/format/impl/CharacterFormatter::asObject → KILLED
    return result;
44
  }
45
46
  /** {@inheritDoc} */
47
  public String asString(Character obj, FormatInstructions instructions) {
48
    String result = "";
49 1 1. asString : negated conditional → KILLED
    if (obj != null) {
50
      result = Character.toString(obj);
51
    }
52 1 1. asString : replaced return value with "" for com/ancientprogramming/fixedformat4j/format/impl/CharacterFormatter::asString → KILLED
    return result;
53
  }
54
}

Mutations

37

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

39

1.1
Location : asObject
Killed by : none
changed conditional boundary → SURVIVED
Covering tests

2.2
Location : asObject
Killed by : none
negated conditional → SURVIVED Covering tests

43

1.1
Location : asObject
Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestCharacterFormatter.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestCharacterFormatter]/[method:testOnlyFirstCharUsedFromLongerString()]
replaced Character return value with 0 for com/ancientprogramming/fixedformat4j/format/impl/CharacterFormatter::asObject → KILLED

49

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

52

1.1
Location : asString
Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestCharacterFormatter.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestCharacterFormatter]/[method:testFormat()]
replaced return value with "" for com/ancientprogramming/fixedformat4j/format/impl/CharacterFormatter::asString → KILLED

Active mutators

Tests examined


Report generated by PIT 1.17.1