BAEL-5675 - variable initialization on declaration vs on constructor (#12800)

* BAEL-5675 - variable initialization on declaration vs on constructor

* moved classes under a different project
This commit is contained in:
tudormarc 2022-10-07 17:57:45 +03:00 committed by GitHub
parent 4a740338e4
commit ae96297bc2
3 changed files with 35 additions and 0 deletions

View File

@ -0,0 +1,13 @@
package com.baeldung.variableInitialization;
public class A {
private B b = new B();
public A() {
this.b = new B();
}
public A(B b) {
this.b = b;
}
}

View File

@ -0,0 +1,4 @@
package com.baeldung.variableInitialization;
public class B {
}

View File

@ -0,0 +1,18 @@
package com.baeldung.variableinitialization;
import static org.mockito.Mockito.mock;
import org.junit.jupiter.api.Test;
import com.baeldung.variableInitialization.A;
import com.baeldung.variableInitialization.B;
public class AUnitTest {
@Test
public void whenCreatingTest_useDependencyInjection() {
// given
B b = mock(B.class);
A a = new A(b);
}
}