#354 added usergroup for version of feature toggle

This commit is contained in:
Joseph McCarthy 2016-01-26 18:41:08 +00:00
parent 0b834128b9
commit 72733acfc6
4 changed files with 89 additions and 0 deletions

View File

@ -13,4 +13,12 @@
<artifactId>feature-toggle</artifactId>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,7 @@
package com.iluwatar.featuretoggle.user;
/**
* Created by joseph on 26/01/16.
*/
public class User {
}

View File

@ -0,0 +1,37 @@
package com.iluwatar.featuretoggle.user;
import java.util.ArrayList;
import java.util.List;
/**
* Created by joseph on 26/01/16.
*/
public class UserGroup {
private static List<User> freeGroup = new ArrayList<>();
private static List<User> paidGroup = new ArrayList<>();
public static void addUserToFreeGroup(final User user){
if(paidGroup.contains(user)){
throw new IllegalArgumentException("User all ready member of paid group.");
}else{
if(!freeGroup.contains(user)){
freeGroup.add(user);
}
}
}
public static void addUserToPaidGroup(final User user){
if(freeGroup.contains(user)){
throw new IllegalArgumentException("User all ready member of free group.");
}else{
if(!paidGroup.contains(user)){
paidGroup.add(user);
}
}
}
public static boolean isPaid(User user) {
return paidGroup.contains(user);
}
}

View File

@ -0,0 +1,37 @@
package com.iluwatar.featuretoggle.user;
import org.junit.Test;
import static junit.framework.TestCase.assertFalse;
import static org.junit.Assert.assertTrue;
public class UserGroupTest {
@Test
public void testAddUserToFreeGroup() throws Exception {
User user = new User();
UserGroup.addUserToFreeGroup(user);
assertFalse(UserGroup.isPaid(user));
}
@Test
public void testAddUserToPaidGroup() throws Exception {
User user = new User();
UserGroup.addUserToPaidGroup(user);
assertTrue(UserGroup.isPaid(user));
}
@Test(expected = IllegalArgumentException.class)
public void testAddUserToPaidWhenOnFree() throws Exception {
User user = new User();
UserGroup.addUserToFreeGroup(user);
UserGroup.addUserToPaidGroup(user);
}
@Test(expected = IllegalArgumentException.class)
public void testAddUserToFreeWhenOnPaid() throws Exception {
User user = new User();
UserGroup.addUserToPaidGroup(user);
UserGroup.addUserToFreeGroup(user);
}
}