Skip to content

Commit bd2cb8e

Browse files
Merge pull request #10 from henri-tremblay/godbless-locale-issue
Parse using locale to match AbstractRuleViolationFactory formatting
2 parents 14a4235 + ffc9bdd commit bd2cb8e

File tree

2 files changed

+51
-4
lines changed

2 files changed

+51
-4
lines changed

effort-ranker/src/main/java/org/hjug/metrics/GodClass.java

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
import lombok.Data;
44

5+
import java.text.NumberFormat;
6+
import java.text.ParseException;
7+
58
/**
69
* Created by Jim on 11/16/2016.
710
*/
@@ -24,11 +27,20 @@ public GodClass(String fileName, String packageName, String result) {
2427
this.fileName = fileName;
2528
this.packageName = packageName;
2629

27-
//null (WMC=79, ATFD=79, TCC=0.027777777777777776)
30+
NumberFormat integerFormat = NumberFormat.getIntegerInstance();
31+
2832
String [] values = result.substring(result.indexOf("(") + 1, result.indexOf(")")).split(", ");
29-
wmc = Integer.valueOf(values[0].split("=")[1]);
30-
atfd = Integer.valueOf(values[1].split("=")[1]);
31-
String rawTcc = values[2].split("=")[1];
33+
try {
34+
wmc = (int) (long) integerFormat.parse(extractValue(values[0]));
35+
atfd = (int) (long) integerFormat.parse(extractValue(values[1]));
36+
} catch (ParseException e) {
37+
throw new RuntimeException(e);
38+
}
39+
String rawTcc = extractValue(values[2]);
3240
tcc = Float.valueOf(rawTcc.replace("%", ""));
3341
}
42+
43+
private String extractValue(String value) {
44+
return value.split("=")[1];
45+
}
3446
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package org.hjug.metrics;
2+
3+
import org.junit.After;
4+
import org.junit.Before;
5+
import org.junit.Test;
6+
7+
import java.util.Locale;
8+
9+
import static org.junit.Assert.assertEquals;
10+
11+
public class GodClassParsingTest {
12+
13+
private Locale defaultLocale;
14+
15+
@Before
16+
public void before() {
17+
defaultLocale = Locale.getDefault(Locale.Category.FORMAT);
18+
Locale.setDefault(Locale.Category.FORMAT, Locale.ENGLISH);
19+
}
20+
21+
@After
22+
public void after() {
23+
Locale.setDefault(defaultLocale);
24+
}
25+
26+
@Test
27+
public void test() {
28+
String result = "Possible God Class (WMC=9200, ATFD=1,700, TCC=4.597%)";
29+
GodClass god = new GodClass("a.txt", "org.hjug", result);
30+
assertEquals(Integer.valueOf(9200), god.getWmc());
31+
assertEquals(Integer.valueOf(1700), god.getAtfd());
32+
assertEquals(Float.valueOf(4.597f), god.getTcc());
33+
}
34+
35+
}

0 commit comments

Comments
 (0)