Package com.pugh.sockso.commands

Source Code of com.pugh.sockso.commands.UserListTest

package com.pugh.sockso.commands;

import com.pugh.sockso.tests.SocksoTestCase;
import com.pugh.sockso.tests.TestDatabase;
import com.pugh.sockso.web.User;

public class UserListTest extends SocksoTestCase {
   
    private TestDatabase db;
   
    private Command cmd;

    @Override
    public void setUp() {
        db = new TestDatabase();
        cmd = new UserList( db );
    }

    public void testListingUsersReturnsTheirDetails() throws Exception {
        User user = new User( "foo", "", "foo@bar.com", true );
        user.save( db );
        String result = cmd.execute( new String[] { "userlist" } );
        assertContains( result, String.valueOf(user.getId()) );
        assertContains( result, user.getName() );
        assertContains( result, user.getEmail() );
    }

    public void testActiveUsersAreNotListedAsPending() throws Exception {
        User user = new User( "foo", "", "foo@bar.com", true );
        user.save( db );
        String result = cmd.execute( new String[] { "userlist" } );
        assertNotContains( result, "PENDING" );
    }

    public void testInactiveUsersAreListedAsPending() throws Exception {
        User user = new User( "foo", "", "foo@bar.com", true );
        user.setActive( false );
        user.save( db );
        String result = cmd.execute( new String[] { "userlist" } );
        assertContains( result, "PENDING" );
    }

    public void testListingUsersIncludesAdminIfTheyAreAnAdmin() throws Exception {
        User user = new User( "foo", "", "foo@bar.com", true );
        user.save( db );
        assertContains( cmd.execute( new String[] { "userlist" } ), "ADMIN" );
    }

    public void testListingUsersDoesntIncludeAdminIfTheyAreNotAnAdmin() throws Exception {
        User user = new User( "foo", "", "foo@bar.com", false );
        user.save( db );
        assertNotContains( cmd.execute( new String[] { "userlist" } ), "ADMIN" );
    }

}
TOP

Related Classes of com.pugh.sockso.commands.UserListTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.