Here is a skeleton of what your tests should look like:
@IsTest
class MyCustomControllerTests
{
// Method stubs below
}
Testing Your Constructor
static testMethod void testConstructor()
{
// If you do complex setup in your constructor test it here.
// Otherwise a constructor test is likely unnecessary.
}
Testing Your Remote Action
static testMethod void testShareObject_PositiveCase()
{
// Set up data so you will get back true
Test.startTest();
Boolean result = MyCustomController.shareObject(someInput);
Test.stopTest();
system.assertEquals(true, result, 'Explanatory message here');
}
static testMethod void testShareObject_NegativeCase()
{
// Set up data so you will get back false
Test.startTest();
Boolean result = MyCustomController.shareObject(someInput);
Test.stopTest();
system.assertEquals(false, result, 'Explanatory message here');
}
Testing Your Map Method
static testMethod void testGetFieldsForSelectedObject()
{
// You should really rewrite this method
// so its parameter type is SObjectType instead of String.
// It also seems like it should not be dependent on any controller state
// in which case you should make the method static.
// Set up data
MyCustomController controller = new MyCustomController();
Test.startTest();
Map<String, String> data = controller.getFieldsForSelectedObject('MyObject__c');
Test.stopTest();
system.assertNotEquals(null, data, 'Explanatory message here');
system.assertEquals(expectedSize, data.size(), 'Explanatory message here');
// Any other prudent assertions here
}