tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

ProjectLicenseRuleTest.kt (1856B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 package mozilla.components.tooling.detekt
      6 
      7 import io.gitlab.arturbosch.detekt.test.lint
      8 import org.junit.Assert.assertEquals
      9 import org.junit.Test
     10 
     11 class ProjectLicenseRuleTest {
     12 
     13    @Test
     14    fun testAbsentLicense() {
     15        val findings = ProjectLicenseRule().lint(fileContent)
     16 
     17        assertEquals(1, findings.size)
     18        assertEquals(
     19            "Expected license not found or incorrect in the file: Test.kt.",
     20            findings.first().message,
     21        )
     22    }
     23 
     24    @Test
     25    fun testInvalidLicense() {
     26        val file = """
     27            |/* This Source Code Form is subject to the terms of the Mozilla Public License.
     28            | * You can obtain one at http://mozilla.org/MPL/2.0/. */
     29            |
     30            $fileContent
     31        """.trimMargin()
     32        val findings = ProjectLicenseRule().lint(file)
     33 
     34        assertEquals(1, findings.size)
     35        assertEquals(
     36            "Expected license not found or incorrect in the file: Test.kt.",
     37            findings.first().message,
     38        )
     39    }
     40 
     41    @Test
     42    fun testValidLicense() {
     43        val file = """
     44            |/* This Source Code Form is subject to the terms of the Mozilla Public
     45            | * License, v. 2.0. If a copy of the MPL was not distributed with this
     46            | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     47            |
     48            $fileContent
     49        """.trimMargin()
     50        val findings = ProjectLicenseRule().lint(file)
     51 
     52        assertEquals(0, findings.size)
     53    }
     54 }
     55 
     56 private val fileContent = """
     57    |package my.package
     58    |
     59    |/** My awesome class */
     60    |class MyClass () {
     61    |    fun foo () {}
     62    |}
     63 """.trimMargin()