source code formatting.
[utils] / security / src / test / java / org / wamblee / usermgt / InMemoryGroupSetTest.java
index 03329d1d958f918b150e220e424ad54d3c6d043a..e71b3e315485aa033201609469558b19761f02ea 100644 (file)
 /*
  * Copyright 2005 the original author or authors.
- * 
+ *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
- * 
+ *
  *      http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
- */ 
-
+ */
 package org.wamblee.usermgt;
 
+import junit.framework.TestCase;
+
 import java.sql.SQLException;
+
 import java.util.Set;
 
-import junit.framework.TestCase;
 
 /**
  * Tests the inmemory group set. Intended to be subclassed for other
- * implementations of group set. 
+ * implementations of group set.
  */
 public class InMemoryGroupSetTest extends TestCase {
-    
-    protected GroupSet groups; 
-   
     /**
-     * This method must be overriden in subclasses. 
-     * @return New group set object. 
+     * DOCUMENT ME!
      */
-    protected GroupSet createGroupSet() { 
-        return new InMemoryGroupSet(); 
+    protected GroupSet groups;
+
+    /**
+     * This method must be overriden in subclasses.
+     *
+     * @return New group set object.
+     */
+    protected GroupSet createGroupSet() {
+        return new InMemoryGroupSet();
     }
-    
+
     /* (non-Javadoc)
      * @see org.wamblee.test.SpringTestCase#setUp()
      */
+    /**
+     * DOCUMENT ME!
+     *
+     * @throws Exception DOCUMENT ME!
+     */
     @Override
     protected void setUp() throws Exception {
         super.setUp();
-        groups = createGroupSet(); 
-        checkGroupCount(0); 
+        groups = createGroupSet();
+        checkGroupCount(0);
     }
-    
-    
-    
+
     /**
-     * Additional check to be implemented by a subclass. 
-     * @param aGroup Group to check for existence. 
+     * Additional check to be implemented by a subclass.
+     *
+     * @param aGroup Group to check for existence.
+     *
+     * @throws SQLException DOCUMENT ME!
      */
-    protected void checkGroupExists(String aGroup) throws SQLException { 
+    protected void checkGroupExists(String aGroup) throws SQLException {
         // Empty
     }
-    
+
     /**
-     * Additional check to be implemented by a subclass. 
-     * @param aGroup Group to check for non-existence. 
+     * Additional check to be implemented by a subclass.
+     *
+     * @param aGroup Group to check for non-existence.
+     *
+     * @throws SQLException DOCUMENT ME!
      */
-    protected void checkGroupNotExists(String aGroup) throws SQLException { 
+    protected void checkGroupNotExists(String aGroup) throws SQLException {
         // Empty
     }
-    
+
     /**
-     * Additional check to be implemented by a subclass. 
-     * @param aSize Expected number of groups. 
+     * Additional check to be implemented by a subclass.
+     *
+     * @param aSize Expected number of groups.
+     *
+     * @throws SQLException DOCUMENT ME!
      */
-    protected void checkGroupCount(int aSize) throws SQLException { 
+    protected void checkGroupCount(int aSize) throws SQLException {
         assertEquals(aSize, groups.size());
     }
-    
+
     /**
-     * Adds a group and verifies that the group is added using 
-     * find(), list(),  and contains().  
+     * Adds a group and verifies that the group is added using  find(),
+     * list(),  and contains().
      *
+     * @throws SQLException DOCUMENT ME!
      */
-    public void testAdd() throws SQLException { 
-       Group group = new Group("group1"); 
-       assertTrue(  groups.add(group) );
-       checkGroupExists(group.getName());
-       checkGroupCount(1);
-       Group group2 = groups.find("group1"); 
-       assertNotNull(group2);
-       assertEquals(group.getName(), group2.getName()); 
-       Set<Group> set = groups.list(); 
-       assertEquals(1, set.size()); 
-       assertTrue(set.contains(group));
+    public void testAdd() throws SQLException {
+        Group group = new Group("group1");
+        assertTrue(groups.add(group));
+        checkGroupExists(group.getName());
+        checkGroupCount(1);
+
+        Group group2 = groups.find("group1");
+        assertNotNull(group2);
+        assertEquals(group.getName(), group2.getName());
+
+        Set<Group> set = groups.list();
+        assertEquals(1, set.size());
+        assertTrue(set.contains(group));
     }
-    
+
     /**
      * Tries to find a non-existing group. Verifies that null is
-     * returned. 
+     * returned.
      *
+     * @throws SQLException DOCUMENT ME!
      */
-    public void testFindUnknownGroup() throws SQLException { 
-       Group group1 = new Group("group1"); 
-       Group group2 = new Group("group2");
-       groups.add(group1); 
-       groups.add(group2);
-       checkGroupExists(group1.getName()); 
-       checkGroupExists(group2.getName()); 
-    
-       assertNull( groups.find("group3") );
-       checkGroupNotExists("group3");
+    public void testFindUnknownGroup() throws SQLException {
+        Group group1 = new Group("group1");
+        Group group2 = new Group("group2");
+        groups.add(group1);
+        groups.add(group2);
+        checkGroupExists(group1.getName());
+        checkGroupExists(group2.getName());
+
+        assertNull(groups.find("group3"));
+        checkGroupNotExists("group3");
     }
-    
+
     /**
-     * Adds duplicate group. Verifies that the existing group is left untouched.  
+     * Adds duplicate group. Verifies that the existing group is left
+     * untouched.
+     *
+     * @throws SQLException DOCUMENT ME!
      */
-    public void testAddDuplicateGroup() throws SQLException { 
-       Group group1 = new Group("group1"); 
-       groups.add(group1); 
-       
-       assertEquals(1, groups.list().size()); 
-       assertTrue(groups.contains(group1));
-       group1 = new Group("group1");
-       assertFalse(groups.add(group1));
-       assertEquals(1, groups.list().size());
-       
-       checkGroupExists(group1.getName()); 
-       checkGroupCount(1); 
+    public void testAddDuplicateGroup() throws SQLException {
+        Group group1 = new Group("group1");
+        groups.add(group1);
+
+        assertEquals(1, groups.list().size());
+        assertTrue(groups.contains(group1));
+        group1 = new Group("group1");
+        assertFalse(groups.add(group1));
+        assertEquals(1, groups.list().size());
+
+        checkGroupExists(group1.getName());
+        checkGroupCount(1);
     }
-    
+
     /**
-     * Removes a group. Verifies that the group is 
-     * removed and the return value is true. 
+     * Removes a group. Verifies that the group is  removed and the
+     * return value is true.
      *
+     * @throws SQLException DOCUMENT ME!
      */
-    public void testRemoveGroup() throws SQLException { 
-        Group group1 = new Group("group1"); 
-        groups.add(group1); 
+    public void testRemoveGroup() throws SQLException {
+        Group group1 = new Group("group1");
+        groups.add(group1);
         assertTrue(groups.contains(group1));
         checkGroupCount(1);
-        
-        assertTrue(groups.remove(group1)); 
-        assertFalse(groups.contains(group1)); 
+
+        assertTrue(groups.remove(group1));
+        assertFalse(groups.contains(group1));
         assertNull(groups.find(group1.getName()));
         assertEquals(0, groups.list().size());
         checkGroupCount(0);
     }
-  
+
     /**
      * Removes a non-existing group. Verifies that no groups are
-     * removed an that the return value is true. 
+     * removed an that the return value is true.
      *
+     * @throws SQLException DOCUMENT ME!
      */
-    public void testRemoveNonExistingGroup() throws SQLException { 
-        Group group1 = new Group("group1"); 
-        groups.add(group1); 
+    public void testRemoveNonExistingGroup() throws SQLException {
+        Group group1 = new Group("group1");
+        groups.add(group1);
         checkGroupCount(1);
-        Group nonExistingGroup = new Group("group2"); 
+
+        Group nonExistingGroup = new Group("group2");
         nonExistingGroup.setPrimaryKey(new Long(1000));
         nonExistingGroup.setPersistedVersion(1000);
         assertFalse(groups.remove(nonExistingGroup));
-        assertTrue(groups.contains(group1)); 
+        assertTrue(groups.contains(group1));
         assertEquals(1, groups.list().size());
-        checkGroupCount(1); 
+        checkGroupCount(1);
     }
-    
+
     /**
-     * Adds a number of groups to the set and verifies that list() 
-     * returns them all. 
+     * Adds a number of groups to the set and verifies that list()
+     * returns them all.
      *
+     * @throws SQLException DOCUMENT ME!
      */
-    public void testList() throws SQLException { 
-        Group group1 = new Group("group1"); 
-        Group group2 = new Group("group2"); 
-        Group group3 = new Group("group3"); 
-        assertTrue(groups.add(group1)); 
-        assertTrue(groups.add(group2)); 
+    public void testList() throws SQLException {
+        Group group1 = new Group("group1");
+        Group group2 = new Group("group2");
+        Group group3 = new Group("group3");
+        assertTrue(groups.add(group1));
+        assertTrue(groups.add(group2));
         assertTrue(groups.add(group3));
-        
-        checkGroupExists(group1.getName()); 
-        checkGroupExists(group2.getName()); 
-        checkGroupExists(group3.getName()); 
-        
-        Set<Group> set = groups.list(); 
-        assertTrue(set.contains(group1)); 
-        assertTrue(set.contains(group2)); 
+
+        checkGroupExists(group1.getName());
+        checkGroupExists(group2.getName());
+        checkGroupExists(group3.getName());
+
+        Set<Group> set = groups.list();
+        assertTrue(set.contains(group1));
+        assertTrue(set.contains(group2));
         assertTrue(set.contains(group3));
-        
-        checkGroupCount(3); 
+
+        checkGroupCount(3);
     }
 }