Skip to content

Commit f7bb31a

Browse files
author
coursar
committed
feat(state)
1 parent 6144524 commit f7bb31a

File tree

7 files changed

+242
-1
lines changed

7 files changed

+242
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
3.2. [x] [Объектно-ориентированное программирование: ключевые принципы](oop2)
2626

27-
3.3. [ ] [Объекты с внутренним состоянием, управление состоянием при тестировании](state)
27+
3.3. [x] [Объекты с внутренним состоянием, управление состоянием при тестировании](state)
2828

2929
3.4. [x] [Композиция и зависимость объектов. Mockito при создании автотестов](composition)
3030

state/pom.xml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>ru.netology</groupId>
8+
<artifactId>smart-house</artifactId>
9+
<version>1.0-SNAPSHOT</version>
10+
11+
12+
<properties>
13+
<maven.compiler.source>11</maven.compiler.source>
14+
<maven.compiler.target>11</maven.compiler.target>
15+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
16+
</properties>
17+
18+
<dependencies>
19+
<dependency>
20+
<groupId>org.projectlombok</groupId>
21+
<artifactId>lombok</artifactId>
22+
<version>1.18.12</version>
23+
<scope>provided</scope>
24+
</dependency>
25+
<dependency>
26+
<groupId>org.junit.jupiter</groupId>
27+
<artifactId>junit-jupiter</artifactId>
28+
<version>5.4.2</version>
29+
<scope>test</scope>
30+
</dependency>
31+
</dependencies>
32+
33+
<build>
34+
<plugins>
35+
<plugin>
36+
<groupId>org.apache.maven.plugins</groupId>
37+
<artifactId>maven-surefire-plugin</artifactId>
38+
<version>2.22.2</version>
39+
</plugin>
40+
</plugins>
41+
</build>
42+
43+
</project>
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
package ru.netology.domain.constructor;
2+
3+
public class Conditioner {
4+
private int id;
5+
private String name = "noname";
6+
private int maxTemperature = 30;
7+
private int minTemperature = 15;
8+
private int currentTemperature = 22;
9+
private boolean on;
10+
11+
public Conditioner() {
12+
}
13+
14+
public Conditioner(
15+
int id,
16+
String name,
17+
int maxTemperature,
18+
int minTemperature,
19+
int currentTemperature,
20+
boolean on
21+
) {
22+
this.id = id;
23+
this.name = name;
24+
this.maxTemperature = maxTemperature;
25+
this.minTemperature = minTemperature;
26+
this.currentTemperature = currentTemperature;
27+
this.on = on;
28+
}
29+
30+
public int getId() {
31+
return id;
32+
}
33+
34+
public void setId(int id) {
35+
this.id = id;
36+
}
37+
38+
public String getName() {
39+
return name;
40+
}
41+
42+
public void setName(String name) {
43+
this.name = name;
44+
}
45+
46+
public int getMaxTemperature() {
47+
return maxTemperature;
48+
}
49+
50+
public void setMaxTemperature(int maxTemperature) {
51+
this.maxTemperature = maxTemperature;
52+
}
53+
54+
public int getMinTemperature() {
55+
return minTemperature;
56+
}
57+
58+
public void setMinTemperature(int minTemperature) {
59+
this.minTemperature = minTemperature;
60+
}
61+
62+
public int getCurrentTemperature() {
63+
return currentTemperature;
64+
}
65+
66+
public void setCurrentTemperature(int currentTemperature) {
67+
this.currentTemperature = currentTemperature;
68+
}
69+
70+
public boolean isOn() {
71+
return on;
72+
}
73+
74+
public void setOn(boolean on) {
75+
this.on = on;
76+
}
77+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package ru.netology.domain.field;
2+
3+
public class Conditioner {
4+
private int id;
5+
private String name = "noname";
6+
private int maxTemperature = 30;
7+
private int minTemperature = 15;
8+
private int currentTemperature = 22;
9+
// private int currentTemperature = (maxTemperature + minTemperature) / 2;
10+
private boolean on;
11+
12+
public int getId() {
13+
return id;
14+
}
15+
16+
public void setId(int id) {
17+
this.id = id;
18+
}
19+
20+
public String getName() {
21+
return name;
22+
}
23+
24+
public void setName(String name) {
25+
this.name = name;
26+
}
27+
28+
public int getMaxTemperature() {
29+
return maxTemperature;
30+
}
31+
32+
public void setMaxTemperature(int maxTemperature) {
33+
this.maxTemperature = maxTemperature;
34+
}
35+
36+
public int getMinTemperature() {
37+
return minTemperature;
38+
}
39+
40+
public void setMinTemperature(int minTemperature) {
41+
this.minTemperature = minTemperature;
42+
}
43+
44+
public int getCurrentTemperature() {
45+
return currentTemperature;
46+
}
47+
48+
public void setCurrentTemperature(int currentTemperature) {
49+
this.currentTemperature = currentTemperature;
50+
}
51+
52+
public boolean isOn() {
53+
return on;
54+
}
55+
56+
public void setOn(boolean on) {
57+
this.on = on;
58+
}
59+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package ru.netology.domain.lombok;
2+
3+
4+
import lombok.AllArgsConstructor;
5+
import lombok.Data;
6+
import lombok.NoArgsConstructor;
7+
8+
@NoArgsConstructor
9+
@AllArgsConstructor
10+
@Data
11+
public class Conditioner {
12+
private int id;
13+
private String name = "noname";
14+
private int maxTemperature = 30;
15+
private int minTemperature = 15;
16+
private int currentTemperature = 22;
17+
private boolean on;
18+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package ru.netology.domain.constructor;
2+
3+
import org.junit.jupiter.api.Test;
4+
5+
import static org.junit.jupiter.api.Assertions.*;
6+
7+
class ConditionerTest {
8+
@Test
9+
public void shouldUseConstructor() {
10+
Conditioner conditioner = new Conditioner(
11+
1,
12+
"Winter Cold",
13+
30,
14+
10,
15+
29,
16+
true
17+
);
18+
assertEquals(29, conditioner.getCurrentTemperature());
19+
}
20+
21+
@Test
22+
public void shouldUseNoArgsConstructor() {
23+
Conditioner conditioner = new Conditioner();
24+
assertEquals(22, conditioner.getCurrentTemperature());
25+
}
26+
}
27+
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package ru.netology.domain.field;
2+
3+
import org.junit.jupiter.api.Test;
4+
5+
import static org.junit.jupiter.api.Assertions.*;
6+
7+
class ConditionerTest {
8+
@Test
9+
public void shouldInitFields() {
10+
Conditioner conditioner = new Conditioner();
11+
12+
assertEquals("noname", conditioner.getName());
13+
assertEquals(30, conditioner.getMaxTemperature());
14+
assertEquals(15, conditioner.getMinTemperature());
15+
assertEquals(22, conditioner.getCurrentTemperature());
16+
}
17+
}

0 commit comments

Comments
 (0)