<commit_before>package de.tu_berlin.formic.client

import akka.actor.Actor
import de.tu_berlin.formic.client.WebSocketFactorySpec._
import org.scalatest.{FlatSpec, Matchers}

import scala.scalajs.js.timers._

/**
  * @author <NAME>
  */
class WebSocketFactorySpec extends FlatSpec with Matchers {

  "WebSocketFactoryJS" should "open a WebSocket connection" in {
    val connection = WebSocketFactoryJS.createConnection("ws://echo.websocket.org", Actor.noSender)
    
    setTimeout(500) {
      getConnectionObject(connection.asInstanceOf[WrappedJSWebSocket].webSocket.readyState) should equal(WebSocketFactorySpec.WebSocketOpenState)
    }
    setTimeout(2000) {
      connection.asInstanceOf[WrappedJSWebSocket].webSocket.close()
    }
  }

  it should "register for onopen events" in {
    val connection = WebSocketFactoryJS.createConnection("ws://echo.websocket.org", Actor.noSender)
    connection.asInstanceOf[WrappedJSWebSocket].webSocket.onopen should not be null
  }

  it should "register for onerror events" in {
    val connection = WebSocketFactoryJS.createConnection("ws://echo.websocket.org", Actor.noSender)
    connection.asInstanceOf[WrappedJSWebSocket].webSocket.onerror should not be null
  }

  it should "register for onmessage events" in {
    val connection = WebSocketFactoryJS.createConnection("ws://echo.websocket.org", Actor.noSender)
    connection.asInstanceOf[WrappedJSWebSocket].webSocket.onmessage should not be null
  }

  it should "register for onclose events" in {
    val connection = WebSocketFactoryJS.createConnection("ws://echo.websocket.org", Actor.noSender)
    connection.asInstanceOf[WrappedJSWebSocket].webSocket.onclose should not be null
  }

  /**
    * This method and the states only serve the readability of the TestFailedException
    */
  def getConnectionObject(readyState: Int) = {
    readyState match {
      case 0 => WebSocketConnectingState
      case 1 => WebSocketOpenState
      case 2 => WebSocketClosingState
      case 3 => WebSocketClosedState
    }
  }
}

object WebSocketFactorySpec {<commit_msg>Actor.noSender was just null, replaced with StandardOutLogger<commit_after>package de.tu_berlin.formic.client

import akka.actor.{Actor, ActorRef}
import akka.event.Logging.StandardOutLogger
import de.tu_berlin.formic.client.WebSocketFactorySpec._
import org.scalatest.{FlatSpec, Matchers}

import scala.scalajs.js.timers._

/**
  * @author <NAME>
  */
class WebSocketFactorySpec extends FlatSpec with Matchers {

  "WebSocketFactoryJS" should "open a WebSocket connection" in {

    val connection = WebSocketFactoryJS.createConnection("ws://echo.websocket.org", new StandardOutLogger)
    
    setTimeout(500) {
      getConnectionObject(connection.asInstanceOf[WrappedJSWebSocket].webSocket.readyState) should equal(WebSocketFactorySpec.WebSocketOpenState)
    }
    setTimeout(2000) {
      connection.asInstanceOf[WrappedJSWebSocket].webSocket.close()
    }
  }

  it should "register for onopen events" in {
    val connection = WebSocketFactoryJS.createConnection("ws://echo.websocket.org", new StandardOutLogger)
    connection.asInstanceOf[WrappedJSWebSocket].webSocket.onopen should not be null
  }

  it should "register for onerror events" in {
    val connection = WebSocketFactoryJS.createConnection("ws://echo.websocket.org", new StandardOutLogger)
    connection.asInstanceOf[WrappedJSWebSocket].webSocket.onerror should not be null
  }

  it should "register for onmessage events" in {
    val connection = WebSocketFactoryJS.createConnection("ws://echo.websocket.org", new StandardOutLogger)
    connection.asInstanceOf[WrappedJSWebSocket].webSocket.onmessage should not be null
  }

  it should "register for onclose events" in {
    val connection = WebSocketFactoryJS.createConnection("ws://echo.websocket.org", new StandardOutLogger)
    connection.asInstanceOf[WrappedJSWebSocket].webSocket.onclose should not be null
  }

  /**
    * This method and the states only serve the readability of the TestFailedException
    */
  def getConnectionObject(readyState: Int) = {
    readyState match {
      case 0 => WebSocketConnectingState
      case 1 => WebSocketOpenState
      case 2 => WebSocketClosingState
      case 3 => WebSocketClosedState
    }
  }
}

object WebSocketFactorySpec {
{'fraction_non_alphanumeric': 0.08859280037400655, 'fraction_numerical': 0.005142589995324918, 'mean_word_length': 4.450955414012739, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, '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': '423492', 'n_tokens_mistral': 1270, 'n_tokens_neox': 1222, 'n_words': 276}