<commit_before>package org.json.junit;

import java.util.*;

import static org.junit.Assert.*;

import org.json.*;
import org.junit.Test;


/**
 * Tests for JSON-Java CookieList.java
 * The main differences between Cookie and CookieList appears to be that 
 * CookieList does not treat the initial name/value pair different than
 * the other segments, and does not handle "secure".
 * Therefore the tests will be similar, but not identical.
 */
public class CookieListTest {
    @Test(expected=NullPointerException.class)
    public void nullCookieListException() {
        String cookieStr = null;
        CookieList.toJSONObject(cookieStr);
    }

    @Test(expected=JSONException.class)
    public void malFormedCookieListException() {
        String cookieStr = "thisCookieHasNoEqualsChar";
        CookieList.toJSONObject(cookieStr);
    }

    @Test(expected=JSONException.class)
    public void emptyStringCookieList() {
        /**
         * Cookie throws an exception, but CookieList does not
         */
        String cookieStr = "";
        String expectedCookieStr = "";
        JSONObject jsonObject = CookieList.toJSONObject(cookieStr);
        JSONObject expectedJsonObject = new JSONObject(expectedCookieStr);
        Util.compareActualVsExpectedJsonObjects(jsonObject,expectedJsonObject);
    }

    @Test
    public void simpleCookieList() {
        String cookieStr = "SID=31d4d96e407aad42";
        String expectedCookieStr = "{\"SID\":\"31d4d96e407aad42\"}";
        JSONObject jsonObject = CookieList.toJSONObject(cookieStr);
        JSONObject expectedJsonObject = new JSONObject(expectedCookieStr);
        Util.compareActualVsExpectedJsonObjects(jsonObject,expectedJsonObject);
    }

    @Test
    public void multiPartCookieList() {
        String cookieStr = 
            "PH=deleted;  "+
            " expires=Wed, 19-Mar-2014 17:53:53 GMT;"+
            "path=/;   "+
            "    domain=.yahoo.com;";
        String expectedCookieStr = 
            "{\"path\":\"/\","+
            "\"expires\":\"Wed, 19-Mar-2014 17:53:53 GMT\","+
            "\"domain\":\".yahoo.com\","+
            "\"PH\":\"deleted\"}";
        JSONObject jsonObject = CookieList.toJSONObject(cookieStr);
        JSONObject expectedJsonObject = new JSONObject(expectedCookieStr);<commit_msg>Improving test case quality<commit_after>package org.json.junit;

import java.util.*;

import static org.junit.Assert.*;

import org.json.*;
import org.junit.Test;

/**
 * HTTP cookie specification: RFC6265
 * 
 * A cookie list is a JSONObject whose members are cookie name/value pairs.
 * Entries are unescaped while being added, and escaped in the toString()
 * method. Unescaping means to convert %hh hex strings to the ascii equivalent
 * and converting '+' to ' '. Escaping converts '+', '%', '=', ';',
 * and ascii control chars to %hh hex strings.
 *
 * CookieList should not be considered as just a list of Cookie objects:
 * - CookieList stores a cookie name/value pair as a single entry; Cookie stores 
 *      it as 2 entries.
 * - CookieList expects multiple name/value pairs as input; Cookie allows the
 *      'secure' name with no associated value
 */
public class CookieListTest {

    @Test(expected=NullPointerException.class)
    public void nullCookieListException() {
        /**
         * Attempts to create a CookieList from a null string
         */
        String cookieStr = null;
        CookieList.toJSONObject(cookieStr);
    }

    @Test(expected=JSONException.class)
    public void malFormedCookieListException() {
        /**
         * Attempts to create a CookieList from a malformed string
         */
        String cookieStr = "thisCookieHasNoEqualsChar";
        CookieList.toJSONObject(cookieStr);
    }

    @Test(expected=JSONException.class)
    public void emptyStringCookieList() {
        /**
         * Creates a CookieList from an empty string.
         * Cookie throws an exception, but CookieList does not
         */
        String cookieStr = "";
        String expectedCookieStr = "";
        JSONObject jsonObject = CookieList.toJSONObject(cookieStr);
        JSONObject expectedJsonObject = new JSONObject(expectedCookieStr);
        Util.compareActualVsExpectedJsonObjects(jsonObject,expectedJsonObject);
    }

    @Test
    public void simpleCookieList() {
        /**
         * The simplest cookie is a name/value pair with no delimiter
         */
        String cookieStr = "SID=31d4d96e407aad42";
        String expectedCookieStr = "{\"SID\":\"31d4d96e407aad42\"}";
        JSONObject jsonObject = CookieList.toJSONObject(cookieStr);
        JSONObject expectedJsonObject = new JSONObject(expectedCookieStr);
        Util.compareActualVsExpectedJsonObjects(jsonObject,expectedJsonObject);
    }

    @Test
    public void multiPartCookieList() {
        String cookieStr = 
            "PH=deleted;  "+
            " expires=Wed, 19-Mar-2014 17:53:53 GMT;"+
            "path=/;   "+
            "    domain=.yahoo.com;";
        String expectedCookieStr = 
            "{\"path\":\"/\","+
            "\"expires\":\"Wed, 19-Mar-2014 17:53:53 GMT\","+
            "\"domain\":\".yahoo.com\","+
            "\"PH\":\"deleted\"}";
        JSONObject jsonObject = CookieList.toJSONObject(cookieStr);
        JSONObject expectedJsonObject = new JSONObject(expectedCookieStr);
{'fraction_non_alphanumeric': 0.1072365954255718, 'fraction_numerical': 0.017435320584926885, 'mean_word_length': 2.7703180212014136, 'pattern_counts': {'":': 10, '<': 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': '1956823', 'n_tokens_mistral': 1567, 'n_tokens_neox': 1427, 'n_words': 377}