<commit_before>/**
 * Copyright (C) 2013 - present by OpenGamma Inc. and the OpenGamma group of companies
 *
 * Please see distribution for license.
 */
package com.opengamma.analytics.financial.legalentity;

import static com.opengamma.analytics.financial.legalentity.LegalEntityTest.CREDIT_RATINGS;
import static com.opengamma.analytics.financial.legalentity.LegalEntityTest.LEGAL_ENTITY;
import static com.opengamma.analytics.financial.legalentity.LegalEntityTest.LEGAL_ENTITY_RED_CODE;
import static com.opengamma.analytics.financial.legalentity.LegalEntityTest.RED_CODE;
import static com.opengamma.analytics.financial.legalentity.LegalEntityTest.REGION;
import static com.opengamma.analytics.financial.legalentity.LegalEntityTest.SECTOR;
import static com.opengamma.analytics.financial.legalentity.LegalEntityTest.SHORT_NAME;
import static com.opengamma.analytics.financial.legalentity.LegalEntityTest.TICKER;
import static org.testng.AssertJUnit.assertEquals;
import static org.testng.AssertJUnit.assertTrue;

import java.util.Collections;
import java.util.HashSet;
import java.util.Set;

import org.joda.beans.impl.flexi.FlexiBean;
import org.testng.annotations.Test;

import com.google.common.collect.Sets;
import com.opengamma.util.i18n.Country;
import com.opengamma.util.money.Currency;
import com.opengamma.util.test.TestGroup;
import com.opengamma.util.tuple.Pair;
import com.opengamma.util.tuple.Pairs;

/**
 * Tests for the classes that extract data from an {@link LegalEntity}.
 */
@Test(groups = TestGroup.UNIT)
public class LegalEntityFilterTest {

  /**
   * Tests failure for a credit rating-specific request when the credit rating is null
   */
  @Test(expectedExceptions = IllegalStateException.class)
  public void testNullCreditRatings() {
    final LegalEntityCreditRatings filter = new LegalEntityCreditRatings();
    filter.getFilteredData(new LegalEntity(null, SHORT_NAME, null, null, null));
  }

  /**
   * Tests failure for a request based on the ratings description where the description is null.
   */
  @Test(expectedExceptions = IllegalStateException.class)
  public void testRatingDescription() {
    final Set<CreditRating> creditRatings = new HashSet<>();
    creditRatings.add(CreditRating.of("A", "S&P", true));
    final LegalEntityCreditRatings filter = new LegalEntityCreditRatings();
    filter.setPerAgencyRatingDescriptions(Collections.singleton("S&P"));
    filter.getFilteredData(new LegalEntity(null, SHORT_NAME, creditRatings, null, null));
  }

  /**
   * Tests failure for an agency rating that is not present in the legal entity.
   */
  @Test(expectedExceptions = IllegalStateException.class)
  public void testUseUnavailableRating() {
    final Set<CreditRating> creditRatings = new HashSet<>();
    creditRatings.add(CreditRating.of("A", "S&P", true));
    creditRatings.add(CreditRating.of("A", "Moody's", true));
    final LegalEntityCreditRatings filter = new LegalEntityCreditRatings();
    filter.setPerAgencyRatings(Collections.singleton("Fitch"));
    filter.getFilteredData(new LegalEntity(null, SHORT_NAME, creditRatings, null, null));
  }

  /**
   * Tests failure for an agency rating description that is not present in the legal entity.
   */
  @Test(expectedExceptions = IllegalStateException.class)
  public void testUseUnavailableRatingDescription() {
    final Set<CreditRating> creditRatings = new HashSet<>();
    creditRatings.add(CreditRating.of("A", "S&P", "Prime", true));
    creditRatings.add(CreditRating.of("A", "Moody's", "Prime", true));
    final LegalEntityCreditRatings filter = new LegalEntityCreditRatings();
    filter.setPerAgencyRatingDescriptions(Collections.singleton("Fitch"));
    filter.getFilteredData(new LegalEntity(null, SHORT_NAME, creditRatings, null, null));
  }

  /**
   * Tests ratings requests.
   */
  @Test
  public void testCreditRatings() {
    LegalEntityCreditRatings filter = new LegalEntityCreditRatings();
    assertEquals(CREDIT_RATINGS, filter.getFilteredData(LEGAL_ENTITY));
    assertEquals(CREDIT_RATINGS, filter.getFilteredData(LEGAL_ENTITY_RED_CODE));
    final Set<CreditRating> creditRatings = new HashSet<>(CREDIT_RATINGS);
    creditRatings.add(CreditRating.of("C", "Poor", "Test", false));
    filter = new LegalEntityCreditRatings();
    filter.setUseRating(true);
    Set<Pair<String, String>> expected = new HashSet<>();
    expected.add(Pairs.of("Moody's", "B"));
    expected.add(Pairs.of("S&P", "A"));
    expected.add(Pairs.of("Test", "C"));
    assertEquals(expected, filter.getFilteredData(new LegalEntity(null, SHORT_NAME, creditRatings, null, null)));
    assertEquals(expected, filter.getFilteredData(new LegalEntityWithREDCode(null, SHORT_NAME, creditRatings, null, null, "")));
    expected = new HashSet<>();
    expected.add(Pairs.of("Moody's", "B"));
    expected.add(Pairs.of("S&P", "A"));
    assertEquals(expected, filter.getFilteredData(LEGAL_ENTITY));
    assertEquals(expected, filter.getFilteredData(LEGAL_ENTITY_RED_CODE));
    filter = new LegalEntityCreditRatings();
    filter.setPerAgencyRatings(Collections.singleton("Moody's"));
    //    System.out.println(JodaBeanSer.PRETTY.xmlWriter().write(filter));
    expected = new HashSet<>();
    expected.add(Pairs.of("Moody's", "B"));
    assertEquals(expected, filter.getFilteredData(LEGAL_ENTITY));
    assertEquals(expected, filter.getFilteredData(LEGAL_ENTITY_RED_CODE));
    filter = new LegalEntityCreditRatings();
    filter.setPerAgencyRatings(Collections.singleton("S&P"));
    expected = new HashSet<>();
    expected.add(Pairs.of("S&P", "A"));
    assertEquals(expected, filter.getFilteredData(LEGAL_ENTITY));
    assertEquals(expected, filter.getFilteredData(LEGAL_ENTITY_RED_CODE));
    filter = new LegalEntityCreditRatings();
    filter.setUseRatingDescription(true);
    expected = new HashSet<>();
    expected.add(Pairs.of("Moody's", "Investment Grade"));
    expected.add(Pairs.of("S&P", "Prime"));
    expected.add(Pairs.of("Test", "Poor"));
    assertEquals(expected, filter.getFilteredData(new LegalEntity(null, SHORT_NAME, creditRatings, null, null)));
    assertEquals(expected, filter.getFilteredData(new LegalEntityWithREDCode(null, SHORT_NAME, creditRatings, null, null, "")));<commit_msg>[PLAT-5488] Clean to comments on a test.<commit_after>/**
 * Copyright (C) 2013 - present by OpenGamma Inc. and the OpenGamma group of companies
 *
 * Please see distribution for license.
 */
package com.opengamma.analytics.financial.legalentity;

import static com.opengamma.analytics.financial.legalentity.LegalEntityTest.CREDIT_RATINGS;
import static com.opengamma.analytics.financial.legalentity.LegalEntityTest.LEGAL_ENTITY;
import static com.opengamma.analytics.financial.legalentity.LegalEntityTest.LEGAL_ENTITY_RED_CODE;
import static com.opengamma.analytics.financial.legalentity.LegalEntityTest.RED_CODE;
import static com.opengamma.analytics.financial.legalentity.LegalEntityTest.REGION;
import static com.opengamma.analytics.financial.legalentity.LegalEntityTest.SECTOR;
import static com.opengamma.analytics.financial.legalentity.LegalEntityTest.SHORT_NAME;
import static com.opengamma.analytics.financial.legalentity.LegalEntityTest.TICKER;
import static org.testng.AssertJUnit.assertEquals;
import static org.testng.AssertJUnit.assertTrue;

import java.util.Collections;
import java.util.HashSet;
import java.util.Set;

import org.joda.beans.impl.flexi.FlexiBean;
import org.testng.annotations.Test;

import com.google.common.collect.Sets;
import com.opengamma.util.i18n.Country;
import com.opengamma.util.money.Currency;
import com.opengamma.util.test.TestGroup;
import com.opengamma.util.tuple.Pair;
import com.opengamma.util.tuple.Pairs;

/**
 * Tests for the classes that extract data from an {@link LegalEntity}.
 */
@Test(groups = TestGroup.UNIT)
public class LegalEntityFilterTest {

  /**
   * Tests failure for a credit rating-specific request when the credit rating is null
   */
  @Test(expectedExceptions = IllegalStateException.class)
  public void testNullCreditRatings() {
    final LegalEntityCreditRatings filter = new LegalEntityCreditRatings();
    filter.getFilteredData(new LegalEntity(null, SHORT_NAME, null, null, null));
  }

  /**
   * Tests failure for a request based on the ratings description where the description is null.
   */
  @Test(expectedExceptions = IllegalStateException.class)
  public void testRatingDescription() {
    final Set<CreditRating> creditRatings = new HashSet<>();
    creditRatings.add(CreditRating.of("A", "S&P", true));
    final LegalEntityCreditRatings filter = new LegalEntityCreditRatings();
    filter.setPerAgencyRatingDescriptions(Collections.singleton("S&P"));
    filter.getFilteredData(new LegalEntity(null, SHORT_NAME, creditRatings, null, null));
  }

  /**
   * Tests failure for an agency rating that is not present in the legal entity.
   */
  @Test(expectedExceptions = IllegalStateException.class)
  public void testUseUnavailableRating() {
    final Set<CreditRating> creditRatings = new HashSet<>();
    creditRatings.add(CreditRating.of("A", "S&P", true));
    creditRatings.add(CreditRating.of("A", "Moody's", true));
    final LegalEntityCreditRatings filter = new LegalEntityCreditRatings();
    filter.setPerAgencyRatings(Collections.singleton("Fitch"));
    filter.getFilteredData(new LegalEntity(null, SHORT_NAME, creditRatings, null, null));
  }

  /**
   * Tests failure for an agency rating description that is not present in the legal entity.
   */
  @Test(expectedExceptions = IllegalStateException.class)
  public void testUseUnavailableRatingDescription() {
    final Set<CreditRating> creditRatings = new HashSet<>();
    creditRatings.add(CreditRating.of("A", "S&P", "Prime", true));
    creditRatings.add(CreditRating.of("A", "Moody's", "Prime", true));
    final LegalEntityCreditRatings filter = new LegalEntityCreditRatings();
    filter.setPerAgencyRatingDescriptions(Collections.singleton("Fitch"));
    filter.getFilteredData(new LegalEntity(null, SHORT_NAME, creditRatings, null, null));
  }

  /**
   * Tests ratings requests.
   */
  @Test
  public void testCreditRatings() {
    LegalEntityCreditRatings filter = new LegalEntityCreditRatings();
    assertEquals(CREDIT_RATINGS, filter.getFilteredData(LEGAL_ENTITY));
    assertEquals(CREDIT_RATINGS, filter.getFilteredData(LEGAL_ENTITY_RED_CODE));
    final Set<CreditRating> creditRatings = new HashSet<>(CREDIT_RATINGS);
    creditRatings.add(CreditRating.of("C", "Poor", "Test", false));
    filter = new LegalEntityCreditRatings();
    filter.setUseRating(true);
    Set<Pair<String, String>> expected = new HashSet<>();
    expected.add(Pairs.of("Moody's", "B"));
    expected.add(Pairs.of("S&P", "A"));
    expected.add(Pairs.of("Test", "C"));
    assertEquals(expected, filter.getFilteredData(new LegalEntity(null, SHORT_NAME, creditRatings, null, null)));
    assertEquals(expected, filter.getFilteredData(new LegalEntityWithREDCode(null, SHORT_NAME, creditRatings, null, null, "")));
    expected = new HashSet<>();
    expected.add(Pairs.of("Moody's", "B"));
    expected.add(Pairs.of("S&P", "A"));
    assertEquals(expected, filter.getFilteredData(LEGAL_ENTITY));
    assertEquals(expected, filter.getFilteredData(LEGAL_ENTITY_RED_CODE));
    filter = new LegalEntityCreditRatings();
    filter.setPerAgencyRatings(Collections.singleton("Moody's"));
    expected = new HashSet<>();
    expected.add(Pairs.of("Moody's", "B"));
    assertEquals(expected, filter.getFilteredData(LEGAL_ENTITY));
    assertEquals(expected, filter.getFilteredData(LEGAL_ENTITY_RED_CODE));
    filter = new LegalEntityCreditRatings();
    filter.setPerAgencyRatings(Collections.singleton("S&P"));
    expected = new HashSet<>();
    expected.add(Pairs.of("S&P", "A"));
    assertEquals(expected, filter.getFilteredData(LEGAL_ENTITY));
    assertEquals(expected, filter.getFilteredData(LEGAL_ENTITY_RED_CODE));
    filter = new LegalEntityCreditRatings();
    filter.setUseRatingDescription(true);
    expected = new HashSet<>();
    expected.add(Pairs.of("Moody's", "Investment Grade"));
    expected.add(Pairs.of("S&P", "Prime"));
    expected.add(Pairs.of("Test", "Poor"));
    assertEquals(expected, filter.getFilteredData(new LegalEntity(null, SHORT_NAME, creditRatings, null, null)));
    assertEquals(expected, filter.getFilteredData(new LegalEntityWithREDCode(null, SHORT_NAME, creditRatings, null, null, "")));
{'fraction_non_alphanumeric': 0.12375958047599839, 'fraction_numerical': 0.001290843081887858, 'mean_word_length': 5.675282714054927, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 1}, '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': '1379717', 'n_tokens_mistral': 3985, 'n_tokens_neox': 3735, 'n_words': 733}