Subject.java:
Код: Выделить всё
package inject_mocks_test;
public class Subject {
private final Section section;
public Subject(Section section) {
this.section = section;
}
public Section getSection() {
return section;
}
}
Код: Выделить всё
package inject_mocks_test;
public class Section {}
Код: Выделить всё
package inject_mocks_test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import static org.testng.Assert.assertEquals;
public class SubjectTest {
@Mock
Section section;
@InjectMocks
Subject subject;
@BeforeMethod
public void setup() {
MockitoAnnotations.initMocks(this);
}
@Test
public void test1() {
assertEquals(section, subject.getSection());
}
@Test
public void test2() {
assertEquals(section, subject.getSection());
}
}
Подробнее здесь: https://stackoverflow.com/questions/200 ... nal-fields