<commit_before>package com.intellij.stats.completion

import com.intellij.testFramework.LightPlatformTestCase
import org.assertj.core.api.Assertions.assertThat
import org.mockito.Mockito.`when`
import org.mockito.Mockito.mock
import java.io.File

class TestFilePathProvider: UniqueFilesProvider("chunk", File("."))

class StatisticsSenderTest: LightPlatformTestCase() {
    lateinit var firstFile: File
    lateinit var secondFile: File
    
    lateinit var urlProvider: UrlProvider
    lateinit var requestService: RequestService
    lateinit var filePathProvider: FilePathProvider

    val test_url = "http://xxx.com" 

    override fun setUp() {
        super.setUp()
        
        firstFile = File("first_file")
        firstFile.createNewFile()
        firstFile.writeText("text")
        
        secondFile = File("second_file")
        secondFile.createNewFile()
        secondFile.writeText("text")
        
        urlProvider = mock(UrlProvider::class.java)
        requestService = mock(RequestService::class.java)
        filePathProvider = mock(FilePathProvider::class.java)
    }

    override fun tearDown() {
        try {
            firstFile.delete()
            secondFile.delete()
        }
        finally {
            super.tearDown()
        }
    }

    fun `test removed if every file send response was ok`() {
        `when`(filePathProvider.getDataFiles()).thenReturn(listOf(firstFile, secondFile))

        `when`(urlProvider.statsServerPostUrl).thenReturn(test_url)

        `when`(requestService.post(test_url, firstFile)).thenReturn(ResponseData(200))
        `when`(requestService.post(test_url, secondFile)).thenReturn(ResponseData(200))
        
        val sender = StatisticSender(requestService, filePathProvider)
        sender.sendStatsData("")
        
        assertThat(firstFile.exists()).isEqualTo(false)
        assertThat(secondFile.exists()).isEqualTo(false)
    }


    fun `test removed first if only first is sent`() {
        `when`(filePathProvider.getDataFiles()).thenReturn(listOf(firstFile, secondFile))

        `when`(urlProvider.statsServerPostUrl).thenReturn(test_url)

        `when`(requestService.post(test_url, firstFile)).thenReturn(ResponseData(200))
        `when`(requestService.post(test_url, secondFile)).thenReturn(ResponseData(404))

        val sender = StatisticSender(requestService, filePathProvider)
        sender.sendStatsData("")

        assertThat(firstFile.exists()).isEqualTo(false)
        assertThat(secondFile.exists()).isEqualTo(true)
    }

    fun `test none is removed if all send failed`() {
        `when`(filePathProvider.getDataFiles()).thenReturn(listOf(firstFile, secondFile))

        `when`(urlProvider.statsServerPostUrl).thenReturn(test_url)

        `when`(requestService.post(test_url, firstFile)).thenReturn(ResponseData(404))
        `when`(requestService.post(test_url, secondFile)).thenThrow(IllegalAccessError("Should not be invoked"))

        val sender = StatisticSender(requestService, filePathProvider)
        sender.sendStatsData("")

        assertThat(firstFile.exists()).isEqualTo(true)
        assertThat(secondFile.exists()).isEqualTo(true)
    }
    
}<commit_msg>Fixed one more failing test<commit_after>package com.intellij.stats.completion

import com.intellij.testFramework.LightPlatformTestCase
import org.assertj.core.api.Assertions.assertThat
import org.mockito.Mockito.`when`
import org.mockito.Mockito.mock
import java.io.File

class TestFilePathProvider: UniqueFilesProvider("chunk", File("."))

class StatisticsSenderTest: LightPlatformTestCase() {
    lateinit var firstFile: File
    lateinit var secondFile: File
    
    lateinit var urlProvider: UrlProvider
    lateinit var requestService: RequestService
    lateinit var filePathProvider: FilePathProvider

    val test_url = "http://xxx.com" 

    override fun setUp() {
        super.setUp()
        
        firstFile = File("first_file")
        firstFile.createNewFile()
        firstFile.writeText("text")
        
        secondFile = File("second_file")
        secondFile.createNewFile()
        secondFile.writeText("text")
        
        urlProvider = mock(UrlProvider::class.java)
        requestService = mock(RequestService::class.java)
        filePathProvider = mock(FilePathProvider::class.java)
    }

    override fun tearDown() {
        try {
            firstFile.delete()
            secondFile.delete()
        }
        finally {
            super.tearDown()
        }
    }

    fun `test removed if every file send response was ok`() {
        `when`(filePathProvider.getDataFiles()).thenReturn(listOf(firstFile, secondFile))

        `when`(urlProvider.statsServerPostUrl).thenReturn(test_url)

        `when`(requestService.post(test_url, firstFile)).thenReturn(ResponseData(200))
        `when`(requestService.post(test_url, secondFile)).thenReturn(ResponseData(200))
        
        val sender = StatisticSender(requestService, filePathProvider)
        sender.sendStatsData(test_url)
        
        assertThat(firstFile.exists()).isEqualTo(false)
        assertThat(secondFile.exists()).isEqualTo(false)
    }


    fun `test removed first if only first is sent`() {
        `when`(filePathProvider.getDataFiles()).thenReturn(listOf(firstFile, secondFile))

        `when`(urlProvider.statsServerPostUrl).thenReturn(test_url)

        `when`(requestService.post(test_url, firstFile)).thenReturn(ResponseData(200))
        `when`(requestService.post(test_url, secondFile)).thenReturn(ResponseData(404))

        val sender = StatisticSender(requestService, filePathProvider)
        sender.sendStatsData(test_url)

        assertThat(firstFile.exists()).isEqualTo(false)
        assertThat(secondFile.exists()).isEqualTo(true)
    }

    fun `test none is removed if all send failed`() {
        `when`(filePathProvider.getDataFiles()).thenReturn(listOf(firstFile, secondFile))

        `when`(urlProvider.statsServerPostUrl).thenReturn(test_url)

        `when`(requestService.post(test_url, firstFile)).thenReturn(ResponseData(404))
        `when`(requestService.post(test_url, secondFile)).thenThrow(IllegalAccessError("Should not be invoked"))

        val sender = StatisticSender(requestService, filePathProvider)
        sender.sendStatsData(test_url)

        assertThat(firstFile.exists()).isEqualTo(true)
        assertThat(secondFile.exists()).isEqualTo(true)
    }
    
}
{'fraction_non_alphanumeric': 0.1100717181166199, 'fraction_numerical': 0.004677268475210477, 'mean_word_length': 3.45176960444136, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7253275', 'n_tokens_mistral': 1816, 'n_tokens_neox': 1786, 'n_words': 286}