-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
172 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
src/test/java/org/jenkinsci/plugins/vs_code_metrics/util/CodeMetricsUtilTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package org.jenkinsci.plugins.vs_code_metrics.util; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
import java.io.File; | ||
|
||
import hudson.FilePath; | ||
|
||
import org.jenkinsci.plugins.vs_code_metrics.bean.*; | ||
import org.junit.Test; | ||
|
||
public class CodeMetricsUtilTest { | ||
|
||
@Test | ||
public void testCreateCodeMetrics() throws Exception { | ||
File file = new File(this.getClass().getResource("test_createbean.xml").getPath()); | ||
FilePath path = new FilePath(file); | ||
|
||
CodeMetrics bean = CodeMetricsUtil.createCodeMetrics(path); | ||
|
||
assertNotNull(bean); | ||
assertEquals(2, bean.getChildren().size()); | ||
} | ||
|
||
@Test | ||
public void testSaveReports() throws Exception { | ||
File file = new File(this.getClass().getResource("test_save.xml").getPath()); | ||
FilePath folder = new FilePath(file.getParentFile()); | ||
FilePath[] files = new FilePath[1]; | ||
files[0] = new FilePath(file); | ||
|
||
boolean r = CodeMetricsUtil.saveReports(folder, files); | ||
assertTrue("saveReports method success.", r); | ||
} | ||
|
||
@Test | ||
public void testSearchBean() throws Exception { | ||
File file = new File(this.getClass().getResource("test_createbean.xml").getPath()); | ||
FilePath path = new FilePath(file); | ||
|
||
CodeMetrics bean = CodeMetricsUtil.createCodeMetrics(path); | ||
|
||
AbstractBean<?> result = CodeMetricsUtil.searchBean(bean, new String[0]); | ||
assertEquals(bean, result); | ||
|
||
Module module = bean.getChildren().get("CodeMetricsTest.exe"); | ||
result = CodeMetricsUtil.searchBean(bean, new String[] { "CodeMetricsTest.exe" }); | ||
assertEquals(module, result); | ||
|
||
result = CodeMetricsUtil.searchBean(bean, new String[] { "dummy" }); | ||
assertNull(result); | ||
|
||
Namespace namespace = module.getChildren().get("CodeMetricsTest"); | ||
result = CodeMetricsUtil.searchBean(bean, new String[] { "CodeMetricsTest.exe", "CodeMetricsTest" }); | ||
assertEquals(namespace, result); | ||
|
||
Type type = namespace.getChildren().get("Program"); | ||
result = CodeMetricsUtil.searchBean(bean, new String[] { "CodeMetricsTest.exe", "CodeMetricsTest", "Program" }); | ||
assertEquals(type, result); | ||
assertEquals(2, result.getChildren().size()); | ||
assertEquals(100, type.getMaintainabilityIndex()); | ||
|
||
} | ||
} |
1 change: 1 addition & 0 deletions
1
src/test/resources/org/jenkinsci/plugins/vs_code_metrics/util/test_createbean.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<?xml version="1.0" encoding="UTF-8"?><report><module loc="1" doi="1" cls="0" cyc="2" mi="100" name="CodeMetricsTest.exe"><namespace loc="1" doi="1" cls="0" cyc="2" mi="100" name="CodeMetricsTest"><type loc="1" doi="1" cls="0" cyc="2" mi="100" name="Program"><member loc="0" cls="0" cyc="1" mi="100" name="Main(string[]) : void"/><member loc="1" cls="0" cyc="1" mi="100" name="Program()"/></type></namespace></module><module loc="1" doi="1" cls="0" cyc="3" mi="90" name="CodeMetricsTest2.exe"><namespace loc="1" doi="1" cls="0" cyc="3" mi="95" name="CodeMetricsTest2"><type loc="1" doi="1" cls="0" cyc="3" mi="90" name="Program"><member loc="0" cls="0" cyc="3" mi="88" name="Main(string[]) : void"/><member loc="1" cls="0" cyc="2" mi="92" name="Program()"/></type></namespace></module></report> |
107 changes: 107 additions & 0 deletions
107
src/test/resources/org/jenkinsci/plugins/vs_code_metrics/util/test_save.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<CodeMetricsReport Version="10.0"> | ||
<Targets> | ||
<Target Name="C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop\CodeMetricsTest.exe"> | ||
<Modules> | ||
<Module Name="CodeMetricsTest.exe" AssemblyVersion="1.0.0.0" FileVersion="1.0.0.0"> | ||
<Metrics> | ||
<Metric Name="MaintainabilityIndex" Value="100" /> | ||
<Metric Name="CyclomaticComplexity" Value="2" /> | ||
<Metric Name="ClassCoupling" Value="0" /> | ||
<Metric Name="DepthOfInheritance" Value="1" /> | ||
<Metric Name="LinesOfCode" Value="1" /> | ||
</Metrics> | ||
<Namespaces> | ||
<Namespace Name="CodeMetricsTest"> | ||
<Metrics> | ||
<Metric Name="MaintainabilityIndex" Value="100" /> | ||
<Metric Name="CyclomaticComplexity" Value="2" /> | ||
<Metric Name="ClassCoupling" Value="0" /> | ||
<Metric Name="DepthOfInheritance" Value="1" /> | ||
<Metric Name="LinesOfCode" Value="1" /> | ||
</Metrics> | ||
<Types> | ||
<Type Name="Program"> | ||
<Metrics> | ||
<Metric Name="MaintainabilityIndex" Value="100" /> | ||
<Metric Name="CyclomaticComplexity" Value="2" /> | ||
<Metric Name="ClassCoupling" Value="0" /> | ||
<Metric Name="DepthOfInheritance" Value="1" /> | ||
<Metric Name="LinesOfCode" Value="1" /> | ||
</Metrics> | ||
<Members> | ||
<Member Name="Main(string[]) : void" File="D:\CodeMetricsTest\Program.cs" Line="11"> | ||
<Metrics> | ||
<Metric Name="MaintainabilityIndex" Value="100" /> | ||
<Metric Name="CyclomaticComplexity" Value="1" /> | ||
<Metric Name="ClassCoupling" Value="0" /> | ||
<Metric Name="LinesOfCode" Value="0" /> | ||
</Metrics> | ||
</Member> | ||
<Member Name="Program()"> | ||
<Metrics> | ||
<Metric Name="MaintainabilityIndex" Value="100" /> | ||
<Metric Name="CyclomaticComplexity" Value="1" /> | ||
<Metric Name="ClassCoupling" Value="0" /> | ||
<Metric Name="LinesOfCode" Value="1" /> | ||
</Metrics> | ||
</Member> | ||
</Members> | ||
</Type> | ||
</Types> | ||
</Namespace> | ||
</Namespaces> | ||
</Module> | ||
<Module Name="CodeMetricsTest2.exe" AssemblyVersion="1.0.0.0" FileVersion="1.0.0.0"> | ||
<Metrics> | ||
<Metric Name="MaintainabilityIndex" Value="90" /> | ||
<Metric Name="CyclomaticComplexity" Value="3" /> | ||
<Metric Name="ClassCoupling" Value="0" /> | ||
<Metric Name="DepthOfInheritance" Value="1" /> | ||
<Metric Name="LinesOfCode" Value="1" /> | ||
</Metrics> | ||
<Namespaces> | ||
<Namespace Name="CodeMetricsTest2"> | ||
<Metrics> | ||
<Metric Name="MaintainabilityIndex" Value="95" /> | ||
<Metric Name="CyclomaticComplexity" Value="3" /> | ||
<Metric Name="ClassCoupling" Value="0" /> | ||
<Metric Name="DepthOfInheritance" Value="1" /> | ||
<Metric Name="LinesOfCode" Value="1" /> | ||
</Metrics> | ||
<Types> | ||
<Type Name="Program"> | ||
<Metrics> | ||
<Metric Name="MaintainabilityIndex" Value="90" /> | ||
<Metric Name="CyclomaticComplexity" Value="3" /> | ||
<Metric Name="ClassCoupling" Value="0" /> | ||
<Metric Name="DepthOfInheritance" Value="1" /> | ||
<Metric Name="LinesOfCode" Value="1" /> | ||
</Metrics> | ||
<Members> | ||
<Member Name="Main(string[]) : void" File="D:\CodeMetricsTest2\Program.cs" Line="11"> | ||
<Metrics> | ||
<Metric Name="MaintainabilityIndex" Value="88" /> | ||
<Metric Name="CyclomaticComplexity" Value="3" /> | ||
<Metric Name="ClassCoupling" Value="0" /> | ||
<Metric Name="LinesOfCode" Value="0" /> | ||
</Metrics> | ||
</Member> | ||
<Member Name="Program()"> | ||
<Metrics> | ||
<Metric Name="MaintainabilityIndex" Value="92" /> | ||
<Metric Name="CyclomaticComplexity" Value="2" /> | ||
<Metric Name="ClassCoupling" Value="0" /> | ||
<Metric Name="LinesOfCode" Value="1" /> | ||
</Metrics> | ||
</Member> | ||
</Members> | ||
</Type> | ||
</Types> | ||
</Namespace> | ||
</Namespaces> | ||
</Module> | ||
</Modules> | ||
</Target> | ||
</Targets> | ||
</CodeMetricsReport> |