2323import static org .hamcrest .Matchers .equalTo ;
2424import static org .hamcrest .Matchers .is ;
2525import static org .hamcrest .Matchers .nullValue ;
26- import static org .mockito .ArgumentMatchers .anyInt ;
2726import static org .mockito .BDDMockito .given ;
2827import static org .mockito .Mockito .mock ;
2928import static org .mockito .Mockito .withSettings ;
4039import org .mockito .quality .Strictness ;
4140import org .parosproxy .paros .extension .history .ExtensionHistory ;
4241import org .parosproxy .paros .model .HistoryReference ;
42+ import org .parosproxy .paros .model .Model ;
43+ import org .parosproxy .paros .model .Session ;
44+ import org .parosproxy .paros .model .SiteMap ;
45+ import org .parosproxy .paros .model .SiteNode ;
4346import org .zaproxy .addon .client .ExtensionClientIntegration ;
4447import org .zaproxy .zap .extension .alert .ExtensionAlert ;
4548import org .zaproxy .zap .testutils .TestUtils ;
@@ -66,16 +69,38 @@ void setup() {
6669 @ Test
6770 void shouldFindHistoryRef () throws Exception {
6871 // Given
69- given (extHistory .getLastHistoryId ()).willReturn (3 );
72+ Model model = mock ();
73+ given (extHistory .getModel ()).willReturn (model );
74+ Session session = mock ();
75+ given (model .getSession ()).willReturn (session );
76+ SiteMap siteTree = mock ();
77+ given (session .getSiteTree ()).willReturn (siteTree );
78+ SiteNode siteNode = mock ();
7079 String url = "http://example.com/" ;
71- HistoryReference href1 = mockHistoryReference (url );
72- HistoryReference href2Deleted = null ;
73- HistoryReference href3 = mockHistoryReference ("http://not.example.com/" );
74- given (extHistory .getHistoryReference (anyInt ())).willReturn (href3 , href2Deleted , href1 );
80+ given (siteTree .findNode (new URI (url , true ))).willReturn (siteNode );
81+ HistoryReference href = mockHistoryReference (url );
82+ given (siteNode .getHistoryReference ()).willReturn (href );
7583 // When
7684 HistoryReference foundHref = helper .findHistoryRef (url );
7785 // Then
78- assertThat (foundHref , is (equalTo (href1 )));
86+ assertThat (foundHref , is (equalTo (href )));
87+ }
88+
89+ @ Test
90+ void shouldNotFindHistoryRefIfNotPresent () throws Exception {
91+ // Given
92+ Model model = mock ();
93+ given (extHistory .getModel ()).willReturn (model );
94+ Session session = mock ();
95+ given (model .getSession ()).willReturn (session );
96+ SiteMap siteTree = mock ();
97+ given (session .getSiteTree ()).willReturn (siteTree );
98+ String url = "http://example.com/" ;
99+ given (siteTree .findNode (new URI (url , true ))).willReturn (null );
100+ // When
101+ HistoryReference foundHref = helper .findHistoryRef (url );
102+ // Then
103+ assertThat (foundHref , is (nullValue ()));
79104 }
80105
81106 private static HistoryReference mockHistoryReference (String url ) throws URIException {
0 commit comments