summaryrefslogtreecommitdiff
path: root/plugins/typeMigration/test/com/intellij/refactoring/TypeMigrationByAtomicRuleTest.java
blob: 80658077e986f313d94d1f929995a7e6cc48f639 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/*
 * User: anna
 * Date: 19-Aug-2009
 */
package com.intellij.refactoring;

import com.intellij.psi.PsiType;
import org.jetbrains.annotations.NotNull;

import java.util.concurrent.atomic.AtomicReferenceArray;
import java.util.concurrent.atomic.AtomicIntegerArray;

public class TypeMigrationByAtomicRuleTest extends TypeMigrationTestBase{
  @NotNull
  @Override
  protected String getTestRoot() {
    return "/refactoring/typeMigrationByAtomic/";
  }

  private void doTestDirectMigration() throws Exception {
    doTestFieldType("i", PsiType.INT, myJavaFacade.getElementFactory().createTypeFromText("java.util.concurrent.atomic.AtomicInteger", null));
  }


  public void testDirectIncrementDecrement() throws Exception {
    doTestDirectMigration();
  }

  public void testDirectAssignments() throws Exception {
    doTestDirectMigration();
  }

  public void testDirectConditions() throws Exception {
    doTestFieldType("b", PsiType.BOOLEAN, myJavaFacade.getElementFactory().createTypeFromText("java.util.concurrent.atomic.AtomicBoolean", null));
  }


  public void testDirectByte() throws Exception {
    doTestFieldType("b", PsiType.BYTE, myJavaFacade.getElementFactory().createTypeFromText("java.util.concurrent.atomic.AtomicReference<java.lang.Byte>", null));
  }

  public void testDirectString() throws Exception {
    doTestFieldType("s", myJavaFacade.getElementFactory().createTypeFromText("java.lang.String", null),
                    myJavaFacade.getElementFactory().createTypeFromText("java.util.concurrent.atomic.AtomicReference<java.lang.String>", null));
  }

  public void testDirectForeach() throws Exception {
    doTestFieldType("lst", myJavaFacade.getElementFactory().createTypeFromText("java.util.List<java.lang.String>", null),
                    myJavaFacade.getElementFactory().createTypeFromText("java.util.concurrent.atomic.AtomicReference<java.util.List<java.lang.String>>", null));
  }

  public void testDirectStringArray() throws Exception {
    doTestFieldType("s", myJavaFacade.getElementFactory().createTypeFromText("java.lang.String", null).createArrayType(),
                    myJavaFacade.getElementFactory().createTypeFromText(AtomicReferenceArray.class.getName() + "<java.lang.String>", null));
  }

  public void testDirectIntArray() throws Exception {
    doTestFieldType("a", PsiType.INT.createArrayType(),
                    myJavaFacade.getElementFactory().createTypeFromText(AtomicIntegerArray.class.getName(), null));
  }

  private void doTestReverseMigration() throws Exception {
    doTestFieldType("i", myJavaFacade.getElementFactory().createTypeFromText("java.util.concurrent.atomic.AtomicInteger", null), PsiType.INT);
  }


  public void testReverseIncrementDecrement() throws Exception {
    doTestReverseMigration();
  }

  public void testReverseAssignments() throws Exception {
    doTestReverseMigration();
  }

  public void testReverseConditions() throws Exception {
    doTestFieldType("b", myJavaFacade.getElementFactory().createTypeFromText("java.util.concurrent.atomic.AtomicBoolean", null), PsiType.BOOLEAN);
  }

  public void testReverseByte() throws Exception {
    doTestFieldType("b", myJavaFacade.getElementFactory().createTypeFromText("java.util.concurrent.atomic.AtomicReference<java.lang.Byte>", null), PsiType.BYTE);
  }

   public void testReverseString() throws Exception {
    doTestFieldType("s",
                    myJavaFacade.getElementFactory().createTypeFromText("java.util.concurrent.atomic.AtomicReference<java.lang.String>", null),
                    myJavaFacade.getElementFactory().createTypeFromText("java.lang.String", null));
  }

   public void testReverseStringArray() throws Exception {
    doTestFieldType("s",
                    myJavaFacade.getElementFactory().createTypeFromText("java.util.concurrent.atomic.AtomicReferenceArray<java.lang.String>", null),
                    myJavaFacade.getElementFactory().createTypeFromText("java.lang.String", null).createArrayType());
  }

  public void testReverseIntArray() throws Exception {
    doTestFieldType("a",
                    myJavaFacade.getElementFactory().createTypeFromText("java.util.concurrent.atomic.AtomicIntegerArray", null),
                    PsiType.INT.createArrayType());
  }
}