Skip to content

Commit

Permalink
Abstract Test Pattern for Parser
Browse files Browse the repository at this point in the history
  • Loading branch information
diridari committed Dec 7, 2017
1 parent 4ecba7e commit ccefbc5
Show file tree
Hide file tree
Showing 4 changed files with 140 additions and 113 deletions.
53 changes: 31 additions & 22 deletions src/test/java/edu/hm/hafner/analysis/parser/EclipseParserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,29 @@

import org.junit.jupiter.api.Test;

import edu.hm.hafner.analysis.AbstractParser;
import edu.hm.hafner.analysis.AbstractParserTest;
import edu.hm.hafner.analysis.Issue;
import edu.hm.hafner.analysis.Issues;
import edu.hm.hafner.analysis.Priority;
import edu.hm.hafner.analysis.assertj.SoftAssertions;
import static edu.hm.hafner.analysis.assertj.Assertions.*;
import static edu.hm.hafner.analysis.assertj.SoftAssertions.*;
import static edu.hm.hafner.analysis.parser.ParserTester.*;

/**
* Tests the class {@link EclipseParser}.
*/
class EclipseParserTest extends AbstractEclipseParserTest {
class EclipseParserTest extends AbstractParserTest {
private static final String CATEGORY = DEFAULT_CATEGORY;

/**
* Creates a new instance of {@link AbstractParserTest}.
*/
protected EclipseParserTest() {
super("issue6427.txt");
}

/**
* Parses a warning log with previously undetected warnings.
*
Expand Down Expand Up @@ -89,27 +100,6 @@ void issue12822() {
assertThat(warnings).hasSize(15);
}

/**
* Parses a warning log with a ClearCase command line that should not be parsed as a warning.
*
* @see <a href="http://issues.jenkins-ci.org/browse/JENKINS-6427">Issue 6427</a>
*/
@Test
void issue6427() {
Issues<Issue> warnings = createParser().parse(openFile("issue6427.txt"));

assertThat(warnings).hasSize(18);
assertSoftly(softly -> {
softly.assertThat(warnings.get(0))
.hasPriority(Priority.NORMAL)
.hasCategory(CATEGORY)
.hasLineStart(10)
.hasLineEnd(10)
.hasMessage("The import com.bombardier.oldinfra.export.dataAccess.InfrastructureDiagramAPI is never used")
.hasFileName("/srv/hudson/workspace/Ebitool Trunk/build/plugins/com.bombardier.oldInfra.export.jet/jet2java/org/eclipse/jet/compiled/_jet_infraSoe.java");
});
}

/**
* Parses a warning log with 2 eclipse messages, the affected source text spans one and two lines.
*
Expand Down Expand Up @@ -155,5 +145,24 @@ void issue7077all() {
number++;
}
}

@Override
protected void assertThatIssuesArePresent(final Issues<Issue> issues, final SoftAssertions softly) {
softly.assertThat(issues).hasSize(18);

softly.assertThat(issues.get(0))
.hasPriority(Priority.NORMAL)
.hasCategory(CATEGORY)
.hasLineStart(10)
.hasLineEnd(10)
.hasMessage("The import com.bombardier.oldinfra.export.dataAccess.InfrastructureDiagramAPI is never used")
.hasFileName("/srv/hudson/workspace/Ebitool Trunk/build/plugins/com.bombardier.oldInfra.export.jet/jet2java/org/eclipse/jet/compiled/_jet_infraSoe.java");

}

@Override
protected AbstractParser createParser() {
return new EclipseParser();
}
}

53 changes: 29 additions & 24 deletions src/test/java/edu/hm/hafner/analysis/parser/ErlcParserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,49 @@

import org.junit.jupiter.api.Test;

import edu.hm.hafner.analysis.AbstractParser;
import edu.hm.hafner.analysis.AbstractParserTest;
import edu.hm.hafner.analysis.Issue;
import edu.hm.hafner.analysis.Issues;
import edu.hm.hafner.analysis.Priority;
import edu.hm.hafner.analysis.assertj.SoftAssertions;
import static edu.hm.hafner.analysis.assertj.SoftAssertions.*;
import static org.assertj.core.api.Java6Assertions.*;

/**
* Tests the class {@link ErlcParser}.
*/
public class ErlcParserTest extends ParserTester {
public class ErlcParserTest extends AbstractParserTest {
/**
* Parses a file with two Erlc warnings.
* Creates a new instance of {@link AbstractParserTest}.
*/
@Test
public void testWarningsParser() {
Issues<Issue> issues = new ErlcParser().parse(openFile());

assertThat(issues).hasSize(2);

assertSoftly(softly -> {
softly.assertThat(issues.get(0)).hasPriority(Priority.NORMAL)
.hasCategory("Warning")
.hasLineStart(125)
.hasLineEnd(125)
.hasMessage("variable 'Name' is unused")
.hasFileName("./test.erl");
softly.assertThat(issues.get(1)).hasPriority(Priority.HIGH)
.hasCategory("Error")
.hasLineStart(175)
.hasLineEnd(175)
.hasMessage("record 'Extension' undefined")
.hasFileName("./test2.erl");
});
protected ErlcParserTest() {
super("erlc.txt");
}


@Override
protected void assertThatIssuesArePresent(final Issues<Issue> issues, final SoftAssertions softly) {
softly.assertThat(issues).hasSize(2);

softly.assertThat(issues.get(0)).hasPriority(Priority.NORMAL)
.hasCategory("Warning")
.hasLineStart(125)
.hasLineEnd(125)
.hasMessage("variable 'Name' is unused")
.hasFileName("./test.erl");
softly.assertThat(issues.get(1)).hasPriority(Priority.HIGH)
.hasCategory("Error")
.hasLineStart(175)
.hasLineEnd(175)
.hasMessage("record 'Extension' undefined")
.hasFileName("./test2.erl");

}

@Override
protected String getWarningsFile() {
return "erlc.txt";
protected AbstractParser createParser() {
return new ErlcParser();
}
}

89 changes: 48 additions & 41 deletions src/test/java/edu/hm/hafner/analysis/parser/FlexSDKParserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,64 +9,71 @@

import org.junit.jupiter.api.Test;

import edu.hm.hafner.analysis.AbstractParser;
import edu.hm.hafner.analysis.AbstractParserTest;
import edu.hm.hafner.analysis.Issue;
import edu.hm.hafner.analysis.Issues;
import edu.hm.hafner.analysis.Priority;
import edu.hm.hafner.analysis.assertj.SoftAssertions;
import static edu.hm.hafner.analysis.assertj.SoftAssertions.*;
import static edu.hm.hafner.analysis.parser.ParserTester.*;
import static org.assertj.core.api.Assertions.*;

/**
* Tests the class {@link FlexSDKParser}.
*/
public class FlexSDKParserTest extends ParserTester {
public class FlexSDKParserTest extends AbstractParserTest {
private static final String CATEGORY = DEFAULT_CATEGORY;

/**
* Parses a file with five warnings.
* Creates a new instance of {@link AbstractParserTest}.
*/
@Test
public void parseDeprecation() {
Issues<Issue> warnings = new FlexSDKParser().parse(openFile());
protected FlexSDKParserTest() {
super("flexsdk.txt");
}


@Override
protected void assertThatIssuesArePresent(final Issues<Issue> issues, final SoftAssertions softly) {
softly.assertThat(issues).hasSize(5);


assertThat(warnings).hasSize(5);
Iterator<Issue> iterator = issues.iterator();
softly.assertThat(iterator.next()).hasPriority(Priority.NORMAL)
.hasCategory(CATEGORY)
.hasLineStart(34)
.hasLineEnd(34)
.hasMessage("class 'FeedStructureHelper' will be scoped to the default namespace: com.company.flex.feed internal. It will not be visible outside of this package.")
.hasFileName("D:/workspaces/flexcompo_trunkdev_nightly/src/flexcompo/uicomponents/ugv_component/src/main/com/company/flex/feed/FeedStructureHelper.as");
softly.assertThat(iterator.next()).hasPriority(Priority.NORMAL)
.hasCategory(CATEGORY)
.hasLineStart(122)
.hasLineEnd(122)
.hasMessage("Duplicate variable definition.")
.hasFileName("D:/workspaces/flexcompo_trunkdev_nightly/src/flexcompo/uicomponents/ugv_component/src/main/com/company/flex/component/chart/lasso/DefaultLassoObjectsHandler.as");
softly.assertThat(iterator.next()).hasPriority(Priority.NORMAL)
.hasCategory(CATEGORY)
.hasLineStart(115)
.hasLineEnd(115)
.hasMessage("return value for function 'cx' has no type declaration.")
.hasFileName("D:/workspaces/flexcompo_trunkdev_nightly/src/flexcompo/samples/ugv_helloExtensibility_flex/src/main/extensibility/wordpress/Tag.as");
softly.assertThat(iterator.next()).hasPriority(Priority.NORMAL)
.hasCategory(CATEGORY)
.hasLineStart(157)
.hasLineEnd(157)
.hasMessage("var 'cacheList' will be scoped to the default namespace: HelloExtensibleWorld: internal. It will not be visible outside of this package.")
.hasFileName("D:/workspaces/flexcompo_trunkdev_nightly/src/flexcompo/samples/ugv_helloExtensibility_flex/src/main/HelloExtensibleWorld.mxml");
softly.assertThat(iterator.next()).hasPriority(Priority.NORMAL)
.hasCategory(CATEGORY)
.hasLineStart(148)
.hasLineEnd(148)
.hasMessage("The CSS type selector 'Book' was not processed, because the type was not used in the application.")
.hasFileName("D:/workspaces/flexcompo_trunkdev_nightly/src/flexcompo/samples/ugv_helloExtensibility_flex/src/main/HelloExtensibleWorld.mxml");

assertSoftly(softly -> {
Iterator<Issue> iterator = warnings.iterator();
softly.assertThat(iterator.next()).hasPriority(Priority.NORMAL)
.hasCategory(CATEGORY)
.hasLineStart(34)
.hasLineEnd(34)
.hasMessage("class 'FeedStructureHelper' will be scoped to the default namespace: com.company.flex.feed internal. It will not be visible outside of this package.")
.hasFileName("D:/workspaces/flexcompo_trunkdev_nightly/src/flexcompo/uicomponents/ugv_component/src/main/com/company/flex/feed/FeedStructureHelper.as");
softly.assertThat(iterator.next()).hasPriority(Priority.NORMAL)
.hasCategory(CATEGORY)
.hasLineStart(122)
.hasLineEnd(122)
.hasMessage("Duplicate variable definition.")
.hasFileName("D:/workspaces/flexcompo_trunkdev_nightly/src/flexcompo/uicomponents/ugv_component/src/main/com/company/flex/component/chart/lasso/DefaultLassoObjectsHandler.as");
softly.assertThat(iterator.next()).hasPriority(Priority.NORMAL)
.hasCategory(CATEGORY)
.hasLineStart(115)
.hasLineEnd(115)
.hasMessage("return value for function 'cx' has no type declaration.")
.hasFileName("D:/workspaces/flexcompo_trunkdev_nightly/src/flexcompo/samples/ugv_helloExtensibility_flex/src/main/extensibility/wordpress/Tag.as");
softly.assertThat(iterator.next()).hasPriority(Priority.NORMAL)
.hasCategory(CATEGORY)
.hasLineStart(157)
.hasLineEnd(157)
.hasMessage("var 'cacheList' will be scoped to the default namespace: HelloExtensibleWorld: internal. It will not be visible outside of this package.")
.hasFileName("D:/workspaces/flexcompo_trunkdev_nightly/src/flexcompo/samples/ugv_helloExtensibility_flex/src/main/HelloExtensibleWorld.mxml");
softly.assertThat(iterator.next()).hasPriority(Priority.NORMAL)
.hasCategory(CATEGORY)
.hasLineStart(148)
.hasLineEnd(148)
.hasMessage("The CSS type selector 'Book' was not processed, because the type was not used in the application.")
.hasFileName("D:/workspaces/flexcompo_trunkdev_nightly/src/flexcompo/samples/ugv_helloExtensibility_flex/src/main/HelloExtensibleWorld.mxml");
});
}

@Override
protected String getWarningsFile() {
return "flexsdk.txt";
protected AbstractParser createParser() {
return new FlexSDKParser();
}
}
58 changes: 32 additions & 26 deletions src/test/java/edu/hm/hafner/analysis/parser/FxcopParserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@

import org.junit.jupiter.api.Test;

import edu.hm.hafner.analysis.AbstractParser;
import edu.hm.hafner.analysis.AbstractParserTest;
import edu.hm.hafner.analysis.Issue;
import edu.hm.hafner.analysis.Issues;
import edu.hm.hafner.analysis.Priority;
import static edu.hm.hafner.analysis.assertj.SoftAssertions.*;
import edu.hm.hafner.analysis.assertj.SoftAssertions;
import edu.hm.hafner.analysis.parser.fxcop.FxCopParser;
import static org.assertj.core.api.Assertions.*;

Expand All @@ -14,7 +17,14 @@
*
* @author Ullrich Hafner
*/
public class FxcopParserTest extends ParserTester {
public class FxcopParserTest extends AbstractParserTest {
/**
* Creates a new instance of {@link AbstractParserTest}.
*/
protected FxcopParserTest() {
super("fxcop.xml");
}

/**
* Verifies that the FXCop parser works as expected.
*/
Expand All @@ -25,34 +35,30 @@ public void testJenkins14172() {
assertThat(result).hasSize(44);
}

/**
* Verifies that the FXCop parser works as expected.
*/
@Test
public void testFXCop() {
Issues<Issue> result = new FxCopParser().parse(openFile());

assertThat(result).hasSize(2);

assertSoftly(softly -> {
softly.assertThat(result.get(0)).hasPriority(Priority.HIGH)
.hasCategory("Microsoft.Globalization")
.hasLineStart(299)
.hasLineEnd(299)
.hasMessage("<a href=\"http://msdn2.microsoft.com/library/ms182190(VS.90).aspx\">SpecifyIFormatProvider</a> - Because the behavior of 'decimal.ToString(string)' could vary based on the current user's locale settings, replace this call in 'FilmFacadeBase.Price.get()' with a call to 'decimal.ToString(string, IFormatProvider)'. If the result of 'decimal.ToString(string, IFormatProvider)' will be displayed to the user, specify 'CultureInfo.CurrentCulture' as the 'IFormatProvider' parameter. Otherwise, if the result will be stored and accessed by software, such as when it is persisted to disk or to a database, specify 'CultureInfo.InvariantCulture'.")
.hasFileName("c:/Hudson/data/jobs/job1/workspace/test/Space/TestBase.cs");
softly.assertThat(result.get(1)).hasPriority(Priority.HIGH)
.hasCategory("Microsoft.Naming")
.hasLineStart(37)
.hasLineEnd(37)
.hasMessage("<a href=\"http://msdn2.microsoft.com/library/bb264474(VS.90).aspx\">CompoundWordsShouldBeCasedCorrectly</a> - In member 'MyControl.InitialParameters(bool)', the discrete term 'javascript' in parameter name 'javascript' should be expressed as a compound word, 'javaScript'.")
.hasFileName("c:/Hudson/data/jobs/job1/workspace/web/UserControls/MyControl.ascx.cs");
});

@Override
protected void assertThatIssuesArePresent(final Issues<Issue> issues, final SoftAssertions softly) {
softly.assertThat(issues).hasSize(2);

softly.assertThat(issues.get(0)).hasPriority(Priority.HIGH)
.hasCategory("Microsoft.Globalization")
.hasLineStart(299)
.hasLineEnd(299)
.hasMessage("<a href=\"http://msdn2.microsoft.com/library/ms182190(VS.90).aspx\">SpecifyIFormatProvider</a> - Because the behavior of 'decimal.ToString(string)' could vary based on the current user's locale settings, replace this call in 'FilmFacadeBase.Price.get()' with a call to 'decimal.ToString(string, IFormatProvider)'. If the result of 'decimal.ToString(string, IFormatProvider)' will be displayed to the user, specify 'CultureInfo.CurrentCulture' as the 'IFormatProvider' parameter. Otherwise, if the result will be stored and accessed by software, such as when it is persisted to disk or to a database, specify 'CultureInfo.InvariantCulture'.")
.hasFileName("c:/Hudson/data/jobs/job1/workspace/test/Space/TestBase.cs");
softly.assertThat(issues.get(1)).hasPriority(Priority.HIGH)
.hasCategory("Microsoft.Naming")
.hasLineStart(37)
.hasLineEnd(37)
.hasMessage("<a href=\"http://msdn2.microsoft.com/library/bb264474(VS.90).aspx\">CompoundWordsShouldBeCasedCorrectly</a> - In member 'MyControl.InitialParameters(bool)', the discrete term 'javascript' in parameter name 'javascript' should be expressed as a compound word, 'javaScript'.")
.hasFileName("c:/Hudson/data/jobs/job1/workspace/web/UserControls/MyControl.ascx.cs");

}

@Override
protected String getWarningsFile() {
return "fxcop.xml";
protected AbstractParser createParser() {
return new FxCopParser();
}

}

0 comments on commit ccefbc5

Please sign in to comment.