<commit_before>package models

import org.scalatest._
import org.scalatest.mock.MockitoSugar
import org.scalatestplus.play._
import org.mockito.Mockito._
import java.util.Vector
import actors.PLMActor
import spies.ExecutionSpy
import plm.core.model.lesson.Exercise
import plm.universe.World
import plm.core.model.lesson.Exercise.WorldKind
import log.PLMLogger
import java.util.Locale
import java.util.UUID
import java.util.Properties

class PLMSpec extends PlaySpec with MockitoSugar {
  var userUUID: String = UUID.randomUUID.toString
  var plm = new PLM(new Properties, userUUID, mock[PLMLogger], new Locale("en"), None, false)
  
  "PLM#switchLesson" should {
    "set the selected lesson as the current one" in {
      val mockSpy = mock[ExecutionSpy]
      when(mockSpy.clone) thenReturn mock[ExecutionSpy]
      
      val expectedLessonID = "welcome"
      plm.switchLesson(expectedLessonID, mockSpy, mockSpy)
      val actualLectID = plm.game.getCurrentLesson.getId
      actualLectID mustBe expectedLessonID
    }
    
    "set the first exercise as the current one" in {
      val mockSpy = mock[ExecutionSpy]
      when(mockSpy.clone) thenReturn mock[ExecutionSpy]
      
      val lessonID = "welcome"
      val expectedExerciseID = "welcome.lessons.welcome.environment.Environment"
      plm.switchLesson(lessonID, mockSpy, mockSpy)
      val actualExerciseID = plm.game.getCurrentLesson.getCurrentExercise.getId
      actualExerciseID mustBe expectedExerciseID
    }
    
    "return the current exercise" in {
      val mockSpy = mock[ExecutionSpy]
      when(mockSpy.clone) thenReturn mock[ExecutionSpy]
      
      val actualLecture = plm.switchLesson("welcome", mockSpy, mockSpy)
      val expectedLecture = plm.game.getCurrentLesson.getCurrentExercise
      actualLecture mustBe expectedLecture
    }
  }
  
  "PLM#addExecutionSpy" should {
    "add a spy's clone to each world" in {
      val mockPLMActor = mock[PLMActor]
      val executionSpy = new ExecutionSpy(mockPLMActor, "testOperation")
      
      val worlds = new Vector[World]()   
      var mockFirstWorld = mock[World]
      var mockSecondWorld = mock[World]
      var mockThirdWorld = mock[World]
      
      worlds.add(mockFirstWorld)
      worlds.add(mockSecondWorld)
      worlds.add(mockThirdWorld)
      
      val exo = mock[Exercise]
      when(exo.getWorlds(WorldKind.CURRENT)) thenReturn worlds
      plm.addExecutionSpy(exo, executionSpy, WorldKind.CURRENT)
      verify(mockFirstWorld, times(1)).addWorldUpdatesListener(executionSpy)
      verify(mockSecondWorld, times(1)).addWorldUpdatesListener(executionSpy)
      verify(mockThirdWorld, times(1)).addWorldUpdatesListener(executionSpy)
    }
    
    "register each clone in PLMActor" in {
      val mockPLMActor = mock[PLMActor]
      val executionSpy = new ExecutionSpy(mockPLMActor, "testOperation")
      
      val worlds = new Vector[World]()   
      var mockFirstWorld = mock[World]
      var mockSecondWorld = mock[World]
      var mockThirdWorld = mock[World]
      
      worlds.add(mockFirstWorld)
      worlds.add(mockSecondWorld)
      worlds.add(mockThirdWorld)
      
      val exo = mock[Exercise]
      when(exo.getWorlds(WorldKind.CURRENT)) thenReturn worlds
      plm.addExecutionSpy(exo, executionSpy, WorldKind.CURRENT)
      verify(mockPLMActor, times(3)).registerSpy(executionSpy)
    }
    
    
  }
  
}<commit_msg>Fix PLMSpec's tests<commit_after>package models

import org.scalatest._
import org.scalatest.mock.MockitoSugar
import org.scalatestplus.play._
import org.mockito.Mockito._
import java.util.Vector
import actors.PLMActor
import plm.core.model.lesson.Exercise
import plm.universe.World
import plm.core.model.lesson.Exercise.WorldKind
import log.PLMLogger
import java.util.Locale
import java.util.UUID
import java.util.Properties
import play.api.test.WithApplication

class PLMSpec extends PlaySpec with MockitoSugar {
  var userUUID: String = UUID.randomUUID.toString
  
  "PLM#switchLesson" should  {
    "set the selected lesson as the current one" in new WithApplication {
      
      var plm = new PLM(mock[Tribunal], new Properties, userUUID, mock[PLMLogger], new Locale("en"), None, false)
      
      val expectedLessonID = "welcome"
      plm.switchLesson(expectedLessonID)
      val actualLectID = plm.game.getCurrentLesson.getId
      actualLectID mustBe expectedLessonID
    }
    
    "set the first exercise as the current one" in new WithApplication {
      
      var plm = new PLM(mock[Tribunal], new Properties, userUUID, mock[PLMLogger], new Locale("en"), None, false)
      
      val lessonID = "welcome"
      val expectedExerciseID = "welcome.lessons.welcome.environment.Environment"
      plm.switchLesson(lessonID)
      val actualExerciseID = plm.game.getCurrentLesson.getCurrentExercise.getId
      actualExerciseID mustBe expectedExerciseID
    }
    
    "return the current exercise" in new WithApplication {
      
      var plm = new PLM(mock[Tribunal], new Properties, userUUID, mock[PLMLogger], new Locale("en"), None, false)

      val actualLecture = plm.switchLesson("welcome")
      val expectedLecture = plm.game.getCurrentLesson.getCurrentExercise
      actualLecture mustBe expectedLecture
    }
  }
}
{'fraction_non_alphanumeric': 0.0825530288553411, 'fraction_numerical': 0.0007643798968087139, 'mean_word_length': 3.5237683664649957, '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': '1043576', 'n_tokens_mistral': 1651, 'n_tokens_neox': 1672, 'n_words': 363}