<commit_before>
/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.apache.iota.fey

import java.io.File

import akka.actor.{ActorRef, PoisonPill, Props}
import akka.testkit.{EventFilter, TestActorRef, TestProbe}
import ch.qos.logback.classic.Level
import play.api.libs.json._
import java.nio.file.{Files, Paths}

import scala.io.Source
import scala.concurrent.duration._

class UtilsSpec extends BaseAkkaSpec{

  "Global variable loadedJars" should{
    "be empty when starting" in {
      Utils.loadedJars shouldBe empty
    }
  }

  "Executing getFilesInDirectory" should {
    "return a list of all Files in the directory" in {
      val files = Utils.getFilesInDirectory(CONFIG.JAR_REPOSITORY)
      files should not be empty
      files should have size(2)
      val filepath = files.map(_.getAbsolutePath)
      filepath should contain(s"${CONFIG.JAR_REPOSITORY}/fey-test-actor.jar")
      filepath should contain(s"${CONFIG.JAR_REPOSITORY}/dynamic")
    }
  }

  "Executing loadActorClassFromJar with not yet loaded jar" should {
    "result in new entry to global variable loadedJars" in {
      Utils.loadActorClassFromJar(s"${CONFIG.JAR_REPOSITORY}/fey-test-actor.jar", "org.apache.iota.fey.TestActor","fey-test-actor.jar")
      Utils.loadedJars should have size(1)
      Utils.loadedJars should contain key("fey-test-actor.jar")
      Utils.loadedJars.get("fey-test-actor.jar").get._2 should have size(1)
      Utils.loadedJars.get("fey-test-actor.jar").get._2 should contain key("org.apache.iota.fey.TestActor")
    }
  }

<commit_msg>[IOTA-36] Unit test - forcing clean up of loaded jars before get into Utils<commit_after>
/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.apache.iota.fey

import java.io.File

import akka.actor.{ActorRef, PoisonPill, Props}
import akka.testkit.{EventFilter, TestActorRef, TestProbe}
import ch.qos.logback.classic.Level
import play.api.libs.json._
import java.nio.file.{Files, Paths}

import scala.collection.mutable
import scala.io.Source
import scala.concurrent.duration._

class UtilsSpec extends BaseAkkaSpec{

  "Global variable loadedJars" should{
    "be empty when starting" in {
      Utils.loadedJars.remove("fey-test-actor.jar")
      Utils.loadedJars shouldBe empty
    }
  }

  "Executing getFilesInDirectory" should {
    "return a list of all Files in the directory" in {
      val files = Utils.getFilesInDirectory(CONFIG.JAR_REPOSITORY)
      files should not be empty
      files should have size(2)
      val filepath = files.map(_.getAbsolutePath)
      filepath should contain(s"${CONFIG.JAR_REPOSITORY}/fey-test-actor.jar")
      filepath should contain(s"${CONFIG.JAR_REPOSITORY}/dynamic")
    }
  }

  "Executing loadActorClassFromJar with not yet loaded jar" should {
    "result in new entry to global variable loadedJars" in {
      Utils.loadActorClassFromJar(s"${CONFIG.JAR_REPOSITORY}/fey-test-actor.jar", "org.apache.iota.fey.TestActor","fey-test-actor.jar")
      Utils.loadedJars should have size(1)
      Utils.loadedJars should contain key("fey-test-actor.jar")
      Utils.loadedJars.get("fey-test-actor.jar").get._2 should have size(1)
      Utils.loadedJars.get("fey-test-actor.jar").get._2 should contain key("org.apache.iota.fey.TestActor")
    }
  }


{'fraction_non_alphanumeric': 0.09249161073825503, 'fraction_numerical': 0.0041946308724832215, 'mean_word_length': 3.8465447154471546, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '934838', 'n_tokens_mistral': 1457, 'n_tokens_neox': 1421, 'n_words': 457}