Skip to content

Commit 72733ac

Browse files
committed
iluwatar#354 added usergroup for version of feature toggle
1 parent 0b83412 commit 72733ac

File tree

4 files changed

+89
-0
lines changed

4 files changed

+89
-0
lines changed

feature-toggle/pom.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,12 @@
1313
<artifactId>feature-toggle</artifactId>
1414

1515

16+
<dependencies>
17+
<dependency>
18+
<groupId>junit</groupId>
19+
<artifactId>junit</artifactId>
20+
<scope>test</scope>
21+
</dependency>
22+
23+
</dependencies>
1624
</project>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.iluwatar.featuretoggle.user;
2+
3+
/**
4+
* Created by joseph on 26/01/16.
5+
*/
6+
public class User {
7+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.iluwatar.featuretoggle.user;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
6+
/**
7+
* Created by joseph on 26/01/16.
8+
*/
9+
public class UserGroup {
10+
11+
private static List<User> freeGroup = new ArrayList<>();
12+
private static List<User> paidGroup = new ArrayList<>();
13+
14+
public static void addUserToFreeGroup(final User user){
15+
if(paidGroup.contains(user)){
16+
throw new IllegalArgumentException("User all ready member of paid group.");
17+
}else{
18+
if(!freeGroup.contains(user)){
19+
freeGroup.add(user);
20+
}
21+
}
22+
}
23+
24+
public static void addUserToPaidGroup(final User user){
25+
if(freeGroup.contains(user)){
26+
throw new IllegalArgumentException("User all ready member of free group.");
27+
}else{
28+
if(!paidGroup.contains(user)){
29+
paidGroup.add(user);
30+
}
31+
}
32+
}
33+
34+
public static boolean isPaid(User user) {
35+
return paidGroup.contains(user);
36+
}
37+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.iluwatar.featuretoggle.user;
2+
3+
import org.junit.Test;
4+
5+
import static junit.framework.TestCase.assertFalse;
6+
import static org.junit.Assert.assertTrue;
7+
8+
public class UserGroupTest {
9+
10+
@Test
11+
public void testAddUserToFreeGroup() throws Exception {
12+
User user = new User();
13+
UserGroup.addUserToFreeGroup(user);
14+
assertFalse(UserGroup.isPaid(user));
15+
}
16+
17+
@Test
18+
public void testAddUserToPaidGroup() throws Exception {
19+
User user = new User();
20+
UserGroup.addUserToPaidGroup(user);
21+
assertTrue(UserGroup.isPaid(user));
22+
}
23+
24+
@Test(expected = IllegalArgumentException.class)
25+
public void testAddUserToPaidWhenOnFree() throws Exception {
26+
User user = new User();
27+
UserGroup.addUserToFreeGroup(user);
28+
UserGroup.addUserToPaidGroup(user);
29+
}
30+
31+
@Test(expected = IllegalArgumentException.class)
32+
public void testAddUserToFreeWhenOnPaid() throws Exception {
33+
User user = new User();
34+
UserGroup.addUserToPaidGroup(user);
35+
UserGroup.addUserToFreeGroup(user);
36+
}
37+
}

0 commit comments

Comments
 (0)