package com.facebook.buck.event.listener;

import com.facebook.buck.test.TestCaseSummary;
import com.facebook.buck.test.TestResultSummary;
import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;

import java.util.List;
import java.util.concurrent.TimeUnit;

class TestMethodResultMapBuilder implements ResultBuilder {

  @Override
  public List<TestRun.Result> build(
      ImmutableSet<String> contacts,
      TestCaseSummary testCaseSummary) {
    ImmutableList.Builder<TestRun.Result> builder = new ImmutableList.Builder<>();
    for (TestResultSummary testResultSummary : testCaseSummary.getTestResults()) {
      TestRun.Status status = TestRun.Status.convertResultType(testResultSummary.getType());
      String name = String.format(
          "%s#%s",
          testCaseSummary.getTestCaseName(),
          testResultSummary.getTestName());
      builder.add(new TestRun.Result(
          /* name */ name,
          /* contacts */ contacts,
          /* durationSecs */ testResultSummary.getTime() / 1000,
          /* status */ status,
          /* endedTime */ TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis()),
          /* summary */ status.toString().toUpperCase(),
          /* details */ buildDetails(testResultSummary)));
    }
    return builder.build();
  }

  private String buildDetails(TestResultSummary testResultSummary) {
    ImmutableList.Builder<String> lines = new ImmutableList.Builder<>();
    TestResultFormatter.reportResultSummary(lines, testResultSummary);
    return Joiner.on("\n").join(lines.build());
  }
}

@@ -1,8 +1,615 @@
+/*%0A * Copyright 2014-present Facebook, Inc.%0A *%0A * Licensed under the Apache License, Version 2.0 (the %22License%22); you may%0A * not use this file except in compliance with the License. You may obtain%0A * a copy of the License at%0A *%0A *     http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS, WITHOUT%0A * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the%0A * License for the specific language governing permissions and limitations%0A * under the License.%0A */%0A%0A
 package 

Fix lint error *grumble grumble grumble*