Due to a ransomware attack, the wiki was reverted to a July 2022 version. . We apologize for the lack of a more recent valid backup.
...
Sometimes when writing a test, you'll need to access data from a class that does not have a public API to access the data. In ONOS, we try to not add interfaces only used by test code. Instead, we have utility methods that use the Java reflection API to access this private data. In this example, the test verifies the contents of the private intentsByLink
member are correct, using the TestUtils.getField()
method.
Code Block | ||||
---|---|---|---|---|
| ||||
import org.onlab.junit.TestUtils; @Test public void testLeaderEvents() throws Exception { final ObjectiveTracker tracker = new ObjectiveTracker(); final SetMultimap<LinkKey, IntentId> intentsByLink = TestUtils.getField(tracker, "intentsByLink"); assertThat(intentsByLink.size(), is(0)); } |
...