Skip to content

Commit 2840347

Browse files
myluckagainKevinGilmore
authored andcommitted
BAEL-1612 (eugenp#3811)
* bael-1612 * line
1 parent f948ea0 commit 2840347

5 files changed

Lines changed: 69 additions & 0 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.baeldung.finalkeyword;
2+
3+
public class BlackCat {
4+
5+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package com.baeldung.finalkeyword;
2+
3+
public class BlackDog extends Dog {
4+
// public void sound() {
5+
// }
6+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.baeldung.finalkeyword;
2+
3+
public final class Cat {
4+
5+
private int weight;
6+
7+
public int getWeight() {
8+
return weight;
9+
}
10+
11+
public void setWeight(int weight) {
12+
this.weight = weight;
13+
}
14+
15+
public void methodWithFinalArguments(final int x) {
16+
// x=1;
17+
}
18+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.baeldung.finalkeyword;
2+
3+
public class Dog {
4+
5+
public final void sound() {
6+
}
7+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.baeldung.finalkeyword;
2+
3+
import org.junit.Test;
4+
import static org.junit.Assert.*;
5+
6+
public class FinalUnitTest {
7+
8+
@Test
9+
public void whenChangedFinalClassProperties_thenChanged() {
10+
Cat cat = new Cat();
11+
cat.setWeight(1);
12+
13+
assertEquals(1, cat.getWeight());
14+
15+
}
16+
17+
@Test
18+
public void whenFinalVariableAssign_thenOnlyOnce() {
19+
final int i;
20+
i = 1;
21+
// i=2;
22+
}
23+
24+
@Test
25+
public void whenChangedFinalReference_thenChanged() {
26+
27+
final Cat cat = new Cat();
28+
// cat=new Cat();
29+
cat.setWeight(5);
30+
31+
assertEquals(5, cat.getWeight());
32+
}
33+
}

0 commit comments

Comments
 (0)