<commit_before>package com.gilesc
package mynab

import java.time.LocalDate

import com.gilesc.mynab.account._
import com.gilesc.mynab.category._
import com.gilesc.mynab.transaction._

import com.gilesc.mynab.persistence.account._
import AccountGroupService.FindByName

import java.time.ZonedDateTime

class PersistingAccountGroupSpec extends TestCase
  with MockAccountCreation {

  val id = 1L
  val validName = "newaccountgroup"
  val invalidName = "r"
  val time = ZonedDateTime.now()

  "Giving the service an AccountName" should "persist the account group" in {
    val expected = AccountGroup.create(id, validName)
    def mockSave(name: AccountName) = Right(AccountGroupId(id))

    AccountGroupService.create(mockSave)(validName) should be(Right(expected))
  }

  it should "find an account group given a proper account name" in {
    def mockFind(an: AccountName): Either[AccountGroupPersistenceError, AccountGroupRow] =
      Right(AccountGroupRow(id, an, time, time, None))

    AccountGroupService.find(mockFind)(FindByName(validName)) should be(
      Right(AccountGroup.create(1L, validName)))
  }

  it should "give you sensible error messages" in {
    val expected = s"$invalidName is not a valid account name"
    def mockFind(an: AccountName): Either[AccountGroupPersistenceError, AccountGroupRow] = ???

    AccountGroupService.find(mockFind)(FindByName(invalidName)) should be(Left(expected))
  }

  it should "fail gracefully if the database contains an invalid name" in {
    val expected = s"n is not a valid account name"

    def mockFind(an: AccountName): Either[AccountGroupPersistenceError, AccountGroupRow] =
      Left(InvalidAccountNameLength("n"))

    AccountGroupService.find(mockFind)(FindByName(validName)) should be(Left(expected))

  }
}<commit_msg>Updated ??? to sys.error<commit_after>package com.gilesc
package mynab

import java.time.LocalDate

import com.gilesc.mynab.account._
import com.gilesc.mynab.category._
import com.gilesc.mynab.transaction._

import com.gilesc.mynab.persistence.account._
import AccountGroupService.FindByName

import java.time.ZonedDateTime

class PersistingAccountGroupSpec extends TestCase
  with MockAccountCreation {

  val id = 1L
  val validName = "newaccountgroup"
  val invalidName = "r"
  val time = ZonedDateTime.now()

  "Giving the service an AccountName" should "persist the account group" in {
    val expected = AccountGroup.create(id, validName)
    def mockSave(name: AccountName) = Right(AccountGroupId(id))

    AccountGroupService.create(mockSave)(validName) should be(Right(expected))
  }

  it should "find an account group given a proper account name" in {
    def mockFind(an: AccountName): Either[AccountGroupPersistenceError, AccountGroupRow] =
      Right(AccountGroupRow(id, an, time, time, None))

    AccountGroupService.find(mockFind)(FindByName(validName)) should be(
      Right(AccountGroup.create(1L, validName)))
  }

  it should "never call the mock function if an invalid account name is provided" in {
    val expected = s"$invalidName is not a valid account name"
    def mockFind(an: AccountName): Either[AccountGroupPersistenceError, AccountGroupRow] =
      sys.error("Somehow passed the AccountName restriction")

    AccountGroupService.find(mockFind)(FindByName(invalidName)) should be(Left(expected))
  }

  it should "fail gracefully if the database contains an invalid name" in {
    val expected = s"n is not a valid account name"

    def mockFind(an: AccountName): Either[AccountGroupPersistenceError, AccountGroupRow] =
      Left(InvalidAccountNameLength("n"))

    AccountGroupService.find(mockFind)(FindByName(validName)) should be(Left(expected))

  }
}
{'fraction_non_alphanumeric': 0.09071156979902227, 'fraction_numerical': 0.0010863661053775121, 'mean_word_length': 5.00815660685155, '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': '5397627', 'n_tokens_mistral': 1087, 'n_tokens_neox': 1072, 'n_words': 294}