Skip to content

Commit a20c83a

Browse files
anchoulsonewhl
authored andcommitted
Added tests using the test framework
1 parent c1a2f15 commit a20c83a

File tree

8 files changed

+446
-65
lines changed

8 files changed

+446
-65
lines changed

MovingCode/WhatIsMoveMethodRefactoring/FindMoreAppropriateClassesForMethodsPractice/src/main/java/jetbrains/refactoring/course/moving/car/Car.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22

33
public class Car {
44
private final int gearsNumber;
5-
private boolean engineStarted;
6-
private int gear;
5+
private boolean engineStarted = false;
6+
private int gear = 0;
77

88
public Car(int gearsNumber) {
99
this.gearsNumber = gearsNumber;
1010
}
1111

12-
public void setGear(int gear) {
12+
private void setGear(int gear) {
1313
if (gear > gearsNumber || gear < 0) {
1414
throw new IllegalStateException();
1515
}

MovingCode/WhatIsMoveMethodRefactoring/FindMoreAppropriateClassesForMethodsPractice/test/MovingMethodsTest.java

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
import org.jetbrains.academy.test.system.core.models.Visibility;
2+
import org.jetbrains.academy.test.system.core.models.classes.ClassType;
3+
import org.jetbrains.academy.test.system.core.models.classes.TestClass;
4+
import org.jetbrains.academy.test.system.core.models.method.TestMethod;
5+
import org.jetbrains.academy.test.system.core.models.variable.TestVariable;
16
import org.jetbrains.academy.test.system.java.test.BaseIjTestClass;
27
import org.junit.jupiter.api.Assertions;
38
import org.junit.jupiter.api.BeforeAll;
@@ -7,11 +12,16 @@
712
import java.nio.file.Files;
813
import java.nio.file.Path;
914
import java.nio.file.Paths;
15+
import java.util.List;
16+
17+
import static java.util.Collections.emptyList;
1018

1119
public class MovingMethodsTest extends BaseIjTestClass {
1220

1321
private static String carText;
1422
private static String driverText;
23+
private static TestClass driverClass;
24+
private static TestClass carClass;
1525

1626
@BeforeAll
1727
static void beforeAll() throws IOException {
@@ -22,6 +32,110 @@ static void beforeAll() throws IOException {
2232
Path driverPath = Paths.get(taskDirectoryPath,
2333
"src/main/java/jetbrains/refactoring/course/moving/driver/Driver.java");
2434
driverText = Files.readString(driverPath);
35+
36+
driverClass = new TestClass(
37+
"Driver",
38+
"jetbrains.refactoring.course.moving.driver",
39+
Visibility.PUBLIC,
40+
ClassType.CLASS,
41+
List.of(
42+
new TestVariable(
43+
"car",
44+
"Car",
45+
null,
46+
Visibility.PRIVATE,
47+
false,
48+
true,
49+
false
50+
)
51+
),
52+
List.of(
53+
new TestMethod(
54+
"changeCar",
55+
"void",
56+
List.of(
57+
new TestVariable("car", "Car")
58+
),
59+
Visibility.PUBLIC
60+
),
61+
new TestMethod(
62+
"driving",
63+
"void",
64+
List.of(new TestVariable("destination", "String")),
65+
Visibility.PRIVATE
66+
),
67+
new TestMethod(
68+
"driveTo",
69+
"void",
70+
List.of(new TestVariable("destination", "String")),
71+
Visibility.PUBLIC
72+
)
73+
),
74+
false,
75+
emptyList(),
76+
emptyList()
77+
);
78+
79+
carClass = new TestClass(
80+
"Car",
81+
"jetbrains.refactoring.course.moving.car",
82+
Visibility.PUBLIC,
83+
ClassType.CLASS,
84+
List.of(
85+
new TestVariable(
86+
"gearsNumber",
87+
"int",
88+
null,
89+
Visibility.PRIVATE,
90+
true,
91+
true,
92+
false
93+
),
94+
new TestVariable(
95+
"engineStarted",
96+
"boolean",
97+
"false",
98+
Visibility.PRIVATE,
99+
false,
100+
false,
101+
false
102+
),
103+
new TestVariable(
104+
"gear",
105+
"int",
106+
"0",
107+
Visibility.PRIVATE,
108+
false,
109+
false,
110+
false
111+
)
112+
),
113+
List.of(
114+
new TestMethod(
115+
"setGear",
116+
"void",
117+
List.of(
118+
new TestVariable("gear", "int")
119+
),
120+
Visibility.PRIVATE
121+
),
122+
new TestMethod(
123+
"start",
124+
"void",
125+
emptyList(),
126+
Visibility.PUBLIC
127+
),
128+
new TestMethod(
129+
"stop",
130+
"void",
131+
emptyList(),
132+
Visibility.PUBLIC
133+
)
134+
),
135+
false,
136+
emptyList(),
137+
emptyList()
138+
);
25139
}
26140

27141
@Test
@@ -43,4 +157,18 @@ public void testStartAndStopMethodRemovedFromDriverClass() throws Exception {
43157
Assertions.assertFalse(hasMethod("stop"),
44158
"Please, remove the \"stop\" method from the Driver class");
45159
}
160+
161+
@Test
162+
public void driverClassTest() {
163+
Class<?> clazz = driverClass.checkBaseDefinition();
164+
driverClass.checkFieldsDefinition(clazz, true);
165+
driverClass.checkDeclaredMethods(clazz);
166+
}
167+
168+
@Test
169+
public void carClassTest() {
170+
Class<?> clazz = carClass.checkBaseDefinition();
171+
carClass.checkFieldsDefinition(clazz, true);
172+
carClass.checkDeclaredMethods(clazz);
173+
}
46174
}

MovingCode/WhatIsMoveMethodRefactoring/FindMoreAppropriateFilesForClassesPractice/src/main/java/jetbrains/refactoring/course/moving/car/Car.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
public class Car {
44
private final int gearsNumber;
5-
public boolean engineStarted;
6-
private int gear;
5+
public boolean engineStarted = false;
6+
private int gear = 0;
77

88
public Car(int gearsNumber) {
99
this.gearsNumber = gearsNumber;

MovingCode/WhatIsMoveMethodRefactoring/WhatIsMoveMethodRefactoring/src/main/java/jetbrains/refactoring/course/moving/Main.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ public static void main(String[] args) {
1010

1111
class Car {
1212
private final int gearsNumber;
13-
public boolean engineStarted;
14-
private int gear;
13+
public boolean engineStarted = false;
14+
private int gear = 0;
1515

1616
public Car(int gearsNumber) {
1717
this.gearsNumber = gearsNumber;

RefactoringToDesignPatterns/FacadePatternPractice/Practice/test/FacadePatternTest.java

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
import org.jetbrains.academy.test.system.core.models.Visibility;
2+
import org.jetbrains.academy.test.system.core.models.classes.ClassType;
3+
import org.jetbrains.academy.test.system.core.models.classes.TestClass;
4+
import org.jetbrains.academy.test.system.core.models.method.TestMethod;
5+
import org.jetbrains.academy.test.system.core.models.variable.TestVariable;
16
import org.jetbrains.academy.test.system.java.test.BaseIjTestClass;
27
import org.junit.jupiter.api.Assertions;
38
import org.junit.jupiter.api.BeforeAll;
@@ -7,17 +12,81 @@
712
import java.nio.file.Files;
813
import java.nio.file.Path;
914
import java.nio.file.Paths;
15+
import java.util.List;
16+
17+
import static java.util.Collections.emptyList;
1018

1119
public class FacadePatternTest extends BaseIjTestClass {
1220

1321
private static String facadeText;
1422

23+
private static TestClass facadeClass;
24+
1525
@BeforeAll
1626
static void beforeAll() throws IOException {
1727
String taskDirectoryPath = System.getProperty("user.dir");
1828
Path facadeFilePath = Paths.get(taskDirectoryPath,
1929
"src/main/java/jetbrains/refactoring/course/patterns/VideoConversionFacade.java");
2030
facadeText = Files.readString(facadeFilePath);
31+
32+
facadeClass = new TestClass(
33+
"VideoConversionFacade",
34+
"jetbrains.refactoring.course.patterns",
35+
Visibility.PUBLIC,
36+
ClassType.CLASS,
37+
List.of(
38+
new TestVariable(
39+
"videoLoader",
40+
"VideoLoader",
41+
"new VideoLoader()",
42+
Visibility.PRIVATE,
43+
true,
44+
false,
45+
false
46+
),
47+
new TestVariable(
48+
"videoProcessor",
49+
"VideoProcessor",
50+
"new VideoProcessor()",
51+
Visibility.PRIVATE,
52+
true,
53+
false,
54+
false
55+
),
56+
new TestVariable(
57+
"videoEncoder",
58+
"VideoEncoder",
59+
"new VideoEncoder()",
60+
Visibility.PRIVATE,
61+
true,
62+
false,
63+
false
64+
),
65+
new TestVariable(
66+
"videoSaver",
67+
"VideoSaver",
68+
"new VideoSaver()",
69+
Visibility.PRIVATE,
70+
true,
71+
false,
72+
false
73+
)
74+
),
75+
List.of(
76+
new TestMethod(
77+
"convertVideo",
78+
"void",
79+
List.of(
80+
new TestVariable("originalVideoName", "String"),
81+
new TestVariable("processedVideoName", "String")
82+
),
83+
Visibility.PUBLIC
84+
)
85+
),
86+
false,
87+
emptyList(),
88+
emptyList()
89+
);
2190
}
2291

2392
@Test
@@ -44,5 +113,9 @@ public void videoConversionFacadeClassTest() throws Exception {
44113
"Please, extract the statements related to encoding the video into the \"convertVideo\" method.");
45114
Assertions.assertTrue(hasExpressionWithParent("videoSaver.saveVideo", "convertVideo", true),
46115
"Please, extract the statements related to saving the video into the \"convertVideo\" method.");
116+
117+
Class<?> clazz = facadeClass.checkBaseDefinition();
118+
facadeClass.checkFieldsDefinition(clazz, true);
119+
facadeClass.checkDeclaredMethods(clazz);
47120
}
48121
}

RefactoringToDesignPatterns/FactoryMethodPatternPractice/Practice/test/FactoryMethodPatternTest.java

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
import org.jetbrains.academy.test.system.core.models.Visibility;
2+
import org.jetbrains.academy.test.system.core.models.classes.ClassType;
3+
import org.jetbrains.academy.test.system.core.models.classes.TestClass;
4+
import org.jetbrains.academy.test.system.core.models.method.TestMethod;
5+
import org.jetbrains.academy.test.system.core.models.variable.TestVariable;
16
import org.jetbrains.academy.test.system.java.test.BaseIjTestClass;
27
import org.junit.jupiter.api.Assertions;
38
import org.junit.jupiter.api.BeforeAll;
@@ -7,31 +12,49 @@
712
import java.nio.file.Files;
813
import java.nio.file.Path;
914
import java.nio.file.Paths;
15+
import java.util.List;
1016

11-
public class FactoryMethodPatternTest extends BaseIjTestClass {
17+
import static java.util.Collections.emptyList;
1218

13-
private static String factoryText;
19+
public class FactoryMethodPatternTest extends BaseIjTestClass {
1420
private static String mainText;
21+
private static TestClass factoryClass;
1522

1623
@BeforeAll
1724
static void beforeAll() throws IOException {
1825
String taskDirectoryPath = System.getProperty("user.dir");
19-
Path factoryFilePath = Paths.get(taskDirectoryPath,
20-
"src/main/java/jetbrains/refactoring/course/patterns/TransportationServiceFactory.java");
21-
factoryText = Files.readString(factoryFilePath);
2226
Path mainPath = Paths.get(taskDirectoryPath,
2327
"src/main/java/jetbrains/refactoring/course/patterns/Main.java");
2428
mainText = Files.readString(mainPath);
29+
30+
factoryClass = new TestClass(
31+
"TransportationServiceFactory",
32+
"jetbrains.refactoring.course.patterns",
33+
Visibility.PUBLIC,
34+
ClassType.CLASS,
35+
emptyList(),
36+
List.of(
37+
new TestMethod(
38+
"getTransportation",
39+
"Transport",
40+
List.of(
41+
new TestVariable("transport", "String")
42+
),
43+
Visibility.PUBLIC
44+
)
45+
),
46+
false,
47+
emptyList(),
48+
emptyList()
49+
);
2550
}
2651

2752
@Test
28-
public void transportationServiceFactoryTest() throws Exception {
29-
setUp();
30-
myFixture.configureByText("TransportationServiceFactory.java", factoryText);
31-
Assertions.assertTrue(hasClass("TransportationServiceFactory"),
32-
"Please, create a TransportationServiceFactory class");
33-
Assertions.assertTrue(hasMethod("getTransportation"),
34-
"Please, define the getTransportation method in TransportationServiceFactory class");
53+
public void transportationServiceFactoryTest() {
54+
Assertions.assertDoesNotThrow(() -> {
55+
Class<?> clazz = factoryClass.checkBaseDefinition();
56+
factoryClass.checkDeclaredMethods(clazz);
57+
}, "Please, create a TransportationServiceFactory class with getTransportation method");
3558
}
3659

3760
@Test

0 commit comments

Comments
 (0)