2 * Copyright 2000-2017 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package com.intellij.stats.completion
18 import com.intellij.codeInsight.lookup.impl.LookupImpl
19 import com.intellij.openapi.editor.Editor
20 import com.intellij.stats.storage.FilePathProvider
21 import com.intellij.testFramework.PlatformTestCase
22 import org.assertj.core.api.Assertions.assertThat
24 import org.mockito.Matchers
25 import org.mockito.Mockito.`when`
26 import org.mockito.Mockito.mock
31 class FileLoggerTest : PlatformTestCase() {
32 private lateinit var dir: File
33 private lateinit var logFile: File
35 private lateinit var pathProvider: FilePathProvider
37 override fun setUp() {
39 dir = createTempDirectory()
40 logFile = File(dir, "unique_1")
42 pathProvider = mock(FilePathProvider::class.java).apply {
43 `when`(getStatsDataDirectory()).thenReturn(dir)
44 `when`(getUniqueFile()).thenReturn(logFile)
47 CompletionTrackerInitializer.isEnabledInTests = true
50 override fun tearDown() {
51 CompletionTrackerInitializer.isEnabledInTests = false
53 dir.deleteRecursively()
62 val fileLengthBefore = logFile.length()
63 val uidProvider = mock(InstallationIdProvider::class.java).apply {
64 `when`(installationId()).thenReturn(UUID.randomUUID().toString())
67 val loggerProvider = CompletionFileLoggerProvider(pathProvider, uidProvider)
68 loggerProvider.initComponent()
70 val logger = loggerProvider.newCompletionLogger()
72 val lookup = mock(LookupImpl::class.java).apply {
73 `when`(getRelevanceObjects(Matchers.any(), Matchers.anyBoolean())).thenReturn(emptyMap())
74 `when`(items).thenReturn(emptyList())
75 `when`(psiFile).thenReturn(null)
76 `when`(editor).thenReturn(mock(Editor::class.java))
79 logger.completionStarted(lookup, true, 2)
81 logger.completionCancelled()
82 loggerProvider.disposeComponent()
84 assertThat(logFile.length()).isGreaterThan(fileLengthBefore)