* Hexagonal architecture: a quick and practical example

* BAEL-3486


commit

* Formatting issue solved

* Update code for consistency with article
This commit is contained in:
mguarnaccia 2020-01-02 20:27:18 +01:00 committed by maibin
parent e11c779a6c
commit 63397e4daa
4 changed files with 9 additions and 14 deletions

View File

@ -15,7 +15,7 @@ public class GreedyAlgorithm {
this.fp = new FollowersPath();
}
public long findMostFollowersPath(String account) throws Exception {
public long findMostFollowersPath(String account) {
long max = 0;
SocialUser toFollow = null;
@ -31,12 +31,8 @@ public class GreedyAlgorithm {
if (currentLevel < maxLevel - 1) {
currentLevel++;
max += findMostFollowersPath(toFollow.getUsername());
//fp.addFollower(toFollow.getUsername(), max);
//fp.addCount(max);
return max;
} else {
//fp.addFollower(toFollow.getUsername(), max);
//fp.addCount(max);
return max;
}
}

View File

@ -13,9 +13,8 @@ public class NonGreedyAlgorithm {
this.tc = tc;
this.currentLevel = level;
}
public long findMostFollowersPath(String account) throws Exception {
public long findMostFollowersPath(String account) {
List<SocialUser> followers = tc.getFollowers(account);
long total = currentLevel > 0 ? followers.size() : 0;

View File

@ -20,9 +20,9 @@ public class SocialConnector {
return this.isCounterEnabled;
}
public List<SocialUser> getFollowers(String account) throws Exception {
public List<SocialUser> getFollowers(String account) {
if (counter < 0)
throw new Exception ("API limit reached");
throw new IllegalStateException ("API limit reached");
else {
if(this.isCounterEnabled) counter--;
for(SocialUser user : users) {

View File

@ -35,21 +35,21 @@ public class GreedyAlgorithmUnitTest {
}
@Test
public void greedyAlgorithmTest() throws Exception {
public void greedyAlgorithmTest() {
GreedyAlgorithm ga = new GreedyAlgorithm(prepareNetwork());
assertEquals(ga.findMostFollowersPath("root"), 5);
}
@Test
public void nongreedyAlgorithmTest() throws Exception {
public void nongreedyAlgorithmTest() {
NonGreedyAlgorithm nga = new NonGreedyAlgorithm(prepareNetwork(), 0);
Assertions.assertThrows(Exception.class, () -> {
Assertions.assertThrows(IllegalStateException.class, () -> {
nga.findMostFollowersPath("root");
});
}
@Test
public void nongreedyAlgorithmUnboundedTest() throws Exception {
public void nongreedyAlgorithmUnboundedTest() {
SocialConnector sc = prepareNetwork();
sc.switchCounter();
NonGreedyAlgorithm nga = new NonGreedyAlgorithm(sc, 0);