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:
parent
4a740338e4
commit
ae96297bc2
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
package com.baeldung.variableInitialization;
|
||||
|
||||
public class B {
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue