### Question:
DefaultToolchainManager implements ToolchainManager { @Override public List<Toolchain> getToolchains( MavenSession session, String type, Map<String, String> requirements ) { List<ToolchainModel> models = session.getRequest().getToolchains().get( type ); return selectToolchains( models, type, requirements ); }  @Override Toolchain getToolchainFromBuildContext( String type, MavenSession session ); @Override List<Toolchain> getToolchains( MavenSession session, String type, Map<String, String> requirements ); static final String getStorageKey( String type );  }### Answer:
@Test public void testNoModels() { MavenSession session = mock( MavenSession.class ); MavenExecutionRequest executionRequest = new DefaultMavenExecutionRequest(); when( session.getRequest() ).thenReturn( executionRequest ); List<Toolchain> toolchains = toolchainManager.getToolchains( session, "unknown", null ); assertEquals( 0, toolchains.size() ); }
@Test public void testModelNoFactory() { MavenSession session = mock( MavenSession.class ); MavenExecutionRequest executionRequest = new DefaultMavenExecutionRequest(); Map<String, List<ToolchainModel>> toolchainModels = new HashMap<>(); toolchainModels.put( "unknown", Collections.singletonList( new ToolchainModel() ) ); executionRequest.setToolchains( toolchainModels ); when( session.getRequest() ).thenReturn( executionRequest ); List<Toolchain> toolchains = toolchainManager.getToolchains( session, "unknown", null ); assertEquals( 0, toolchains.size() ); verify( logger ).error( "Missing toolchain factory for type: unknown. Possibly caused by misconfigured project." ); }
@Test public void testModelAndFactory() { MavenSession session = mock( MavenSession.class ); MavenExecutionRequest executionRequest = new DefaultMavenExecutionRequest(); Map<String, List<ToolchainModel>> toolchainModels = new HashMap<>(); toolchainModels.put( "basic", Arrays.asList( new ToolchainModel(), new ToolchainModel() ) ); toolchainModels.put( "rare", Collections.singletonList( new ToolchainModel() ) ); executionRequest.setToolchains( toolchainModels ); when( session.getRequest() ).thenReturn( executionRequest ); List<Toolchain> toolchains = toolchainManager.getToolchains( session, "rare", null ); assertEquals( 1, toolchains.size() ); }
@Test public void testModelsAndFactory() { MavenSession session = mock( MavenSession.class ); MavenExecutionRequest executionRequest = new DefaultMavenExecutionRequest(); Map<String, List<ToolchainModel>> toolchainModels = new HashMap<>(); toolchainModels.put( "basic", Arrays.asList( new ToolchainModel(), new ToolchainModel() ) ); toolchainModels.put( "rare", Collections.singletonList( new ToolchainModel() ) ); executionRequest.setToolchains( toolchainModels ); when( session.getRequest() ).thenReturn( executionRequest ); List<Toolchain> toolchains = toolchainManager.getToolchains( session, "basic", null ); assertEquals( 2, toolchains.size() ); }
@Test public void testRequirements() throws Exception { MavenSession session = mock( MavenSession.class ); MavenExecutionRequest executionRequest = new DefaultMavenExecutionRequest(); Map<String, List<ToolchainModel>> toolchainModels = new HashMap<>(); toolchainModels.put( "basic", Arrays.asList( new ToolchainModel(), new ToolchainModel() ) ); toolchainModels.put( "rare", Collections.singletonList( new ToolchainModel() ) ); executionRequest.setToolchains( toolchainModels ); when( session.getRequest() ).thenReturn( executionRequest ); ToolchainPrivate basicPrivate = mock( ToolchainPrivate.class ); when( basicPrivate.matchesRequirements( ArgumentMatchers.<String, String>anyMap() ) ).thenReturn( false ).thenReturn( true ); when( toolchainFactory_basicType.createToolchain( isA( ToolchainModel.class ) ) ).thenReturn( basicPrivate ); List<Toolchain> toolchains = toolchainManager.getToolchains( session, "basic", Collections.singletonMap( "key", "value" ) ); assertEquals( 1, toolchains.size() ); }