### Question:
ServiceMappedAddressFunctionProcessor extends ServiceRegistryFunctionProcessorBase<ServiceMappedAddressFunctionDescriptor> implements UrlRewriteFunctionProcessor<ServiceMappedAddressFunctionDescriptor> { @Override public void initialize( UrlRewriteEnvironment environment, ServiceMappedAddressFunctionDescriptor descriptor ) throws Exception { super.initialize( environment, descriptor ); HostMapperService hostmapService = services().getService( ServiceType.HOST_MAPPING_SERVICE ); if( hostmapService != null ) { hostmap = hostmapService.getHostMapper( cluster() ); } }  @Override String name(); @Override void initialize( UrlRewriteEnvironment environment, ServiceMappedAddressFunctionDescriptor descriptor ); @Override List<String> resolve( UrlRewriteContext context, List<String> parameters ); String resolve( UrlRewriter.Direction direction, String parameter );  }### Answer:
@Test public void testInitialize() throws Exception { ServiceMappedAddressFunctionProcessor func = new ServiceMappedAddressFunctionProcessor(); try { func.initialize( null, desc ); fail( "Should have thrown an IllegalArgumentException" ); } catch( IllegalArgumentException e ) { assertThat( e.getMessage(), containsString( "environment" ) ); } func = new ServiceMappedAddressFunctionProcessor(); try { func.initialize( env, null ); } catch( Exception e ) { e.printStackTrace(); fail( "Should not have thrown an exception" ); } func.initialize( env, desc ); assertThat( func.cluster(), is( "test-cluster" ) ); assertThat( func.registry(), sameInstance( reg ) ); }
@Test public void testDestroy() throws Exception { ServiceMappedAddressFunctionProcessor func = new ServiceMappedAddressFunctionProcessor(); func.initialize( env, desc ); func.destroy(); assertThat( func.cluster(), nullValue() ); assertThat( func.registry(), nullValue() ); }