<commit_before>/*
 * See the NOTICE file distributed with this work for additional
 * information regarding copyright ownership.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see http://www.gnu.org/licenses/
 */
package org.phenotips.data.push.internal;

import org.xwiki.component.manager.ComponentLookupException;

import java.util.Set;
import java.util.TreeSet;

import org.json.JSONObject;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

public class DefaultPushServerConfigurationResponseTest
{

    private DefaultPushServerConfigurationResponse defaultPushServerConfigurationResponse;

    private JSONObject serverResponse;

    private Set<String> expected;

    @Before
    public void setUp()
    {
        serverResponse = new JSONObject();
        defaultPushServerConfigurationResponse = new
            DefaultPushServerConfigurationResponse(serverResponse);
        expected = new TreeSet<String>();
    }

    @Test
    public void getRemoteUserGroupsTest() throws ComponentLookupException
    {
        // populate a JSONObject
        for (int i = 0; i < 10; i++) {
            serverResponse.accumulate("user_groups", i);
            expected.add(String.valueOf(i));
        }

        Assert.assertEquals(expected, defaultPushServerConfigurationResponse.getRemoteUserGroups());
    }

    @Test
    public void getRemoteUserGroupsNullTest()
    {
        Assert.assertNull(defaultPushServerConfigurationResponse.getRemoteUserGroups());
    }

    @Test
    public void getRemoteAcceptedPatientFieldsTest()
    {
        // populate a JSONObject
        for (int i = 0; i < 10; i++) {
            serverResponse.accumulate("accepted_fields", i);
            expected.add(String.valueOf(i));
        }

        Assert.assertEquals(expected, defaultPushServerConfigurationResponse.getRemoteAcceptedPatientFields());
        Assert.assertEquals(expected, defaultPushServerConfigurationResponse.getRemoteAcceptedPatientFields("string"));
    }

    @Test
    public void getRemoteAcceptedPatientFieldsNullTest()
    {
        Assert.assertNull(defaultPushServerConfigurationResponse.getRemoteAcceptedPatientFields());
        Assert.assertNull(defaultPushServerConfigurationResponse.getRemoteAcceptedPatientFields("string"));
    }

    @Test
    public void getPushableFieldsTest()
    {
        // populate a JSONObject
        for (int i = 0; i < 10; i++) {
            serverResponse.accumulate("accepted_fields", i);
            expected.add(String.valueOf(i));
        }

        Assert.assertTrue(defaultPushServerConfigurationResponse.getPushableFields().isEmpty());
        Assert.assertTrue(defaultPushServerConfigurationResponse.getPushableFields("string").isEmpty());
    }

    @Test
    public void getPushableFieldsNullTest()
    {
        Assert.assertTrue(defaultPushServerConfigurationResponse.getPushableFields().isEmpty());
        Assert.assertTrue(defaultPushServerConfigurationResponse.getPushableFields("string").isEmpty());
    }

    @Test
    public void getPushableFieldsExceptionTest()
    {
        serverResponse = null;
        Assert.assertTrue(defaultPushServerConfigurationResponse.getPushableFields().isEmpty());
    }

    @Test
    public void remoteUpdatesAvailableTest()
    {
        serverResponse.accumulate("updates_enabled", true);
        Assert.assertTrue(defaultPushServerConfigurationResponse.remoteUpdatesEnabled());
    }

    @Test
    public void remoteUpdatesNotAvailableTest()
    {
        // check before anything has been set
        Assert.assertFalse(defaultPushServerConfigurationResponse.remoteUpdatesEnabled());
        serverResponse.accumulate("updates_enabled", false);
        // check after it has been set false
        Assert.assertFalse(defaultPushServerConfigurationResponse.remoteUpdatesEnabled());
    }

    @Test
    public void getRemoteUserTokenTest()
    {
        Assert.assertNull(defaultPushServerConfigurationResponse.getRemoteUserToken());
        serverResponse.accumulate("user_login_token", "yes");
        Assert.assertEquals("yes", defaultPushServerConfigurationResponse.getRemoteUserToken());
    }

}<commit_msg>[cleanup] Applied codestyle<commit_after>/*
 * See the NOTICE file distributed with this work for additional
 * information regarding copyright ownership.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see http://www.gnu.org/licenses/
 */
package org.phenotips.data.push.internal;

import org.xwiki.component.manager.ComponentLookupException;

import java.util.Set;
import java.util.TreeSet;

import org.json.JSONObject;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

public class DefaultPushServerConfigurationResponseTest
{
    private DefaultPushServerConfigurationResponse defaultPushServerConfigurationResponse;

    private JSONObject serverResponse;

    private Set<String> expected;

    @Before
    public void setUp()
    {
        this.serverResponse = new JSONObject();
        this.defaultPushServerConfigurationResponse = new DefaultPushServerConfigurationResponse(this.serverResponse);
        this.expected = new TreeSet<>();
    }

    @Test
    public void getRemoteUserGroupsTest() throws ComponentLookupException
    {
        // populate a JSONObject
        for (int i = 0; i < 10; i++) {
            this.serverResponse.accumulate("user_groups", i);
            this.expected.add(String.valueOf(i));
        }

        Assert.assertEquals(this.expected, this.defaultPushServerConfigurationResponse.getRemoteUserGroups());
    }

    @Test
    public void getRemoteUserGroupsNullTest()
    {
        Assert.assertNull(this.defaultPushServerConfigurationResponse.getRemoteUserGroups());
    }

    @Test
    public void getRemoteAcceptedPatientFieldsTest()
    {
        // populate a JSONObject
        for (int i = 0; i < 10; i++) {
            this.serverResponse.accumulate("accepted_fields", i);
            this.expected.add(String.valueOf(i));
        }

        Assert.assertEquals(this.expected,
            this.defaultPushServerConfigurationResponse.getRemoteAcceptedPatientFields());
        Assert.assertEquals(this.expected,
            this.defaultPushServerConfigurationResponse.getRemoteAcceptedPatientFields("string"));
    }

    @Test
    public void getRemoteAcceptedPatientFieldsNullTest()
    {
        Assert.assertNull(this.defaultPushServerConfigurationResponse.getRemoteAcceptedPatientFields());
        Assert.assertNull(this.defaultPushServerConfigurationResponse.getRemoteAcceptedPatientFields("string"));
    }

    @Test
    public void getPushableFieldsTest()
    {
        // populate a JSONObject
        for (int i = 0; i < 10; i++) {
            this.serverResponse.accumulate("accepted_fields", i);
            this.expected.add(String.valueOf(i));
        }

        Assert.assertTrue(this.defaultPushServerConfigurationResponse.getPushableFields().isEmpty());
        Assert.assertTrue(this.defaultPushServerConfigurationResponse.getPushableFields("string").isEmpty());
    }

    @Test
    public void getPushableFieldsNullTest()
    {
        Assert.assertTrue(this.defaultPushServerConfigurationResponse.getPushableFields().isEmpty());
        Assert.assertTrue(this.defaultPushServerConfigurationResponse.getPushableFields("string").isEmpty());
    }

    @Test
    public void getPushableFieldsExceptionTest()
    {
        this.serverResponse = null;
        Assert.assertTrue(this.defaultPushServerConfigurationResponse.getPushableFields().isEmpty());
    }

    @Test
    public void remoteUpdatesAvailableTest()
    {
        this.serverResponse.accumulate("updates_enabled", true);
        Assert.assertTrue(this.defaultPushServerConfigurationResponse.remoteUpdatesEnabled());
    }

    @Test
    public void remoteUpdatesNotAvailableTest()
    {
        // check before anything has been set
        Assert.assertFalse(this.defaultPushServerConfigurationResponse.remoteUpdatesEnabled());
        this.serverResponse.accumulate("updates_enabled", false);
        // check after it has been set false
        Assert.assertFalse(this.defaultPushServerConfigurationResponse.remoteUpdatesEnabled());
    }

    @Test
    public void getRemoteUserTokenTest()
    {
        Assert.assertNull(this.defaultPushServerConfigurationResponse.getRemoteUserToken());
        this.serverResponse.accumulate("user_login_token", "yes");
        Assert.assertEquals("yes", this.defaultPushServerConfigurationResponse.getRemoteUserToken());
    }
}
{'fraction_non_alphanumeric': 0.08550108819566794, 'fraction_numerical': 0.002072753653228314, 'mean_word_length': 3.639423076923077, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '3027489', 'n_tokens_mistral': 2409, 'n_tokens_neox': 2332, 'n_words': 562}