<commit_before>package com.skiwi.olog

import grails.test.mixin.Mock
import grails.test.mixin.TestFor
import spock.lang.Specification

/**
 * See the API for {@link grails.test.mixin.services.ServiceUnitTestMixin} for usage instructions
 */
@TestFor(ReportKeyService)
@Mock([SpyReport, CombatReport, RecycleReport, MissileReport, Player, PlayerAlias])
class ReportKeyServiceSpec extends Specification {
    Player player

    def setup() {
        def playerService = mockService(PlayerService)
        player = playerService.createPlayer(103168, "skiwi")
    }

    def cleanup() {
    }

    void "test add or get spy report"() {
        given: "a spy report key"
        def key = "sr-en-135-73536e717b84e3ebd7cc6c415a3b3675cc1af166"

        when: "add spy report"
        def spyReport = service.addOrGetSpyReport(player, key)

        then: "spy report should be added"
        spyReport
        spyReport.player == player
        spyReport.key == key
        SpyReport.findByKey(key) == spyReport

        when: "add spy report with same key again"
        def sameSpyReport = service.addOrGetSpyReport(player, key)

        then: "spy report should not be added"
        SpyReport.countByKey(key) == 1
    }

    void "test add or get combat report"() {
        given: "a combat report key"
        def key = "cr-en-135-3be2512d98e266343c100f71d6c14b7a68e639f4"

        when: "add combat report"
        def combatReport = service.addOrGetCombatReport(player, key)

        then: "combat report should be added"
        combatReport
        combatReport.player == player
        combatReport.key == key
        CombatReport.findByKey(key) == combatReport

        when: "add combat report with same key again"
        def sameCombatReport = service.addOrGetCombatReport(player, key)

        then: "combat report should not be added"
        CombatReport.countByKey(key) == 1
    }

    void "test add or get recycle report"() {
        given: "a recycle report key"
        def key = "rr-en-135-3105606a1fdb509f9f51459b5ddf0d36afc8a074"

        when: "add recycle report"
        def recycleReport = service.addOrGetRecycleReport(player, key)

        then: "recycle report should be added"
        recycleReport
        recycleReport.player == player
        recycleReport.key == key
        RecycleReport.findByKey(key) == recycleReport

        when: "add recycle report with same key again"
        def sameRecycleReport = service.addOrGetRecycleReport(player, key)

        then: "recycle report should not be added"
        RecycleReport.countByKey(key) == 1
    }

    void "test add or get missile report"() {
        given: "a missile report key"
        def key = "mr-en-135-b47906dc63fafa3c47185e09c23908945c802781"

        when: "add missile report"
        def missileReport = service.addOrGetMissileReport(player, key)

        then: "missile report should be added"
        missileReport
        missileReport.player == player
        missileReport.key == key
        MissileReport.findByKey(key) == missileReport

        when: "add missile report with same key again"
        def sameMissileReport = service.addOrGetMissileReport(player, key)

        then: "missile report should not be added"
        MissileReport.countByKey(key) == 1
    }

    void "test all types of reports with same key"() {
        given: "a key that is the same for every report"
        def key = "testkey"

        when: "reports are valid"
        def spyReport = service.addOrGetSpyReport(player, key)
        def combatReport = service.addOrGetCombatReport(player, key)
        def recycleReport = service.addOrGetRecycleReport(player, key)
        def missileReport = service.addOrGetMissileReport(player, key)

        then: "all reports should be saved"
        spyReport.save(flush: true)
        combatReport.save(flush: true)
        recycleReport.save(flush: true)
        missileReport.save()
    }
}<commit_msg>Improved unit tests in ReportKeyServiceSpec.<commit_after>package com.skiwi.olog

import grails.test.mixin.Mock
import grails.test.mixin.TestFor
import spock.lang.Specification

/**
 * See the API for {@link grails.test.mixin.services.ServiceUnitTestMixin} for usage instructions
 */
@TestFor(ReportKeyService)
@Mock([SpyReport, CombatReport, RecycleReport, MissileReport, Player, PlayerAlias])
class ReportKeyServiceSpec extends Specification {
    Player player

    def setup() {
        def playerService = mockService(PlayerService)
        player = playerService.createPlayer(103168, "skiwi")
    }

    def cleanup() {
    }

    void "test add or get spy report"() {
        given: "a spy report key"
        def key = "sr-en-135-73536e717b84e3ebd7cc6c415a3b3675cc1af166"

        when: "add spy report"
        def spyReport = service.addOrGetSpyReport(player, key)

        then: "spy report should be added"
        spyReport
        spyReport.player == player
        spyReport.key == key
        SpyReport.findByKey(key) == spyReport

        when: "add spy report with same key again"
        def sameSpyReport = service.addOrGetSpyReport(player, key)

        then: "spy report should not be added"
        SpyReport.countByKey(key) == 1
        spyReport == sameSpyReport
    }

    void "test add or get combat report"() {
        given: "a combat report key"
        def key = "cr-en-135-3be2512d98e266343c100f71d6c14b7a68e639f4"

        when: "add combat report"
        def combatReport = service.addOrGetCombatReport(player, key)

        then: "combat report should be added"
        combatReport
        combatReport.player == player
        combatReport.key == key
        CombatReport.findByKey(key) == combatReport

        when: "add combat report with same key again"
        def sameCombatReport = service.addOrGetCombatReport(player, key)

        then: "combat report should not be added"
        CombatReport.countByKey(key) == 1
        combatReport == sameCombatReport
    }

    void "test add or get recycle report"() {
        given: "a recycle report key"
        def key = "rr-en-135-3105606a1fdb509f9f51459b5ddf0d36afc8a074"

        when: "add recycle report"
        def recycleReport = service.addOrGetRecycleReport(player, key)

        then: "recycle report should be added"
        recycleReport
        recycleReport.player == player
        recycleReport.key == key
        RecycleReport.findByKey(key) == recycleReport

        when: "add recycle report with same key again"
        def sameRecycleReport = service.addOrGetRecycleReport(player, key)

        then: "recycle report should not be added"
        RecycleReport.countByKey(key) == 1
        recycleReport == sameRecycleReport
    }

    void "test add or get missile report"() {
        given: "a missile report key"
        def key = "mr-en-135-b47906dc63fafa3c47185e09c23908945c802781"

        when: "add missile report"
        def missileReport = service.addOrGetMissileReport(player, key)

        then: "missile report should be added"
        missileReport
        missileReport.player == player
        missileReport.key == key
        MissileReport.findByKey(key) == missileReport

        when: "add missile report with same key again"
        def sameMissileReport = service.addOrGetMissileReport(player, key)

        then: "missile report should not be added"
        MissileReport.countByKey(key) == 1
        missileReport == sameMissileReport
    }

    void "test all types of reports with same key"() {
        given: "a key that is the same for every report"
        def key = "testkey"

        when: "reports are valid"
        def spyReport = service.addOrGetSpyReport(player, key)
        def combatReport = service.addOrGetCombatReport(player, key)
        def recycleReport = service.addOrGetRecycleReport(player, key)
        def missileReport = service.addOrGetMissileReport(player, key)

        then: "all reports should be saved"
        spyReport.save(flush: true)
        combatReport.save(flush: true)
        recycleReport.save(flush: true)
        missileReport.save()
    }
}
{'fraction_non_alphanumeric': 0.08156424581005586, 'fraction_numerical': 0.03202979515828678, 'mean_word_length': 2.733086190917516, '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': '6886754', 'n_tokens_mistral': 2586, 'n_tokens_neox': 2393, 'n_words': 658}