| 1 | package com.automationrhapsody.reststub.persistence; | |
| 2 | ||
| 3 | import com.automationrhapsody.reststub.data.Person; | |
| 4 | ||
| 5 | import java.util.ArrayList; | |
| 6 | import java.util.HashMap; | |
| 7 | import java.util.List; | |
| 8 | import java.util.Map; | |
| 9 | ||
| 10 | public class PersonDB { | |
| 11 | private static final Map<Integer, Person> PERSONS = new HashMap<>(); | |
| 12 | ||
| 13 | static { | |
| 14 | PERSONS.put(1, new Person(1, "FN1", "LN1", "email1@email.na")); | |
| 15 | PERSONS.put(2, new Person(2, "FN2", "LN2", "email2@email.na")); | |
| 16 | PERSONS.put(3, new Person(3, "FN3", "LN3", "email3@email.na")); | |
| 17 | PERSONS.put(4, new Person(4, "FN4", "LN4", "email4@email.na")); | |
| 18 | } | |
| 19 | ||
| 20 | public static Person getById(int id) { | |
| 21 |
1
1. getById : mutated return of Object value for com/automationrhapsody/reststub/persistence/PersonDB::getById to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return PERSONS.get(id); |
| 22 | } | |
| 23 | ||
| 24 | public static List<Person> getAll() { | |
| 25 | List<Person> result = new ArrayList<Person>(); | |
| 26 |
1
1. getAll : negated conditional → KILLED |
for (Integer key : PERSONS.keySet()) { |
| 27 | result.add(PERSONS.get(key)); | |
| 28 | } | |
| 29 |
1
1. getAll : mutated return of Object value for com/automationrhapsody/reststub/persistence/PersonDB::getAll to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return result; |
| 30 | } | |
| 31 | ||
| 32 | public static int getCount() { | |
| 33 |
1
1. getCount : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return PERSONS.size(); |
| 34 | } | |
| 35 | ||
| 36 | public static void remove() { | |
| 37 |
1
1. remove : negated conditional → KILLED |
if (!PERSONS.keySet().isEmpty()) { |
| 38 |
1
1. remove : Replaced integer subtraction with addition → KILLED |
PERSONS.remove(PERSONS.keySet().toArray()[PERSONS.keySet().size() - 1]); |
| 39 | } | |
| 40 | } | |
| 41 | ||
| 42 | public static String save(Person person) { | |
| 43 | String result = ""; | |
| 44 |
1
1. save : negated conditional → SURVIVED |
if (PERSONS.get(person.getId()) != null) { |
| 45 | result = "Updated Person with id=" + person.getId(); | |
| 46 | } else { | |
| 47 | result = "Added Person with id=" + person.getId(); | |
| 48 | } | |
| 49 | PERSONS.put(person.getId(), person); | |
| 50 |
1
1. save : mutated return of Object value for com/automationrhapsody/reststub/persistence/PersonDB::save to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return result; |
| 51 | } | |
| 52 | } | |
Mutations | ||
| 21 |
1.1 |
|
| 26 |
1.1 |
|
| 29 |
1.1 |
|
| 33 |
1.1 |
|
| 37 |
1.1 |
|
| 38 |
1.1 |
|
| 44 |
1.1 |
|
| 50 |
1.1 |