### Question:
RequireJsConfigManager { public String getContextMapping( String baseUrl, String referer ) { return this.getCachedContextMapping( baseUrl, referer ); }  void setPackageConfigurationsTracker( RequireJsPackageServiceTracker packageConfigurationsTracker ); void setExternalResourcesScriptsTracker( RequireJsBundleListener externalResourcesScriptsTracker ); void setPlugins( List<IRequireJsPackageConfigurationPlugin> plugins ); void destroy(); String getRequireJsConfig( String baseUrl ); String getContextMapping( String baseUrl, String referer ); void invalidateCachedConfigurations();  }### Answer:
@Test public void testGetContextMappingKnownReferer() { Collection<IRequireJsPackageConfiguration> requireJsPackages = new ArrayList<>(); requireJsPackages.add( createRequireJsPackageConfigurationMock( "package/1.0" ) ); doReturn( requireJsPackages ).when( this.mockPackageConfigurationsTracker ).getPackages(); String config = this.requireJsConfigManager.getContextMapping( this.baseUrl, "/default/base/url/package/1.0/index.html" ); HashMap<String, Object> topMap = new HashMap<>(); topMap.put( "*", packageConfigurationMapping ); HashMap<String, Object> requireConfig = new HashMap<>(); requireConfig.put( "map", topMap ); assertEquals( "Configuration for context mapping should be the same of the package", JSONObject.toJSONString( requireConfig ), config ); }
@Test public void testGetContextMappingNullReferer() { String config = this.requireJsConfigManager.getContextMapping( this.baseUrl, null ); assertNull( "No configuration for context mapping should be returned", config ); }
@Test public void testGetContextMappingEmptyReferer() { String config = this.requireJsConfigManager.getContextMapping( this.baseUrl, "" ); assertNull( "No configuration for context mapping should be returned", config ); }
@Test public void testGetContextMappingUnknownReferer() { Collection<IRequireJsPackageConfiguration> requireJsPackages = new ArrayList<>(); requireJsPackages.add( createRequireJsPackageConfigurationMock( "package/1.0" ) ); doReturn( requireJsPackages ).when( this.mockPackageConfigurationsTracker ).getPackages(); String config = this.requireJsConfigManager.getContextMapping( this.baseUrl, "/something/index.html" ); assertNull( "No configuration for context mapping should be returned", config ); }
@Test public void testGetContextMappingCache() { Collection<IRequireJsPackageConfiguration> requireJsPackages = new ArrayList<>(); IRequireJsPackageConfiguration packageA = createRequireJsPackageConfigurationMock( "packageA/1.0" ); IRequireJsPackageConfiguration packageB = createRequireJsPackageConfigurationMock( "packageB/1.5" ); requireJsPackages.add( packageA ); requireJsPackages.add( packageB ); doReturn( requireJsPackages ).when( this.mockPackageConfigurationsTracker ).getPackages(); this.requireJsConfigManager.getContextMapping( this.baseUrl, "/default/base/url/packageA/1.0/index.html" ); verify( packageA, times( 1 ) ).getModuleIdsMapping(); verify( packageB, times( 0 ) ).getModuleIdsMapping(); this.requireJsConfigManager.getContextMapping( this.baseUrl, "/default/base/url/packageB/1.5/index.html" ); verify( packageA, times( 1 ) ).getModuleIdsMapping(); verify( packageB, times( 1 ) ).getModuleIdsMapping(); this.requireJsConfigManager.getContextMapping( this.baseUrl, "/default/base/url/packageA/1.0/index.html" ); verify( packageA, times( 1 ) ).getModuleIdsMapping(); verify( packageB, times( 1 ) ).getModuleIdsMapping(); this.requireJsConfigManager.getContextMapping( this.baseUrl, "/default/base/url/packageB/1.5/index.html" ); verify( packageA, times( 1 ) ).getModuleIdsMapping(); verify( packageB, times( 1 ) ).getModuleIdsMapping(); }