update copyright
[fedora-idea.git] / plugins / junit / src / com / intellij / execution / junit2 / info / TestInfoFactory.java
blob86d83186eb23601d1b9c63bbb53d889ae3f6f141
1 /*
2 * Copyright 2000-2009 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package com.intellij.execution.junit2.info;
19 import com.intellij.execution.junit2.segments.ObjectReader;
20 import com.intellij.rt.execution.junit.segments.PoolOfTestTypes;
21 import com.intellij.util.containers.HashMap;
22 import org.jetbrains.annotations.NotNull;
24 import java.util.Map;
26 public abstract class TestInfoFactory {
27 private static final Map<String,Class> KNOWN_PSI_LOCATOR_CLASSES = new HashMap<String, Class>();
29 static {
30 KNOWN_PSI_LOCATOR_CLASSES.put(PoolOfTestTypes.TEST_METHOD, TestCaseInfo.class);
31 KNOWN_PSI_LOCATOR_CLASSES.put(PoolOfTestTypes.TEST_CLASS, TestClassInfo.class);
32 KNOWN_PSI_LOCATOR_CLASSES.put(PoolOfTestTypes.ALL_IN_PACKAGE, AllInPackageInfo.class);
35 @NotNull
36 public static TestInfo readInfoFrom(final ObjectReader reader) {
37 final String testType = reader.readLimitedString();
38 Class infoClass = KNOWN_PSI_LOCATOR_CLASSES.get(testType);
39 if (infoClass == null)
40 infoClass = DefaultTestInfo.class;
41 final TestInfoImpl info;
42 try {
43 info = (TestInfoImpl) infoClass.newInstance();
44 } catch (Exception e) {
45 throw new RuntimeException(e);
47 info.readPacketFrom(reader);
48 info.setTestCount(reader.readInt());
49 return info;