Skip to content

Commit b54d28a

Browse files
committed
acromyn: adjust API to use an instance method
Fixes issue exercism#351.
1 parent 99f4a1d commit b54d28a

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

exercises/acronym/src/example/java/Acronym.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,17 @@
22
import java.util.regex.Pattern;
33

44
public class Acronym {
5-
public static String generate(String phrase){
5+
private final String acronym;
6+
7+
public Acronym(String phrase) {
8+
acronym = generateAcronym(phrase);
9+
}
10+
11+
public String getAcronym() {
12+
return acronym;
13+
}
14+
15+
private String generateAcronym(String phrase){
616
final Pattern BREAK_WORDS = Pattern.compile("[A-Z]+[a-z]*|[a-z]+");
717
final Matcher matcher = BREAK_WORDS.matcher(phrase);
818
final StringBuilder b = new StringBuilder();

exercises/acronym/src/test/java/AcronymTest.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,68 +5,67 @@
55

66
public class AcronymTest {
77

8-
98
@Test
109
public void fromTitleCasedPhrases() {
1110
final String phrase = "Portable Network Graphics";
1211
final String expected = "PNG";
13-
assertEquals(expected, Acronym.generate(phrase));
12+
assertEquals(expected, new Acronym(phrase).getAcronym());
1413
}
1514

1615
@Ignore
1716
@Test
1817
public void fromOtherTitleCasedPhrases() {
1918
final String phrase = "Ruby on Rails";
2019
final String expected = "ROR";
21-
assertEquals(expected, Acronym.generate(phrase));
20+
assertEquals(expected, new Acronym(phrase).getAcronym());
2221
}
2322

2423
@Ignore
2524
@Test
2625
public void fromInconsistentlyCasedPhrases() {
2726
final String phrase = "HyperText Markup Language";
2827
final String expected = "HTML";
29-
assertEquals(expected, Acronym.generate(phrase));
28+
assertEquals(expected, new Acronym(phrase).getAcronym());
3029
}
3130

3231
@Ignore
3332
@Test
3433
public void fromPhrasesWithPunctuation() {
3534
final String phrase = "First In, First Out";
3635
final String expected = "FIFO";
37-
assertEquals(expected, Acronym.generate(phrase));
36+
assertEquals(expected, new Acronym(phrase).getAcronym());
3837
}
3938

4039
@Ignore
4140
@Test
4241
public void fromOtherPhrasesWithPunctuation() {
4342
final String phrase = "PHP: Hypertext Preprocessor";
4443
final String expected = "PHP";
45-
assertEquals(expected, Acronym.generate(phrase));
44+
assertEquals(expected, new Acronym(phrase).getAcronym());
4645
}
4746

4847
@Ignore
4948
@Test
5049
public void fromPhrasesWithNonAcronymAllCapsWord() {
5150
final String phrase = "GNU Image Manipulation Program";
5251
final String expected = "GIMP";
53-
assertEquals(expected, Acronym.generate(phrase));
52+
assertEquals(expected, new Acronym(phrase).getAcronym());
5453
}
5554

5655
@Ignore
5756
@Test
5857
public void fromPhrasesWithPunctuationAndSentenceCasing() {
5958
final String phrase = "Complementary metal-oxide semiconductor";
6059
final String expected = "CMOS";
61-
assertEquals(expected, Acronym.generate(phrase));
60+
assertEquals(expected, new Acronym(phrase).getAcronym());
6261
}
6362

6463
@Ignore
6564
@Test
6665
public void fromPhraseWithSingleLetterWord() {
6766
final String phrase = "Cat in a Hat";
6867
final String expected = "CIAH";
69-
assertEquals(expected, Acronym.generate(phrase));
68+
assertEquals(expected, new Acronym(phrase).getAcronym());
7069
}
7170

7271
}

0 commit comments

Comments
 (0)