@IsTest
public class sObjectComparator_Test {

    @IsTest
    static void AccountSorting() {
        List<Account> toSort = new List<Account>();
        toSort.add(new Account(Name='Test1', NumberOfEmployees=5));
        toSort.add(new Account(Name='Test3', NumberOfEmployees=2));
        toSort.add(new Account(Name='Test2'));
        toSort.add(null);
        
       	sObjectComparator nameComp = new sObjectComparator(Account.Name);
        
        toSort.sort(nameComp);
        
        System.debug(toSort);
        Assert.isNull(toSort.get(0));
        Assert.areEqual('Test1', toSort.get(1).Name);
        Assert.areEqual('Test2', toSort.get(2).Name);
        Assert.areEqual('Test3', toSort.get(3).Name);
        
       	sObjectComparator numEmpCom = new sObjectComparator(Account.NumberOfEmployees);
        
        toSort.sort(numEmpCom);
        Assert.isNull(toSort.get(0));
        Assert.areEqual('Test2', toSort.get(1).Name);
        Assert.areEqual('Test3', toSort.get(2).Name);
        Assert.areEqual('Test1', toSort.get(3).Name);
        
        numEmpCom.order = sObjectComparator.SortOrder.Descend;
        toSort.sort(numEmpCom);
        Assert.areEqual('Test1', toSort.get(0).Name);
        Assert.areEqual('Test3', toSort.get(1).Name);
        Assert.areEqual('Test2', toSort.get(2).Name);
        Assert.isNull(toSort.get(3));
    }
    
    @IsTest
    static void ContactSorting() {
        List<Contact> toSort = new List<Contact>();
        toSort.add(new Contact(LastName='Test1', Birthdate=DateTime.now().date()) );
        toSort.add(new Contact(LastName='Test3'));
        toSort.add(new Contact(LastName='Test2', Birthdate=DateTime.now().addDays(-10).date()));
        toSort.add(null);
        
       	sObjectComparator nameComp = new sObjectComparator(Contact.LastName);
        
        toSort.sort(nameComp);
        
        System.debug(toSort);
        Assert.isNull(toSort.get(0));
        Assert.areEqual('Test1', toSort.get(1).LastName);
        Assert.areEqual('Test2', toSort.get(2).LastName);
        Assert.areEqual('Test3', toSort.get(3).LastName);
        
       	sObjectComparator numEmpCom = new sObjectComparator(Contact.BirthDate);
        
        toSort.sort(numEmpCom);
        Assert.isNull(toSort.get(0));
        Assert.areEqual('Test3', toSort.get(1).LastName);
        Assert.areEqual('Test2', toSort.get(2).LastName);
        Assert.areEqual('Test1', toSort.get(3).LastName);
        
        numEmpCom.order = sObjectComparator.SortOrder.Descend;
        toSort.sort(numEmpCom);
        Assert.areEqual('Test1', toSort.get(0).LastName);
        Assert.areEqual('Test2', toSort.get(1).LastName);
        Assert.areEqual('Test3', toSort.get(2).LastName);
        Assert.isNull(toSort.get(3));
    }
    
}