Skip to content

Commit b1d254c

Browse files
Merge branch 'main' into feat/CBO
# Conflicts: # cost-benefit-calculator/src/test/java/org/hjug/cbc/CostBenefitCalculatorTest.java # effort-ranker/src/test/java/org/hjug/metrics/CBOClassParsingTest.java # effort-ranker/src/test/java/org/hjug/metrics/CBORuleRunnerTest.java # graph-data-generator/src/test/java/org/hjug/gdg/GraphDataGeneratorTest.java
2 parents 7a8e6fd + 8baf5c9 commit b1d254c

File tree

13 files changed

+180
-226
lines changed

13 files changed

+180
-226
lines changed
Lines changed: 9 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,22 @@
1+
# This workflow was added by CodeSee. Learn more at https://codesee.io/
2+
# This is v2.0 of this workflow file
13
on:
24
push:
35
branches:
46
- main
57
pull_request_target:
68
types: [opened, synchronize, reopened]
79

8-
name: CodeSee Map
10+
name: CodeSee
11+
12+
permissions: read-all
913

1014
jobs:
11-
test_map_action:
15+
codesee:
1216
runs-on: ubuntu-latest
1317
continue-on-error: true
14-
name: Run CodeSee Map Analysis
18+
name: Analyze the repo with CodeSee
1519
steps:
16-
- name: checkout
17-
id: checkout
18-
uses: actions/checkout@v2
19-
with:
20-
repository: ${{ github.event.pull_request.head.repo.full_name }}
21-
ref: ${{ github.event.pull_request.head.ref }}
22-
fetch-depth: 0
23-
24-
# codesee-detect-languages has an output with id languages.
25-
- name: Detect Languages
26-
id: detect-languages
27-
uses: Codesee-io/codesee-detect-languages-action@latest
28-
29-
- name: Configure JDK 16
30-
uses: actions/setup-java@v2
31-
if: ${{ fromJSON(steps.detect-languages.outputs.languages).java }}
32-
with:
33-
java-version: '16'
34-
distribution: 'zulu'
35-
36-
# CodeSee Maps Go support uses a static binary so there's no setup step required.
37-
38-
- name: Configure Node.js 14
39-
uses: actions/setup-node@v2
40-
if: ${{ fromJSON(steps.detect-languages.outputs.languages).javascript }}
41-
with:
42-
node-version: '14'
43-
44-
- name: Configure Python 3.x
45-
uses: actions/setup-python@v2
46-
if: ${{ fromJSON(steps.detect-languages.outputs.languages).python }}
47-
with:
48-
python-version: '3.x'
49-
architecture: 'x64'
50-
51-
- name: Configure Ruby '3.x'
52-
uses: ruby/setup-ruby@v1
53-
if: ${{ fromJSON(steps.detect-languages.outputs.languages).ruby }}
54-
with:
55-
ruby-version: '3.0'
56-
57-
# CodeSee Maps Rust support uses a static binary so there's no setup step required.
58-
59-
- name: Generate Map
60-
id: generate-map
61-
uses: Codesee-io/codesee-map-action@latest
62-
with:
63-
step: map
64-
github_ref: ${{ github.ref }}
65-
languages: ${{ steps.detect-languages.outputs.languages }}
66-
67-
- name: Upload Map
68-
id: upload-map
69-
uses: Codesee-io/codesee-map-action@latest
70-
with:
71-
step: mapUpload
72-
api_token: ${{ secrets.CODESEE_ARCH_DIAG_API_TOKEN }}
73-
github_ref: ${{ github.ref }}
74-
75-
- name: Insights
76-
id: insights
77-
uses: Codesee-io/codesee-map-action@latest
20+
- uses: Codesee-io/codesee-action@v2
7821
with:
79-
step: insights
80-
api_token: ${{ secrets.CODESEE_ARCH_DIAG_API_TOKEN }}
81-
github_ref: ${{ github.ref }}
22+
codesee-token: ${{ secrets.CODESEE_ARCH_DIAG_API_TOKEN }}

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ There is still much to be done. Your feedback and collaboration would be greatl
6767
If you find this plugin useful, please star this repository and share with your friends & colleagues and on social media.
6868

6969
## Future Plans
70-
* Move from JUnit 4 to Junit 5. Junit 5 is lacking the support for temporary files that JUnit 4 provides.
7170
* Add a Gradle plugin.
7271
* Incorporate Unit Test coverage metrics to quickly identify the safety of refactoring a God class.
7372
* Incorporate bug counts per God class to the Impact (Y-Axis) calculation.

change-proneness-ranker/src/test/java/org/hjug/git/ChangePronenessRankerTest.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,24 @@
77
import java.io.IOException;
88
import java.util.*;
99
import org.eclipse.jgit.api.errors.GitAPIException;
10-
import org.junit.Assert;
11-
import org.junit.Before;
12-
import org.junit.Test;
10+
import org.junit.jupiter.api.Assertions;
11+
import org.junit.jupiter.api.BeforeEach;
12+
import org.junit.jupiter.api.Test;
1313

1414
public class ChangePronenessRankerTest {
1515

1616
private ChangePronenessRanker changePronenessRanker;
1717
private RepositoryLogReader repositoryLogReader;
1818

19-
@Before
19+
@BeforeEach
2020
public void setUp() {
2121
repositoryLogReader = mock(RepositoryLogReader.class);
2222
changePronenessRanker = new ChangePronenessRanker(null, repositoryLogReader);
2323
}
2424

2525
// TODO: this should probably be a cucumber test
2626
@Test
27-
public void testChangePronenessCalculation() throws IOException, GitAPIException {
27+
void testChangePronenessCalculation() throws IOException, GitAPIException {
2828
ScmLogInfo scmLogInfo = new ScmLogInfo("path", 1595275997, 0, 1);
2929

3030
TreeMap<Integer, Integer> commitsWithChangeCounts = new TreeMap<>();
@@ -39,11 +39,11 @@ public void testChangePronenessCalculation() throws IOException, GitAPIException
3939
changePronenessRanker.rankChangeProneness(scmLogInfos);
4040

4141
// 1 commit of a class we're interested in, 6 commits of other files after it
42-
Assert.assertEquals((float) 1 / 7, scmLogInfo.getChangeProneness(), 0.1);
42+
Assertions.assertEquals((float) 1 / 7, scmLogInfo.getChangeProneness(), 0.1);
4343
}
4444

4545
@Test
46-
public void testRankChangeProneness() throws IOException, GitAPIException {
46+
void testRankChangeProneness() throws IOException, GitAPIException {
4747
ScmLogInfo scmLogInfo = new ScmLogInfo("file1", 1595275997, 0, 1);
4848

4949
TreeMap<Integer, Integer> commitsWithChangeCounts = new TreeMap<>();
@@ -65,8 +65,8 @@ public void testRankChangeProneness() throws IOException, GitAPIException {
6565
changePronenessRanker.rankChangeProneness(scmLogInfos);
6666

6767
// ranks higher since fewer commits since initial commit
68-
Assert.assertEquals(2, scmLogInfo.getChangePronenessRank());
68+
Assertions.assertEquals(2, scmLogInfo.getChangePronenessRank());
6969
// ranks lower since there have been more commits since initial commit
70-
Assert.assertEquals(1, scmLogInfo2.getChangePronenessRank());
70+
Assertions.assertEquals(1, scmLogInfo2.getChangePronenessRank());
7171
}
7272
}

change-proneness-ranker/src/test/java/org/hjug/git/GitLogReaderTest.java

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,32 +8,35 @@
88
import org.eclipse.jgit.api.errors.GitAPIException;
99
import org.eclipse.jgit.lib.Repository;
1010
import org.eclipse.jgit.revwalk.RevCommit;
11-
import org.junit.*;
12-
import org.junit.rules.TemporaryFolder;
11+
import org.junit.jupiter.api.AfterEach;
12+
import org.junit.jupiter.api.Assertions;
13+
import org.junit.jupiter.api.BeforeEach;
14+
import org.junit.jupiter.api.Test;
15+
import org.junit.jupiter.api.io.TempDir;
1316

1417
public class GitLogReaderTest {
1518
// Borrowed bits and pieces from
1619
// https://gist.github.com/rherrmann/0c682ea327862cb6847704acf90b1d5d
1720

18-
@Rule
19-
public TemporaryFolder tempFolder = new TemporaryFolder();
21+
@TempDir
22+
public File tempFolder;
2023

2124
private Git git;
2225
private Repository repository;
2326

24-
@Before
27+
@BeforeEach
2528
public void setUp() throws GitAPIException {
26-
git = Git.init().setDirectory(tempFolder.getRoot()).call();
29+
git = Git.init().setDirectory(tempFolder).call();
2730
repository = git.getRepository();
2831
}
2932

30-
@After
33+
@AfterEach
3134
public void tearDown() {
3235
repository.close();
3336
}
3437

3538
@Test
36-
public void testFileLog() throws IOException, GitAPIException, InterruptedException {
39+
void testFileLog() throws IOException, GitAPIException, InterruptedException {
3740
// This path works when referencing the full Tobago repository
3841
// String filePath = "tobago-core/src/main/java/org/apache/myfaces/tobago/facelets/AttributeHandler.java";
3942

@@ -58,13 +61,13 @@ public void testFileLog() throws IOException, GitAPIException, InterruptedExcept
5861

5962
ScmLogInfo scmLogInfo = gitLogReader.fileLog(repository, attributeHandler);
6063

61-
Assert.assertEquals(2, scmLogInfo.getCommitCount());
62-
Assert.assertEquals(firstCommit.getCommitTime(), scmLogInfo.getEarliestCommit());
63-
Assert.assertEquals(secondCommit.getCommitTime(), scmLogInfo.getMostRecentCommit());
64+
Assertions.assertEquals(2, scmLogInfo.getCommitCount());
65+
Assertions.assertEquals(firstCommit.getCommitTime(), scmLogInfo.getEarliestCommit());
66+
Assertions.assertEquals(secondCommit.getCommitTime(), scmLogInfo.getMostRecentCommit());
6467
}
6568

6669
@Test
67-
public void testWalkFirstCommit() throws IOException, GitAPIException {
70+
void testWalkFirstCommit() throws IOException, GitAPIException {
6871
GitLogReader gitLogReader = new GitLogReader();
6972

7073
String attributeHandler = "AttributeHandler.java";
@@ -75,12 +78,12 @@ public void testWalkFirstCommit() throws IOException, GitAPIException {
7578

7679
Map<Integer, Integer> result = gitLogReader.walkFirstCommit(repository, commit);
7780

78-
Assert.assertTrue(result.containsKey(commit.getCommitTime()));
79-
Assert.assertEquals(1, result.get(commit.getCommitTime()).intValue());
81+
Assertions.assertTrue(result.containsKey(commit.getCommitTime()));
82+
Assertions.assertEquals(1, result.get(commit.getCommitTime()).intValue());
8083
}
8184

8285
@Test
83-
public void testCaptureChangCountByCommitTimestamp() throws Exception {
86+
void testCaptureChangCountByCommitTimestamp() throws Exception {
8487
GitLogReader gitLogReader = new GitLogReader();
8588

8689
String attributeHandler = "AttributeHandler.java";
@@ -105,8 +108,9 @@ public void testCaptureChangCountByCommitTimestamp() throws Exception {
105108

106109
Map<Integer, Integer> commitCounts = gitLogReader.captureChangeCountByCommitTimestamp(repository);
107110

108-
Assert.assertEquals(1, commitCounts.get(firstCommit.getCommitTime()).intValue());
109-
Assert.assertEquals(2, commitCounts.get(secondCommit.getCommitTime()).intValue());
111+
Assertions.assertEquals(1, commitCounts.get(firstCommit.getCommitTime()).intValue());
112+
Assertions.assertEquals(
113+
2, commitCounts.get(secondCommit.getCommitTime()).intValue());
110114
}
111115

112116
private void writeFile(String name, String content) throws IOException {

cost-benefit-calculator/src/test/java/org/hjug/cbc/CostBenefitCalculatorTest.java

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,30 +11,33 @@
1111
import org.hjug.git.GitLogReader;
1212
import org.hjug.metrics.GodClass;
1313
import org.hjug.metrics.PMDGodClassRuleRunner;
14-
import org.junit.*;
15-
import org.junit.rules.TemporaryFolder;
14+
import org.junit.jupiter.api.AfterEach;
15+
import org.junit.jupiter.api.Assertions;
16+
import org.junit.jupiter.api.BeforeEach;
17+
import org.junit.jupiter.api.Test;
18+
import org.junit.jupiter.api.io.TempDir;
1619

1720
public class CostBenefitCalculatorTest {
1821

19-
@Rule
20-
public TemporaryFolder tempFolder = new TemporaryFolder();
22+
@TempDir
23+
public File tempFolder;
2124

2225
private Git git;
2326
private Repository repository;
2427

25-
@Before
28+
@BeforeEach
2629
public void setUp() throws GitAPIException {
27-
git = Git.init().setDirectory(tempFolder.getRoot()).call();
30+
git = Git.init().setDirectory(tempFolder).call();
2831
repository = git.getRepository();
2932
}
3033

31-
@After
34+
@AfterEach
3235
public void tearDown() {
3336
repository.close();
3437
}
3538

3639
@Test
37-
public void testCostBenefitCalculation() throws IOException, GitAPIException, InterruptedException {
40+
void testCostBenefitCalculation() throws IOException, GitAPIException, InterruptedException {
3841
String attributeHandler = "AttributeHandler.java";
3942
InputStream resourceAsStream = getClass().getClassLoader().getResourceAsStream(attributeHandler);
4043
writeFile(attributeHandler, convertInputStreamToString(resourceAsStream));
@@ -60,12 +63,12 @@ public void testCostBenefitCalculation() throws IOException, GitAPIException, In
6063
List<RankedDisharmony> disharmonies = costBenefitCalculator.calculateGodClassCostBenefitValues(
6164
git.getRepository().getDirectory().getPath());
6265

63-
Assert.assertEquals(0, disharmonies.get(0).getRawPriority().intValue());
64-
Assert.assertEquals(0, disharmonies.get(1).getRawPriority().intValue());
66+
Assertions.assertEquals(0, disharmonies.get(0).getPriority().intValue());
67+
Assertions.assertEquals(0, disharmonies.get(1).getPriority().intValue());
6568
}
6669

6770
@Test
68-
public void scanClassesInRepo2() throws IOException, GitAPIException {
71+
void scanClassesInRepo2() throws IOException, GitAPIException {
6972
String attributeHandler = "AttributeHandler.java";
7073
InputStream resourceAsStream = getClass().getClassLoader().getResourceAsStream(attributeHandler);
7174
writeFile(attributeHandler, convertInputStreamToString(resourceAsStream));
@@ -86,11 +89,11 @@ public void scanClassesInRepo2() throws IOException, GitAPIException {
8689
godClassOptional.ifPresent(godClass -> godClasses.put(filePath, godClass));
8790
}
8891

89-
Assert.assertFalse(godClasses.isEmpty());
92+
Assertions.assertFalse(godClasses.isEmpty());
9093
}
9194

9295
@Test
93-
public void scanClassesInRepo() throws IOException, GitAPIException {
96+
void scanClassesInRepo() throws IOException, GitAPIException {
9497
String attributeHandler = "AttributeHandler.java";
9598
InputStream resourceAsStream = getClass().getClassLoader().getResourceAsStream(attributeHandler);
9699
writeFile(attributeHandler, convertInputStreamToString(resourceAsStream));
@@ -111,7 +114,7 @@ public void scanClassesInRepo() throws IOException, GitAPIException {
111114
godClassOptional.ifPresent(godClass -> godClasses.put(filePath, godClass));
112115
}
113116

114-
Assert.assertFalse(godClasses.isEmpty());
117+
Assertions.assertFalse(godClasses.isEmpty());
115118
}
116119

117120
private void writeFile(String name, String content) throws IOException {

effort-ranker/src/test/java/org/hjug/metrics/CBOClassParsingTest.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11
package org.hjug.metrics;
22

3-
import static org.junit.Assert.assertEquals;
3+
import static org.junit.jupiter.api.Assertions.assertEquals;
44

55
import java.util.Locale;
6-
import org.junit.After;
7-
import org.junit.Before;
8-
import org.junit.Test;
6+
import org.junit.jupiter.api.AfterEach;
7+
import org.junit.jupiter.api.BeforeEach;
8+
import org.junit.jupiter.api.Test;
99

1010
public class CBOClassParsingTest {
1111

1212
private Locale defaultLocale;
1313

14-
@Before
14+
@BeforeEach
1515
public void before() {
1616
defaultLocale = Locale.getDefault(Locale.Category.FORMAT);
1717
Locale.setDefault(Locale.Category.FORMAT, Locale.ENGLISH);
1818
}
1919

20-
@After
20+
@AfterEach
2121
public void after() {
2222
Locale.setDefault(defaultLocale);
2323
}
2424

2525
@Test
26-
public void test() {
26+
void test() {
2727
String result = "A value of 20 may denote a high amount of coupling within the class";
2828
CBOClass cboClass = new CBOClass("a", "a.txt", "org.hjug", result);
2929
assertEquals(Integer.valueOf(20), cboClass.getCouplingCount());

0 commit comments

Comments
 (0)