File tree Expand file tree Collapse file tree 4 files changed +89
-0
lines changed
java/com/iluwatar/featuretoggle/user
test/com/iluwatar/featuretoggle/user Expand file tree Collapse file tree 4 files changed +89
-0
lines changed Original file line number Diff line number Diff line change 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 >
Original file line number Diff line number Diff line change 1+ package com .iluwatar .featuretoggle .user ;
2+
3+ /**
4+ * Created by joseph on 26/01/16.
5+ */
6+ public class User {
7+ }
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments