Commit 069da820 authored by Johannes Salentin's avatar Johannes Salentin
Browse files

added DataService

extended SmellExample
parent 3808019f
Pipeline #160226 passed with stages
in 1 minute and 25 seconds
This diff is collapsed.
......@@ -15,6 +15,7 @@ public class EASmellDetector {
List<Detector> detectors = new ArrayList<>();
detectors.add(new AmbiguousViewpoint());
detectors.add(new CyclicDependency());
detectors.add(new DataService());
detectors.add(new DeadComponent());
detectors.add(new DenseStructure());
detectors.add(new Documentation());
......
package de.example.smells;
import de.example.model.ElementType;
import java.util.List;
import java.util.stream.Collectors;
public class DataService extends Detector {
public DataService() {
super("Data Service");
}
public List<EASmell> detect() {
List<ElementType> serviceElements = model.getElements().stream().filter(e -> e.getClass().getSimpleName().contains("Service")).collect(Collectors.toList());
List<ElementType> dataElements = model.getElementsOfType(new String[]{"BusinessObject", "DataObject", "SystemSoftware"});
for (ElementType serviceElement : serviceElements) {
List<ElementType> referencedElements = model.getReferencedElementsOf(serviceElement);
if (!referencedElements.isEmpty()) {
boolean onlyDataReferences = true;
for (ElementType referencedElement : referencedElements) {
if (!dataElements.contains(referencedElement)) {
onlyDataReferences = false;
break;
}
}
if (onlyDataReferences) {
addToSmells(new EASmell(getSmellName(), serviceElement));
}
}
}
return result;
}
}
......@@ -18,6 +18,7 @@ public abstract class Detector {
Detector() {
smells = new ArrayList<>();
result = new ArrayList<>();
}
Detector(String name) {
......
package de.example.smells;
import de.example.main.ModelAdapter;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
class TestDataService {
private DataService detector;
@Test
void testCentralModel() {
ModelAdapter model = new ModelAdapter("CentralModel.xml", null);
Detector.setModel(model);
detector = new DataService();
assertEquals(detector.detect().size(), 0);
}
@Test
void testSmellExample() {
ModelAdapter model = new ModelAdapter("SmellExample.xml", null);
Detector.setModel(model);
detector = new DataService();
assertEquals(detector.detect().size(), 1);
}
}
......@@ -22,6 +22,6 @@ class TestWeakenedModularity {
ModelAdapter model = new ModelAdapter("SmellExample.xml", null);
Detector.setModel(model);
detector = new WeakenedModularity();
assertEquals(detector.detect().size(), 2);
assertEquals(detector.detect().size(), 1);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment