Skip to content

Commit

Permalink
Added tests for stripLocalNamespace
Browse files Browse the repository at this point in the history
Fixed broken test
  • Loading branch information
rob-baillie-ortoo committed Apr 21, 2022
1 parent 0dcd5ea commit e303575
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ private without sharing class ortoo_MessageRendererFactoryTest
}
Test.stopTest();

ortoo_Asserts.assertContains( 'ortoo_MessageRendererFactoryTest.NonRegisterableType does not implement MessageRendererEngine.IMessageRenderer', exceptionMessage, 'newInstance, when called for an unmapped type that does not implement IMessageRenderer, will throw an exception' );
ortoo_Asserts.assertContains( 'ortoo_MessageRendererFactoryTest.NonRegisterableType) does not implement MessageRendererEngine.IMessageRenderer', exceptionMessage, 'newInstance, when called for an unmapped type that does not implement IMessageRenderer, will throw an exception' );
}

@isTest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,20 @@ public inherited sharing class ObjectUtils
return returnType;
}

// TODO: test
// TODO: document
/**
* Given the name of a class, will strip the local namespace prefix from it,
* if that namespace is present.
*
* @param String The className to strip the namespace from
* @return String The className with the namespace stripped
*/
public static String stripLocalNamespace( String className )
{
Contract.requires( String.isNotBlank( className ), 'stripLocalNamespace called with a blank className' );

if ( className.startsWithIgnoreCase( PackageUtils.NAMESPACE_PREFIX + '.' ) )
{
return className.substringAfter( PackageUtils.NAMESPACE_PREFIX + '.' );
return className.substringAfter( '.' );
}
return className;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,50 @@
@isTest
public without sharing class PublicObjectUtilsTest
{
@isTest
private static void stripLocalNamespace_whenGivenANameWithTheNamespace_stripsIt() // NOPMD: Test method name format
{
String originalClassName = PackageUtils.NAMESPACE_PREFIX + '.' + 'theouterclass.theinnerclass';
Test.startTest();
String got = ObjectUtils.stripLocalNamespace( originalClassName );
Test.stopTest();

System.assertEquals( 'theouterclass.theinnerclass', got, 'stripLocalNamespace, when given a class name with the local namespace prefix, will strip it' );
}

@isTest
private static void stripLocalNamespace_whenGivenANameWithTheNamespaceInUppercase_stripsIt() // NOPMD: Test method name format
{
String originalClassName = PackageUtils.NAMESPACE_PREFIX.toUppercase() + '.' + 'theouterclass.theinnerclass';
Test.startTest();
String got = ObjectUtils.stripLocalNamespace( originalClassName );
Test.stopTest();

System.assertEquals( 'theouterclass.theinnerclass', got, 'stripLocalNamespace, when given a class name with the local namespace prefix in uppercase, will strip it' );
}

@isTest
private static void stripLocalNamespace_whenGivenANameWithTheNamespaceInTheMiddle_doesNotStripIt() // NOPMD: Test method name format
{
String originalClassName = 'anotherbit.' + PackageUtils.NAMESPACE_PREFIX + '.' + 'theouterclass.theinnerclass';
Test.startTest();
String got = ObjectUtils.stripLocalNamespace( originalClassName );
Test.stopTest();

System.assertEquals( originalClassName, got, 'stripLocalNamespace, when given a class name with the local namespace prefix in the middle, will not strip it' );
}

@isTest
private static void stripLocalNamespace_whenGivenANameWithNoLocalNamespace_doesNotStripIt() // NOPMD: Test method name format
{
String originalClassName = 'adifferentnamespace.theouterclass.theinnerclass';
Test.startTest();
String got = ObjectUtils.stripLocalNamespace( originalClassName );
Test.stopTest();

System.assertEquals( originalClassName, got, 'stripLocalNamespace, when given a class name with a different namespace, will not strip it' );
}

@isTest
private static void getParentClassType_whenGivenATypeForAnInnerClassInAPublicParent_willReturnTheTypeForTheContainingClass() // NOPMD: Test method name format
{
Expand Down

0 comments on commit e303575

Please sign in to comment.