Mark services as private readonly

Remove ununused instances of services
Stub services in tests instead of accessing private property directly

Change-Id: Idfdeb21769c1ee84b8f1469b9dd82d22f0e11d3c
diff --git a/polygerrit-ui/app/elements/change-list/gr-change-list/gr-change-list.ts b/polygerrit-ui/app/elements/change-list/gr-change-list/gr-change-list.ts
index 8c33f52..56d0105 100644
--- a/polygerrit-ui/app/elements/change-list/gr-change-list/gr-change-list.ts
+++ b/polygerrit-ui/app/elements/change-list/gr-change-list/gr-change-list.ts
@@ -138,7 +138,7 @@
   @property({type: Object})
   _config?: ServerInfo;
 
-  flagsService = appContext.flagsService;
+  private readonly flagsService = appContext.flagsService;
 
   private readonly restApiService = appContext.restApiService;
 
diff --git a/polygerrit-ui/app/elements/change/gr-change-actions/gr-change-actions.ts b/polygerrit-ui/app/elements/change/gr-change-actions/gr-change-actions.ts
index eb979a1..a0b1794 100644
--- a/polygerrit-ui/app/elements/change/gr-change-actions/gr-change-actions.ts
+++ b/polygerrit-ui/app/elements/change/gr-change-actions/gr-change-actions.ts
@@ -380,7 +380,7 @@
 
   RevisionActions = RevisionActions;
 
-  reporting = appContext.reportingService;
+  private readonly reporting = appContext.reportingService;
 
   private readonly jsAPI = appContext.jsApiService;
 
diff --git a/polygerrit-ui/app/elements/change/gr-change-actions/gr-change-actions_test.ts b/polygerrit-ui/app/elements/change/gr-change-actions/gr-change-actions_test.ts
index 02e4161..e13b8b9 100644
--- a/polygerrit-ui/app/elements/change/gr-change-actions/gr-change-actions_test.ts
+++ b/polygerrit-ui/app/elements/change/gr-change-actions/gr-change-actions_test.ts
@@ -34,6 +34,7 @@
   query,
   queryAll,
   queryAndAssert,
+  stubReporting,
   stubRestApi,
 } from '../../../test/test-utils';
 import {assertUIActionInfo, GrChangeActions} from './gr-change-actions';
@@ -2314,7 +2315,7 @@
       sinon.stub(element, '_fireAction');
       sinon.stub(element, '_handleChangeAction');
 
-      const reportStub = sinon.stub(element.reporting, 'reportInteraction');
+      const reportStub = stubReporting('reportInteraction');
       element._handleAction(ActionType.CHANGE, 'key');
       assert.isTrue(reportStub.called);
       assert.equal(reportStub.lastCall.args[0], 'change-key');
diff --git a/polygerrit-ui/app/elements/change/gr-reply-dialog/gr-reply-dialog.ts b/polygerrit-ui/app/elements/change/gr-reply-dialog/gr-reply-dialog.ts
index e8d11fe..b95f52e 100644
--- a/polygerrit-ui/app/elements/change/gr-reply-dialog/gr-reply-dialog.ts
+++ b/polygerrit-ui/app/elements/change/gr-reply-dialog/gr-reply-dialog.ts
@@ -213,11 +213,9 @@
 
   FocusTarget = FocusTarget;
 
-  reporting = appContext.reportingService;
+  private readonly reporting = appContext.reportingService;
 
-  flagsService = appContext.flagsService;
-
-  changeService = appContext.changeService;
+  private readonly changeService = appContext.changeService;
 
   @property({type: Object})
   change?: ChangeInfo;
diff --git a/polygerrit-ui/app/elements/diff/gr-diff-view/gr-diff-view.ts b/polygerrit-ui/app/elements/diff/gr-diff-view/gr-diff-view.ts
index 3e8414d..54985bb 100644
--- a/polygerrit-ui/app/elements/diff/gr-diff-view/gr-diff-view.ts
+++ b/polygerrit-ui/app/elements/diff/gr-diff-view/gr-diff-view.ts
@@ -328,9 +328,7 @@
     };
   }
 
-  reporting = appContext.reportingService;
-
-  flagsService = appContext.flagsService;
+  private readonly reporting = appContext.reportingService;
 
   private readonly restApiService = appContext.restApiService;
 
diff --git a/polygerrit-ui/app/elements/edit/gr-editor-view/gr-editor-view.ts b/polygerrit-ui/app/elements/edit/gr-editor-view/gr-editor-view.ts
index fb8c2e0..aeb6500 100644
--- a/polygerrit-ui/app/elements/edit/gr-editor-view/gr-editor-view.ts
+++ b/polygerrit-ui/app/elements/edit/gr-editor-view/gr-editor-view.ts
@@ -119,7 +119,7 @@
 
   private storeTask?: DelayedTask;
 
-  reporting = appContext.reportingService;
+  private readonly reporting = appContext.reportingService;
 
   get keyBindings() {
     return {
diff --git a/polygerrit-ui/app/elements/settings/gr-change-table-editor/gr-change-table-editor.ts b/polygerrit-ui/app/elements/settings/gr-change-table-editor/gr-change-table-editor.ts
index d13b2a9..8b8a923 100644
--- a/polygerrit-ui/app/elements/settings/gr-change-table-editor/gr-change-table-editor.ts
+++ b/polygerrit-ui/app/elements/settings/gr-change-table-editor/gr-change-table-editor.ts
@@ -44,7 +44,7 @@
   @property({type: Array})
   defaultColumns: string[] = [];
 
-  flagsService = appContext.flagsService;
+  private readonly flagsService = appContext.flagsService;
 
   @observe('serverConfig')
   _configChanged(config: ServerInfo) {
diff --git a/polygerrit-ui/app/elements/shared/gr-comment-thread/gr-comment-thread.ts b/polygerrit-ui/app/elements/shared/gr-comment-thread/gr-comment-thread.ts
index d6ad030..845849b 100644
--- a/polygerrit-ui/app/elements/shared/gr-comment-thread/gr-comment-thread.ts
+++ b/polygerrit-ui/app/elements/shared/gr-comment-thread/gr-comment-thread.ts
@@ -211,9 +211,9 @@
     };
   }
 
-  reporting = appContext.reportingService;
+  private readonly reporting = appContext.reportingService;
 
-  flagsService = appContext.flagsService;
+  private readonly flagsService = appContext.flagsService;
 
   readonly storage = appContext.storageService;
 
@@ -349,9 +349,7 @@
   _getLayers(diff?: DiffInfo) {
     if (!diff) return [];
     const layers = [];
-    if (
-      appContext.flagsService.isEnabled(KnownExperimentId.TOKEN_HIGHLIGHTING)
-    ) {
+    if (this.flagsService.isEnabled(KnownExperimentId.TOKEN_HIGHLIGHTING)) {
       layers.push(new TokenHighlightLayer());
     }
     layers.push(this.syntaxLayer);
diff --git a/polygerrit-ui/app/elements/shared/gr-comment-thread/gr-comment-thread_test.ts b/polygerrit-ui/app/elements/shared/gr-comment-thread/gr-comment-thread_test.ts
index d068cea..31908fd 100644
--- a/polygerrit-ui/app/elements/shared/gr-comment-thread/gr-comment-thread_test.ts
+++ b/polygerrit-ui/app/elements/shared/gr-comment-thread/gr-comment-thread_test.ts
@@ -45,7 +45,11 @@
   pressAndReleaseKeyOn,
 } from '@polymer/iron-test-helpers/mock-interactions';
 import {html} from '@polymer/polymer/lib/utils/html-tag';
-import {stubRestApi, stubStorage} from '../../../test/test-utils';
+import {
+  stubReporting,
+  stubRestApi,
+  stubStorage,
+} from '../../../test/test-utils';
 
 const basicFixture = fixtureFromElement('gr-comment-thread');
 
@@ -362,7 +366,7 @@
 
   test('reply', () => {
     const commentEl = element.shadowRoot?.querySelector('gr-comment');
-    const reportStub = sinon.stub(element.reporting, 'recordDraftInteraction');
+    const reportStub = stubReporting('recordDraftInteraction');
     assert.ok(commentEl);
 
     const replyBtn = element.$.replyBtn;
@@ -381,7 +385,7 @@
 
   test('quote reply', () => {
     const commentEl = element.shadowRoot?.querySelector('gr-comment');
-    const reportStub = sinon.stub(element.reporting, 'recordDraftInteraction');
+    const reportStub = stubReporting('recordDraftInteraction');
     assert.ok(commentEl);
 
     const quoteBtn = element.$.quoteBtn;
@@ -399,7 +403,7 @@
   });
 
   test('quote reply multiline', () => {
-    const reportStub = sinon.stub(element.reporting, 'recordDraftInteraction');
+    const reportStub = stubReporting('recordDraftInteraction');
     element.comments = [
       {
         author: {
@@ -436,7 +440,7 @@
   });
 
   test('ack', done => {
-    const reportStub = sinon.stub(element.reporting, 'recordDraftInteraction');
+    const reportStub = stubReporting('recordDraftInteraction');
     element.changeNum = 42 as NumericChangeId;
     element.patchNum = 1 as PatchSetNum;
 
@@ -461,7 +465,7 @@
   });
 
   test('done', done => {
-    const reportStub = sinon.stub(element.reporting, 'recordDraftInteraction');
+    const reportStub = stubReporting('recordDraftInteraction');
     element.changeNum = 42 as NumericChangeId;
     element.patchNum = 1 as PatchSetNum;
     const commentEl = element.shadowRoot?.querySelector('gr-comment');
diff --git a/polygerrit-ui/app/elements/shared/gr-comment/gr-comment.ts b/polygerrit-ui/app/elements/shared/gr-comment/gr-comment.ts
index 124d71e..3f003bb 100644
--- a/polygerrit-ui/app/elements/shared/gr-comment/gr-comment.ts
+++ b/polygerrit-ui/app/elements/shared/gr-comment/gr-comment.ts
@@ -271,7 +271,7 @@
 
   private readonly storage = appContext.storageService;
 
-  reporting = appContext.reportingService;
+  private readonly reporting = appContext.reportingService;
 
   private fireUpdateTask?: DelayedTask;
 
diff --git a/polygerrit-ui/app/elements/shared/gr-comment/gr-comment_test.ts b/polygerrit-ui/app/elements/shared/gr-comment/gr-comment_test.ts
index 6d5cec7..bbf3442 100644
--- a/polygerrit-ui/app/elements/shared/gr-comment/gr-comment_test.ts
+++ b/polygerrit-ui/app/elements/shared/gr-comment/gr-comment_test.ts
@@ -27,6 +27,7 @@
   spyStorage,
   query,
   isVisible,
+  stubReporting,
 } from '../../../test/test-utils';
 import {
   AccountId,
@@ -363,9 +364,7 @@
         endStub = sinon.stub();
         const mockTimer = new MockTimer();
         mockTimer.end = endStub;
-        getTimerStub = sinon
-          .stub(element.reporting, 'getTimer')
-          .returns(mockTimer);
+        getTimerStub = stubReporting('getTimer').returns(mockTimer);
       });
 
       test('create', () => {
@@ -414,10 +413,7 @@
     });
 
     test('edit reports interaction', () => {
-      const reportStub = sinon.stub(
-        element.reporting,
-        'recordDraftInteraction'
-      );
+      const reportStub = stubReporting('recordDraftInteraction');
       element.draft = true;
       flush();
       tap(queryAndAssert(element, '.edit'));
@@ -425,10 +421,7 @@
     });
 
     test('discard reports interaction', () => {
-      const reportStub = sinon.stub(
-        element.reporting,
-        'recordDraftInteraction'
-      );
+      const reportStub = stubReporting('recordDraftInteraction');
       element.draft = true;
       flush();
       tap(queryAndAssert(element, '.discard'));