/**
   * Asserts that NODE_NAME works on the master computer, as the MasterComputer.getName() returns
   * null.
   */
  @Test
  public void assertMasterNodeNameIsResolved() {
    when(computer.getName()).thenReturn("");

    BuildVariableResolver resolver = new BuildVariableResolver(project, computer);
    assertEquals("Variable resolution was incorrect", "MASTER", resolver.resolve("NODE_NAME"));
    verifyZeroInteractions(project);
  }
  @Test
  public void assertJobNameIsResolved() {
    when(project.getName()).thenReturn("ThisIsAJob");

    BuildVariableResolver resolver = new BuildVariableResolver(project, computer);
    assertEquals("Variable resolution was incorrect", "ThisIsAJob", resolver.resolve("JOB_NAME"));
    verifyZeroInteractions(computer);
  }
  @Test
  public void assertJobNameWithoutComputerIsResolved() {
    when(project.getName()).thenReturn("ThisIsAJob");

    BuildVariableResolver resolver = new BuildVariableResolver(project);
    assertEquals("Variable resolution was incorrect", "ThisIsAJob", resolver.resolve("JOB_NAME"));
    assertNull("Variable resolution was performed", resolver.resolve("NONE_EXISTING_KEY"));
  }
  @Test
  public void assertNoComputeraDoesNotThrowNPEWhenResolvingNodeName() {
    when(launcher.getComputer()).thenReturn(null);

    BuildVariableResolver resolver = new BuildVariableResolver(project, launcher);
    assertNull("Variable resolution was incorrect", resolver.resolve("NODE_NAME"));
    verifyZeroInteractions(project);
  }
  @Test
  public void assertNodeNameIsResolved() {
    Computer computer = mock(Computer.class);
    when(launcher.getComputer()).thenReturn(computer);
    when(computer.getName()).thenReturn("AKIRA");

    BuildVariableResolver resolver = new BuildVariableResolver(project, launcher);
    assertEquals("Variable resolution was incorrect", "AKIRA", resolver.resolve("NODE_NAME"));
    verifyZeroInteractions(project);
  }
  @Test
  public void assertComputerUserNameIsResolved() throws Exception {
    Map<Object, Object> map = new HashMap<Object, Object>();
    map.put("user.name", "Other_user");

    when(computer.getSystemProperties()).thenReturn(map);

    BuildVariableResolver resolver = new BuildVariableResolver(project, computer);
    assertEquals("Variable resolution was incorrect", "Other_user", resolver.resolve("USER_NAME"));
    verifyZeroInteractions(project);
  }
  @Test
  public void assertComputerEnvVarIsResolved() throws Exception {
    EnvVars map = new EnvVars();
    map.put("ENV_VAR", "This is an env var");

    when(computer.getEnvironment()).thenReturn(map);

    BuildVariableResolver resolver = new BuildVariableResolver(project, computer);
    assertEquals(
        "Variable resolution was incorrect", "This is an env var", resolver.resolve("ENV_VAR"));
    verifyZeroInteractions(project);
  }
  @Test
  public void assertBuildEnvVarIsResolved() throws Exception {
    EnvVars map = new EnvVars();
    map.put("BUILD_ID", "121212");

    when(build.getProject()).thenReturn(project);
    when(build.getEnvironment(TaskListener.NULL)).thenReturn(map);

    BuildVariableResolver resolver = new BuildVariableResolver(build, computer);
    assertEquals("Variable resolution was incorrect", "121212", resolver.resolve("BUILD_ID"));
    verify(build).getEnvironment(TaskListener.NULL);
    verifyZeroInteractions(project);
  }
  @Test
  public void assertBuildEnvVarIsResolved() throws Exception {
    HashMap<String, String> map = new HashMap<String, String>();
    map.put("BUILD_ID", "121212");

    when(build.getProject()).thenReturn(project);
    when(build.getEnvVars()).thenReturn(map);

    BuildVariableResolver resolver = new BuildVariableResolver(build, launcher);
    assertEquals("Variable resolution was incorrect", "121212", resolver.resolve("BUILD_ID"));
    verify(build).getEnvVars();
    verifyZeroInteractions(project);
  }
  @Test
  public void assertComputerEnvVarIsResolved() throws Exception {
    Map<String, String> map = new HashMap<String, String>();
    map.put("ENV_VAR", "This is an env var");

    Computer computer = mock(Computer.class);
    when(launcher.getComputer()).thenReturn(computer);
    when(computer.getEnvVars()).thenReturn(map);

    BuildVariableResolver resolver = new BuildVariableResolver(project, launcher);
    assertEquals(
        "Variable resolution was incorrect", "This is an env var", resolver.resolve("ENV_VAR"));
    verifyZeroInteractions(project);
  }