Line 8 marks the Test Case class to be run with the MockitoJUnitRunner which allows for the use of the @Mock annotations to define mock objects at the Class level.
Lines 14-15 creates a mock object of type com.adobe.cq.wcm.core.components.models.Image. Note that this is defined at the class level so that, as needed, @Test methods can alter its behavior as needed.
Line 11 creates a mock object of type ModelFactory. Note that this is a pure Mockito mock and has no methods implemented on it. Note that this is defined at the class level so that, as needed, @Test methods can alter its behavior as needed.
Lines 26-28 registers mock behavior for when getModelFromWrappedRequest(..) is called on the mock ModelFactory object. The result defined in thenReturn (..) is to return the mock Image object. Note that this behavior is only invoked when: the 1st parameter is equal to the ctx 's request object, the 2nd param is any Resource object, and the 3rd param must be the Core Components Image class. We accept any Resource because throughout our tests we will be setting the ctx.currentResource(...) to various mock resources defined in the BylineImplTest.json.
Lines 30-31 registers the mock ModelFactory object into the AemContext, with the highest service ranking. This is required since the ModelFactory used in the BylineImpl's init() is injected via the @OSGiService ModelFactory model field. In order for the AemContext to inject our mock object, which handles calls to getModelFromWrappedRequest(..), we must register it as the highest ranking Service of that type (ModelFactory).