Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improving the implementation of the AbstractSmell class, removing rep… #4

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 0 additions & 21 deletions TestSmellDetector.iml

This file was deleted.

2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>edu.rit.se.testsmells</groupId>
<artifactId>TestSmellDetector</artifactId>
<version>0.1</version>
<version>0.2</version>
<build>
<plugins>
<plugin>
Expand Down
34 changes: 34 additions & 0 deletions src/main/java/edu/rit/se/testsmells/AbstractSmell.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package edu.rit.se.testsmells;

import com.github.javaparser.ast.CompilationUnit;

import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.List;

public abstract class AbstractSmell {

protected List<SmellyElement> smellyElementList;

public AbstractSmell() {
smellyElementList = new ArrayList<>();
}

/**
* Returns true if any of the elements has a smell
*/
public boolean getHasSmell() {
return smellyElementList.stream().filter(x -> x.getHasSmell()).count() >= 1;
}

/**
* Returns the set of analyzed elements (i.e. test methods)
*/
public List<SmellyElement> getSmellyElements() {
return smellyElementList;
}

public abstract String getSmellName();

public abstract void runAnalysis(CompilationUnit testFileCompilationUnit,CompilationUnit productionFileCompilationUnit, String testFileName, String productionFileName) throws FileNotFoundException;
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import testsmell.AbstractSmell;
import testsmell.ResultsWriter;
import testsmell.TestFile;
import testsmell.TestSmellDetector;
package edu.rit.se.testsmells;

import java.io.BufferedReader;
import java.io.File;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package testsmell;
package edu.rit.se.testsmells;

import java.io.FileWriter;
import java.io.IOException;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package testsmell;
package edu.rit.se.testsmells;

import java.util.Map;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package testsmell;
package edu.rit.se.testsmells;

import java.util.HashMap;
import java.util.Map;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package testsmell;
package edu.rit.se.testsmells;

import org.apache.commons.lang3.StringUtils;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package testsmell;
package edu.rit.se.testsmells;

import java.util.HashMap;
import java.util.Map;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package testsmell;
package edu.rit.se.testsmells;

import com.github.javaparser.JavaParser;
import com.github.javaparser.ast.CompilationUnit;
import org.apache.commons.lang3.StringUtils;
import testsmell.smell.*;
import edu.rit.se.testsmells.smell.*;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package testsmell;
package edu.rit.se.testsmells;

import com.github.javaparser.ast.Modifier;
import com.github.javaparser.ast.body.MethodDeclaration;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
package testsmell.smell;
package edu.rit.se.testsmells.smell;

import com.github.javaparser.ast.CompilationUnit;
import com.github.javaparser.ast.body.MethodDeclaration;
import com.github.javaparser.ast.expr.MethodCallExpr;
import com.github.javaparser.ast.visitor.VoidVisitorAdapter;
import testsmell.AbstractSmell;
import testsmell.SmellyElement;
import testsmell.TestMethod;
import testsmell.Util;
import edu.rit.se.testsmells.AbstractSmell;
import edu.rit.se.testsmells.TestMethod;
import edu.rit.se.testsmells.Util;

import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.List;

/**
* "Guess what's wrong?" This smell comes from having a number of assertions in a test method that have no explanation.
Expand All @@ -20,12 +17,6 @@
*/
public class AssertionRoulette extends AbstractSmell {

private List<SmellyElement> smellyElementList;

public AssertionRoulette() {
smellyElementList = new ArrayList<>();
}

/**
* Checks of 'Assertion Roulette' smell
*/
Expand All @@ -34,14 +25,6 @@ public String getSmellName() {
return "Assertion Roulette";
}

/**
* Returns true if any of the elements has a smell
*/
@Override
public boolean getHasSmell() {
return smellyElementList.stream().filter(x -> x.getHasSmell()).count() >= 1;
}

/**
* Analyze the test file for test methods for multiple assert statements without an explanation/message
*/
Expand All @@ -52,15 +35,6 @@ public void runAnalysis(CompilationUnit testFileCompilationUnit, CompilationUnit
classVisitor.visit(testFileCompilationUnit, null);
}

/**
* Returns the set of analyzed elements (i.e. test methods)
*/
@Override
public List<SmellyElement> getSmellyElements() {
return smellyElementList;
}


private class ClassVisitor extends VoidVisitorAdapter<Void> {
private MethodDeclaration currentMethod = null;
private int assertNoMessageCount = 0;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,20 @@
package testsmell.smell;
package edu.rit.se.testsmells.smell;

import com.github.javaparser.ast.CompilationUnit;
import com.github.javaparser.ast.body.MethodDeclaration;
import com.github.javaparser.ast.expr.ConditionalExpr;
import com.github.javaparser.ast.stmt.*;
import com.github.javaparser.ast.visitor.VoidVisitorAdapter;
import testsmell.AbstractSmell;
import testsmell.SmellyElement;
import testsmell.TestMethod;
import testsmell.Util;
import edu.rit.se.testsmells.AbstractSmell;
import edu.rit.se.testsmells.TestMethod;
import edu.rit.se.testsmells.Util;

import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.List;

/*
This class check a test method for the existence of loops and conditional statements in the methods body
*/
public class ConditionalTestLogic extends AbstractSmell {
private List<SmellyElement> smellyElementList;

public ConditionalTestLogic() {
smellyElementList = new ArrayList<>();
}

/**
* Checks of 'Conditional Test Logic' smell
Expand All @@ -32,14 +24,6 @@ public String getSmellName() {
return "Conditional Test Logic";
}

/**
* Returns true if any of the elements has a smell
*/
@Override
public boolean getHasSmell() {
return smellyElementList.stream().filter(x -> x.getHasSmell()).count() >= 1;
}

/**
* Analyze the test file for test methods that use conditional statements
*/
Expand All @@ -50,15 +34,6 @@ public void runAnalysis(CompilationUnit testFileCompilationUnit, CompilationUnit
classVisitor.visit(testFileCompilationUnit, null);
}

/**
* Returns the set of analyzed elements (i.e. test methods)
*/
@Override
public List<SmellyElement> getSmellyElements() {
return smellyElementList;
}


private class ClassVisitor extends VoidVisitorAdapter<Void> {
private MethodDeclaration currentMethod = null;
private int conditionCount, ifCount, switchCount, forCount, foreachCount, whileCount = 0;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
package testsmell.smell;
package edu.rit.se.testsmells.smell;

import com.github.javaparser.ast.CompilationUnit;
import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration;
import com.github.javaparser.ast.body.ConstructorDeclaration;
import com.github.javaparser.ast.type.ClassOrInterfaceType;
import com.github.javaparser.ast.visitor.VoidVisitorAdapter;
import testsmell.AbstractSmell;
import testsmell.SmellyElement;
import testsmell.TestClass;
import edu.rit.se.testsmells.AbstractSmell;
import edu.rit.se.testsmells.TestClass;

import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.List;


/*
Expand All @@ -20,13 +17,8 @@ This class checks if the code file contains a Constructor. Ideally, the test sui
*/
public class ConstructorInitialization extends AbstractSmell {

private List<SmellyElement> smellyElementList;
private String testFileName;

public ConstructorInitialization() {
smellyElementList = new ArrayList<>();
}

/**
* Checks of 'Constructor Initialization' smell
*/
Expand All @@ -35,14 +27,6 @@ public String getSmellName() {
return "Constructor Initialization";
}

/**
* Returns true if any of the elements has a smell
*/
@Override
public boolean getHasSmell() {
return smellyElementList.stream().filter(x -> x.getHasSmell()).count() >= 1;
}

/**
* Analyze the test file for Constructor Initialization smell
*/
Expand All @@ -54,15 +38,6 @@ public void runAnalysis(CompilationUnit testFileCompilationUnit,CompilationUnit
classVisitor.visit(testFileCompilationUnit, null);
}

/**
* Returns the set of analyzed elements (i.e. test methods)
*/
@Override
public List<SmellyElement> getSmellyElements() {
return smellyElementList;
}


private class ClassVisitor extends VoidVisitorAdapter<Void> {
TestClass testClass;
boolean constructorAllowed=false;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,19 @@
package testsmell.smell;
package edu.rit.se.testsmells.smell;

import com.github.javaparser.ast.CompilationUnit;
import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration;
import com.github.javaparser.ast.visitor.VoidVisitorAdapter;
import testsmell.AbstractSmell;
import testsmell.SmellyElement;
import testsmell.TestClass;
import edu.rit.se.testsmells.AbstractSmell;
import edu.rit.se.testsmells.TestClass;

import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.List;

/*
By default Android Studio creates default test classes when a project is created. These classes are meant to serve as an example for developers when wring unit tests
This code marks the class as smelly if the class name corresponds to the name of the default test classes
*/
public class DefaultTest extends AbstractSmell {

private List<SmellyElement> smellyElementList;

public DefaultTest() {
smellyElementList = new ArrayList<>();
}

/**
* Checks of 'Default Test' smell
*/
Expand All @@ -31,29 +22,13 @@ public String getSmellName() {
return "Default Test";
}

/**
* Returns true if any of the elements has a smell
*/
@Override
public boolean getHasSmell() {
return smellyElementList.stream().filter(x -> x.getHasSmell()).count() >= 1;
}

@Override
public void runAnalysis(CompilationUnit testFileCompilationUnit,CompilationUnit productionFileCompilationUnit, String testFileName, String productionFileName) throws FileNotFoundException {
DefaultTest.ClassVisitor classVisitor;
classVisitor = new DefaultTest.ClassVisitor();
classVisitor.visit(testFileCompilationUnit, null);
}

/**
* Returns the set of analyzed elements (i.e. test methods)
*/
@Override
public List<SmellyElement> getSmellyElements() {
return smellyElementList;
}

private class ClassVisitor extends VoidVisitorAdapter<Void> {
TestClass testClass;

Expand Down
Loading