### Question:
DefaultToolchainManagerPrivate extends DefaultToolchainManager implements ToolchainManagerPrivate { @Override public ToolchainPrivate[] getToolchainsForType( String type, MavenSession context ) throws MisconfiguredToolchainException { List<ToolchainPrivate> toRet = new ArrayList<>(); ToolchainFactory fact = factories.get( type ); if ( fact == null ) { logger.error( "Missing toolchain factory for type: " + type + ". Possibly caused by misconfigured project." ); } else { List<ToolchainModel> availableToolchains = context.getRequest().getToolchains().get( type ); if ( availableToolchains != null ) { for ( ToolchainModel toolchainModel : availableToolchains ) { toRet.add( fact.createToolchain( toolchainModel ) ); } } ToolchainPrivate tool = fact.createDefaultToolchain(); if ( tool != null ) { toRet.add( tool ); } } return toRet.toArray( new ToolchainPrivate[0] ); }  @Override ToolchainPrivate[] getToolchainsForType( String type, MavenSession context ); @Override void storeToolchainToBuildContext( ToolchainPrivate toolchain, MavenSession session );  }### Answer:
@Test public void testToolchainsForAvailableType() throws Exception { MavenSession session = mock( MavenSession.class ); MavenExecutionRequest req = new DefaultMavenExecutionRequest(); when( session.getRequest() ).thenReturn( req ); ToolchainPrivate basicToolchain = mock( ToolchainPrivate.class ); when( toolchainFactory_basicType.createDefaultToolchain() ).thenReturn( basicToolchain ); ToolchainPrivate rareToolchain = mock( ToolchainPrivate.class ); when( toolchainFactory_rareType.createDefaultToolchain() ).thenReturn( rareToolchain ); ToolchainPrivate[] toolchains = toolchainManager.getToolchainsForType( "basic", session ); verify( logger, never() ).error( anyString() ); assertEquals( 1, toolchains.length ); }
@Test public void testToolchainsForUnknownType() throws Exception { MavenSession session = mock( MavenSession.class ); MavenExecutionRequest req = new DefaultMavenExecutionRequest(); when( session.getRequest() ).thenReturn( req ); ToolchainPrivate basicToolchain = mock( ToolchainPrivate.class ); when( toolchainFactory_basicType.createDefaultToolchain() ).thenReturn( basicToolchain ); ToolchainPrivate rareToolchain = mock( ToolchainPrivate.class ); when( toolchainFactory_rareType.createDefaultToolchain() ).thenReturn( rareToolchain ); ToolchainPrivate[] toolchains = toolchainManager.getToolchainsForType( "unknown", session ); verify( logger ).error( "Missing toolchain factory for type: unknown. Possibly caused by misconfigured project." ); assertEquals( 0, toolchains.length ); }
@Test public void testToolchainsForConfiguredType() throws Exception { MavenSession session = mock( MavenSession.class ); MavenExecutionRequest req = new DefaultMavenExecutionRequest(); when( session.getRequest() ).thenReturn( req ); Map<String, List<ToolchainModel>> groupedToolchains = new HashMap<>(); req.setToolchains( groupedToolchains ); List<ToolchainModel> basicToolchains = new ArrayList<>(); ToolchainModel basicToolchainModel = new ToolchainModel(); basicToolchainModel.setType( "basic" ); basicToolchains.add( basicToolchainModel ); basicToolchains.add( basicToolchainModel ); groupedToolchains.put( "basic", basicToolchains ); List<ToolchainModel> rareToolchains = new ArrayList<>(); ToolchainModel rareToolchainModel = new ToolchainModel(); rareToolchainModel.setType( "rare" ); rareToolchains.add( rareToolchainModel ); groupedToolchains.put( "rare", rareToolchains ); ToolchainPrivate[] toolchains = toolchainManager.getToolchainsForType( "basic", session ); verify( logger, never() ).error( anyString() ); assertEquals( 2, toolchains.length ); }
@Test public void testMisconfiguredToolchain() throws Exception { MavenSession session = mock( MavenSession.class ); MavenExecutionRequest req = new DefaultMavenExecutionRequest(); when( session.getRequest() ).thenReturn( req ); ToolchainPrivate[] basics = toolchainManager.getToolchainsForType("basic", session); assertEquals( 0, basics.length ); }