Exemplo n.º 1
0
  @Before
  public void onSetup() throws Exception {
    toolchainManager = new DefaultToolchainManager();

    MockitoAnnotations.initMocks(this);

    toolchainManager.factories = new HashMap<>();
    toolchainManager.factories.put("basic", toolchainFactory_basicType);
    toolchainManager.factories.put("rare", toolchainFactory_rareType);
  }
Exemplo n.º 2
0
  @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());
  }
Exemplo n.º 3
0
  @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());
  }
Exemplo n.º 4
0
  @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.");
  }
Exemplo n.º 5
0
  @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(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());
  }