Skip to content

Commit 454b4e3

Browse files
committed
feat(oop1)
1 parent 7cbe000 commit 454b4e3

File tree

6 files changed

+169
-1
lines changed

6 files changed

+169
-1
lines changed

README.md

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

2121
## Блок 3. ООП
2222

23-
3.1. [ ] [Объектно-ориентированное программирование и проектирование](oop1)
23+
3.1. [x] [Объектно-ориентированное программирование и проектирование](oop1)
2424

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

oop1/smart-house/pom.xml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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+
<properties>
12+
<maven.compiler.source>11</maven.compiler.source>
13+
<maven.compiler.target>11</maven.compiler.target>
14+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
15+
</properties>
16+
17+
<dependencies>
18+
<dependency>
19+
<groupId>org.junit.jupiter</groupId>
20+
<artifactId>junit-jupiter</artifactId>
21+
<version>5.4.2</version>
22+
<scope>test</scope>
23+
</dependency>
24+
</dependencies>
25+
26+
<build>
27+
<plugins>
28+
<plugin>
29+
<groupId>org.apache.maven.plugins</groupId>
30+
<artifactId>maven-surefire-plugin</artifactId>
31+
<version>2.22.2</version>
32+
</plugin>
33+
</plugins>
34+
</build>
35+
36+
</project>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package ru.netology;
2+
3+
public class Conditioner {
4+
String name;
5+
int maxTemperature;
6+
int minTemperature;
7+
int currentTemperature;
8+
boolean on;
9+
}
10+
11+
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
package ru.netology;
2+
3+
public class ConditionerAdvanced {
4+
private String name;
5+
private int maxTemperature;
6+
private int minTemperature;
7+
private int currentTemperature;
8+
private boolean on;
9+
10+
public String getName() {
11+
return name;
12+
}
13+
14+
public void setName(String name) {
15+
this.name = name;
16+
}
17+
18+
public int getMaxTemperature() {
19+
return maxTemperature;
20+
}
21+
22+
public void setMaxTemperature(int maxTemperature) {
23+
this.maxTemperature = maxTemperature;
24+
}
25+
26+
public int getMinTemperature() {
27+
return minTemperature;
28+
}
29+
30+
public void setMinTemperature(int minTemperature) {
31+
this.minTemperature = minTemperature;
32+
}
33+
34+
public int getCurrentTemperature() {
35+
return currentTemperature;
36+
}
37+
38+
public void setCurrentTemperature(int currentTemperature) {
39+
if (currentTemperature > maxTemperature) {
40+
return;
41+
}
42+
if (currentTemperature < minTemperature) {
43+
return;
44+
}
45+
// здесь уверены, что все проверки прошли
46+
this.currentTemperature = currentTemperature;
47+
}
48+
49+
// public void setCurrentTemperature(int currentTemperature) {
50+
// if (currentTemperature <= maxTemperature) {
51+
// if (currentTemperature >= minTemperature) {
52+
// this.currentTemperature = currentTemperature;
53+
// }
54+
// }
55+
// }
56+
57+
public boolean isOn() {
58+
return on;
59+
}
60+
61+
public void setOn(boolean on) {
62+
this.on = on;
63+
}
64+
}
65+
66+
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package ru.netology;
2+
3+
import org.junit.jupiter.api.Test;
4+
5+
import static org.junit.jupiter.api.Assertions.*;
6+
7+
class ConditionerAdvancedTest {
8+
@Test
9+
public void shouldGetAndSet() {
10+
ConditionerAdvanced conditioner = new ConditionerAdvanced();
11+
String expected = "Кондишн";
12+
13+
assertNull(conditioner.getName());
14+
conditioner.setName(expected);
15+
assertEquals(expected, conditioner.getName());
16+
}
17+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package ru.netology;
2+
3+
import org.junit.jupiter.api.Disabled;
4+
import org.junit.jupiter.api.Test;
5+
6+
import static org.junit.jupiter.api.Assertions.*;
7+
8+
class ConditionerTest {
9+
@Test
10+
public void shouldCreate() {
11+
Conditioner conditioner = new Conditioner();
12+
}
13+
14+
@Test
15+
public void shouldInitFieldToZeroValues() {
16+
Conditioner conditioner = new Conditioner();
17+
assertNull(conditioner.name);
18+
assertEquals(0, conditioner.maxTemperature);
19+
assertEquals(0, conditioner.minTemperature);
20+
assertEquals(0, conditioner.currentTemperature);
21+
assertFalse(conditioner.on);
22+
}
23+
24+
@Test
25+
@Disabled
26+
public void shouldThrowNPE() {
27+
Conditioner conditioner = new Conditioner();
28+
assertEquals(0, conditioner.name.length());
29+
}
30+
31+
@Test
32+
public void shouldChangeFields() {
33+
Conditioner conditioner = new Conditioner();
34+
assertEquals(0, conditioner.currentTemperature);
35+
conditioner.currentTemperature = -100;
36+
assertEquals(-100, conditioner.currentTemperature);
37+
}
38+
}

0 commit comments

Comments
 (0)