* bael-1612

* line
This commit is contained in:
myluckagain 2018-03-23 18:36:49 +05:00 committed by KevinGilmore
parent f948ea0f46
commit 2840347d60
5 changed files with 69 additions and 0 deletions

View File

@ -0,0 +1,5 @@
package com.baeldung.finalkeyword;
public class BlackCat {
}

View File

@ -0,0 +1,6 @@
package com.baeldung.finalkeyword;
public class BlackDog extends Dog {
// public void sound() {
// }
}

View File

@ -0,0 +1,18 @@
package com.baeldung.finalkeyword;
public final class Cat {
private int weight;
public int getWeight() {
return weight;
}
public void setWeight(int weight) {
this.weight = weight;
}
public void methodWithFinalArguments(final int x) {
// x=1;
}
}

View File

@ -0,0 +1,7 @@
package com.baeldung.finalkeyword;
public class Dog {
public final void sound() {
}
}

View File

@ -0,0 +1,33 @@
package com.baeldung.finalkeyword;
import org.junit.Test;
import static org.junit.Assert.*;
public class FinalUnitTest {
@Test
public void whenChangedFinalClassProperties_thenChanged() {
Cat cat = new Cat();
cat.setWeight(1);
assertEquals(1, cat.getWeight());
}
@Test
public void whenFinalVariableAssign_thenOnlyOnce() {
final int i;
i = 1;
// i=2;
}
@Test
public void whenChangedFinalReference_thenChanged() {
final Cat cat = new Cat();
// cat=new Cat();
cat.setWeight(5);
assertEquals(5, cat.getWeight());
}
}