package com.yammer.stresstime.entities;

import com.yammer.stresstime.managers.EmployeeManager;
import com.yammer.stresstime.managers.GroupManager;
import com.yammer.stresstime.managers.MembershipManager;
import com.yammer.stresstime.test.DatabaseTest;
import org.hibernate.exception.ConstraintViolationException;
import org.junit.Before;
import org.junit.Test;

import static com.yammer.stresstime.test.TestUtils.assertCauses;

public class MembershipTest extends DatabaseTest {

    private GroupManager groupManager;
    private EmployeeManager employeeManager;
    private MembershipManager membershipManager;

    @Override
    @Before
    public void setUp() throws Exception {
        super.setUp();
        groupManager = new GroupManager(getSessionFactory());
        employeeManager = new EmployeeManager(getSessionFactory());
        membershipManager = new MembershipManager(getSessionFactory());
    }

    @Test
    public void testAssignmentUniqueness() throws Exception {
        Employee employee = new Employee("John Doe", "<yid>");
        Group group = new Group("Core Services");
        employeeManager.save(employee);
        groupManager.save(group);
        membershipManager.join(group, employee);

        assertCauses(ConstraintViolationException.class, () -> membershipManager.join(group, employee));

        hibernateThrewException();
    }
}

@@ -1320,24 +1320,190 @@
 mployee));%0A%0A
+        Membership membership = new Membership(employee, group);%0A        assertCauses(ConstraintViolationException.class, () -%3E membershipManager.save(membership));%0A%0A
         hibe

Add new membership validation