<commit_before>/*
 * Copyright 2007 <NAME>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package twitter4j;

import java.io.File;
import java.io.FileInputStream;
import java.util.Date;

/**
 * @author <NAME> - <EMAIL>
 * @since Twitter4J 2.2.4
 */
public class UsersResourcesTest extends TwitterTestBase {
    public UsersResourcesTest(String name) {
        super(name);
    }

    protected void setUp() throws Exception {
        super.setUp();
    }

    protected void tearDown() throws Exception {
        super.tearDown();
    }

    public void testShowUser() throws Exception {
        User user = twitter1.showUser("yusuke");
        assertEquals("yusuke", user.getScreenName());
        assertNotNull(user.getLocation());
        assertNotNull(user.getDescription());
        assertNotNull(user.getProfileImageURL());
        assertNotNull(user.getBiggerProfileImageURL());
        assertNotNull(user.getMiniProfileImageURL());
        assertNotNull(user.getOriginalProfileImageURL());

        assertNotNull(user.getProfileImageURLHttps());
        assertNotNull(user.getBiggerProfileImageURLHttps());
        assertNotNull(user.getMiniProfileImageURLHttps());
        assertNotNull(user.getOriginalProfileImageURLHttps());

        assertNotNull(user.getProfileBannerURL());
        HttpClientWrapper wrapper = new HttpClientWrapper();
        wrapper.head(user.getProfileBannerURL());
        wrapper.head(user.getProfileBannerRetinaURL());
        wrapper.head(user.getProfileBannerIPadURL());
        wrapper.head(user.getProfileBannerIPadRetinaURL());
        wrapper.head(user.getProfileBannerMobileURL());
        wrapper.head(user.getProfileBannerMobileRetinaURL());
        assertNotNull(user.getURL());
        assertFalse(user.isProtected());

        assertTrue(0 <= user.getFavouritesCount());
        assertTrue(0 <= user.getFollowersCount());
        assertTrue(0 <= user.getFriendsCount());
        assertNotNull(user.getCreatedAt());
        assertNotNull(user.getTimeZone());
        assertNotNull(user.getProfileBackgroundImageURL());

        assertTrue(0 <= user.getStatusesCount());
        assertNotNull(user.getProfileBackgroundColor());
        assertNotNull(user.getProfileTextColor());
        assertNotNull(user.getProfileLinkColor());
        assertNotNull(user.getProfileSidebarBorderColor());
        assertNotNull(user.getProfileSidebarFillColor());
        assertNotNull(user.getProfileTextColor());

        assertTrue(1 < user.getFollowersCount());
        if (user.getStatus() != null) {
            assertNotNull(user.getStatus().getCreatedAt());
            assertNotNull(user.getStatus().getText());
            assertNotNull(user.getStatus().getSource());
        }

        assertTrue(1 <= user.getListedCount());
        assertFalse(user.isFollowRequestSent());

        //test case for TFJ-91 null pointer exception getting user detail on users with no statuses
        //http://yusuke.homeip.net/jira/browse/TFJ-91
        user = twitter1.showUser("twit4jnoupdate");
        assertNull(user.getProfileBannerURL());
        user = twitter1.showUser("tigertest");
        User previousUser = user;
        assertNotNull(TwitterObjectFactory.getRawJSON(user));

        user = twitter1.showUser(numberId);
        assertEquals(numberIdId, user.getId());
        assertNull(TwitterObjectFactory.getRawJSON(previousUser));
        assertNotNull(TwitterObjectFactory.getRawJSON(user));
        assertEquals(user, TwitterObjectFactory.createUser(TwitterObjectFactory.getRawJSON(user)));

        previousUser = user;
        user = twitter1.showUser(numberIdId);
        assertEquals(numberIdId, user.getId());
        assertNotNull(TwitterObjectFactory.getRawJSON(user));
        assertEquals(user, TwitterObjectFactory.createUser(TwitterObjectFactory.getRawJSON(user)));
    }

    public void testLookupUsers() throws TwitterException {
        ResponseList<User> users = twitter1.lookupUsers(new String[]{id1.screenName, id2.screenName});
        assertEquals(2, users.size());
        assertContains(users, id1);
        assertContains(users, id2);

        users = twitter1.lookupUsers(new long[]{id1.id, id2.id});
        assertEquals(2, users.size());
        assertContains(users, id1);
        assertContains(users, id2);
        assertNotNull(TwitterObjectFactory.getRawJSON(users.get(0)));
        assertEquals(users.get(0), TwitterObjectFactory.createUser(TwitterObjectFactory.getRawJSON(users.get(0))));
        assertNotNull(TwitterObjectFactory.getRawJSON(users));
    }

    private void assertContains(ResponseList<User> users, TestUserInfo user) {
        boolean found = false;
        for (User aUser : users) {
            if (aUser.getId() == user.id && aUser.getScreenName().equals(user.screenName)) {
                found = true;
                break;
            }
        }
        if (!found) {
            fail(user.screenName + " not found in the result.");
        }

    }

    public void testSearchUser() throws TwitterException {
        ResponseList<User> users = twitter1.searchUsers("<NAME>", 1);
        assertTrue(4 < users.size());
        assertNotNull(TwitterObjectFactory.getRawJSON(users.get(0)));
        assertEquals(users.get(0), TwitterObjectFactory.createUser(TwitterObjectFactory.getRawJSON(users.get(0))));
        assertNotNull(TwitterObjectFactory.getRawJSON(users));
    }


    public void testContributors() throws Exception {
        ResponseList<User> users = twitter1.getContributors("twitter");
        assertTrue(users.size() > 0);
        users = twitter1.getContributees(users.get(0).getId());
        assertTrue(users.size() > 0);
    }

    public void testBanner() throws Exception {
        twitter1.updateProfileBanner(getRandomlyChosenFile(banners));
        User user = twitter1.verifyCredentials();
        if (user.getProfileBannerURL() != null) {
            twitter1.removeProfileBanner();
        }
    }

    public void testAccountMethods() throws Exception {
        User original = twitter1.verifyCredentials();
        assertNotNull(TwitterObjectFactory.getRawJSON(original));
        assertEquals(original, TwitterObjectFactory.createUser(TwitterObjectFactory.getRawJSON(original)));
        if (original.getScreenName().endsWith("new") ||
                original.getName().endsWith("new")) {
            original = twitter1.updateProfile(
                    "twit4j", "http://yusuke.homeip.net/twitter4j/"
                    , "location:", "Hi there, I do test a lot!new");

        }
        String newName, newURL, newLocation, newDescription;
        String neu = "new";
        newName = original.getName() + neu;
        newURL = original.getURL() + neu;
        newLocation = new Date().toString();
        newDescription = original.getDescription() + neu;

        User altered = twitter1.updateProfile(
                newName, newURL, newLocation, newDescription);
        assertNotNull(TwitterObjectFactory.getRawJSON(altered));
        assertEquals(original, TwitterObjectFactory.createUser(TwitterObjectFactory.getRawJSON(original)));
        assertEquals(altered, TwitterObjectFactory.createUser(TwitterObjectFactory.getRawJSON(altered)));
        twitter1.updateProfile(original.getName(), original.getURL().toString(), original.getLocation(), original.getDescription());
        assertEquals(newName, altered.getName());
        assertEquals(newURL, altered.getURL().toString());
        assertEquals(newLocation, altered.getLocation());
        assertEquals(newDescription, altered.getDescription());

        User eu;
        eu = twitter1.updateProfileColors("f00", "f0f", "0ff", "0f0", "f0f");
        assertNotNull(TwitterObjectFactory.getRawJSON(eu));
        assertEquals(eu, TwitterObjectFactory.createUser(TwitterObjectFactory.getRawJSON(eu)));
        assertEquals("FF0000", eu.getProfileBackgroundColor());
        assertEquals("FF00FF", eu.getProfileTextColor());
        assertEquals("00FFFF", eu.getProfileLinkColor());
        assertEquals("00FF00", eu.getProfileSidebarFillColor());
        assertEquals("FF00FF", eu.getProfileSidebarBorderColor());
        assertTrue(eu.isProfileUseBackgroundImage());
        assertFalse(eu.isShowAllInlineMedia());
        assertTrue(0 <= eu.getListedCount());
        eu = twitter1.updateProfileColors("87bc44", "9ae4e8", "000000", "0000ff", "e0ff92");<commit_msg>twit4j doesn't seem to use profile background image<commit_after>/*
 * Copyright 2007 <NAME>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package twitter4j;

import java.io.File;
import java.io.FileInputStream;
import java.util.Date;

/**
 * @author <NAME> - yusuke at mac.com
 * @since Twitter4J 2.2.4
 */
public class UsersResourcesTest extends TwitterTestBase {
    public UsersResourcesTest(String name) {
        super(name);
    }

    protected void setUp() throws Exception {
        super.setUp();
    }

    protected void tearDown() throws Exception {
        super.tearDown();
    }

    public void testShowUser() throws Exception {
        User user = twitter1.showUser("yusuke");
        assertEquals("yusuke", user.getScreenName());
        assertNotNull(user.getLocation());
        assertNotNull(user.getDescription());
        assertNotNull(user.getProfileImageURL());
        assertNotNull(user.getBiggerProfileImageURL());
        assertNotNull(user.getMiniProfileImageURL());
        assertNotNull(user.getOriginalProfileImageURL());

        assertNotNull(user.getProfileImageURLHttps());
        assertNotNull(user.getBiggerProfileImageURLHttps());
        assertNotNull(user.getMiniProfileImageURLHttps());
        assertNotNull(user.getOriginalProfileImageURLHttps());

        assertNotNull(user.getProfileBannerURL());
        HttpClientWrapper wrapper = new HttpClientWrapper();
        wrapper.head(user.getProfileBannerURL());
        wrapper.head(user.getProfileBannerRetinaURL());
        wrapper.head(user.getProfileBannerIPadURL());
        wrapper.head(user.getProfileBannerIPadRetinaURL());
        wrapper.head(user.getProfileBannerMobileURL());
        wrapper.head(user.getProfileBannerMobileRetinaURL());
        assertNotNull(user.getURL());
        assertFalse(user.isProtected());

        assertTrue(0 <= user.getFavouritesCount());
        assertTrue(0 <= user.getFollowersCount());
        assertTrue(0 <= user.getFriendsCount());
        assertNotNull(user.getCreatedAt());
        assertNotNull(user.getTimeZone());
        assertNotNull(user.getProfileBackgroundImageURL());

        assertTrue(0 <= user.getStatusesCount());
        assertNotNull(user.getProfileBackgroundColor());
        assertNotNull(user.getProfileTextColor());
        assertNotNull(user.getProfileLinkColor());
        assertNotNull(user.getProfileSidebarBorderColor());
        assertNotNull(user.getProfileSidebarFillColor());
        assertNotNull(user.getProfileTextColor());

        assertTrue(1 < user.getFollowersCount());
        if (user.getStatus() != null) {
            assertNotNull(user.getStatus().getCreatedAt());
            assertNotNull(user.getStatus().getText());
            assertNotNull(user.getStatus().getSource());
        }

        assertTrue(1 <= user.getListedCount());
        assertFalse(user.isFollowRequestSent());

        //test case for TFJ-91 null pointer exception getting user detail on users with no statuses
        //http://yusuke.homeip.net/jira/browse/TFJ-91
        user = twitter1.showUser("twit4jnoupdate");
        assertNull(user.getProfileBannerURL());
        user = twitter1.showUser("tigertest");
        User previousUser = user;
        assertNotNull(TwitterObjectFactory.getRawJSON(user));

        user = twitter1.showUser(numberId);
        assertEquals(numberIdId, user.getId());
        assertNull(TwitterObjectFactory.getRawJSON(previousUser));
        assertNotNull(TwitterObjectFactory.getRawJSON(user));
        assertEquals(user, TwitterObjectFactory.createUser(TwitterObjectFactory.getRawJSON(user)));

        previousUser = user;
        user = twitter1.showUser(numberIdId);
        assertEquals(numberIdId, user.getId());
        assertNotNull(TwitterObjectFactory.getRawJSON(user));
        assertEquals(user, TwitterObjectFactory.createUser(TwitterObjectFactory.getRawJSON(user)));
    }

    public void testLookupUsers() throws TwitterException {
        ResponseList<User> users = twitter1.lookupUsers(new String[]{id1.screenName, id2.screenName});
        assertEquals(2, users.size());
        assertContains(users, id1);
        assertContains(users, id2);

        users = twitter1.lookupUsers(new long[]{id1.id, id2.id});
        assertEquals(2, users.size());
        assertContains(users, id1);
        assertContains(users, id2);
        assertNotNull(TwitterObjectFactory.getRawJSON(users.get(0)));
        assertEquals(users.get(0), TwitterObjectFactory.createUser(TwitterObjectFactory.getRawJSON(users.get(0))));
        assertNotNull(TwitterObjectFactory.getRawJSON(users));
    }

    private void assertContains(ResponseList<User> users, TestUserInfo user) {
        boolean found = false;
        for (User aUser : users) {
            if (aUser.getId() == user.id && aUser.getScreenName().equals(user.screenName)) {
                found = true;
                break;
            }
        }
        if (!found) {
            fail(user.screenName + " not found in the result.");
        }

    }

    public void testSearchUser() throws TwitterException {
        ResponseList<User> users = twitter1.searchUsers("<NAME>", 1);
        assertTrue(4 < users.size());
        assertNotNull(TwitterObjectFactory.getRawJSON(users.get(0)));
        assertEquals(users.get(0), TwitterObjectFactory.createUser(TwitterObjectFactory.getRawJSON(users.get(0))));
        assertNotNull(TwitterObjectFactory.getRawJSON(users));
    }


    public void testContributors() throws Exception {
        ResponseList<User> users = twitter1.getContributors("twitter");
        assertTrue(users.size() > 0);
        users = twitter1.getContributees(users.get(0).getId());
        assertTrue(users.size() > 0);
    }

    public void testBanner() throws Exception {
        twitter1.updateProfileBanner(getRandomlyChosenFile(banners));
        User user = twitter1.verifyCredentials();
        if (user.getProfileBannerURL() != null) {
            twitter1.removeProfileBanner();
        }
    }

    public void testAccountMethods() throws Exception {
        User original = twitter1.verifyCredentials();
        assertNotNull(TwitterObjectFactory.getRawJSON(original));
        assertEquals(original, TwitterObjectFactory.createUser(TwitterObjectFactory.getRawJSON(original)));
        if (original.getScreenName().endsWith("new") ||
                original.getName().endsWith("new")) {
            original = twitter1.updateProfile(
                    "twit4j", "http://yusuke.homeip.net/twitter4j/"
                    , "location:", "Hi there, I do test a lot!new");

        }
        String newName, newURL, newLocation, newDescription;
        String neu = "new";
        newName = original.getName() + neu;
        newURL = original.getURL() + neu;
        newLocation = new Date().toString();
        newDescription = original.getDescription() + neu;

        User altered = twitter1.updateProfile(
                newName, newURL, newLocation, newDescription);
        assertNotNull(TwitterObjectFactory.getRawJSON(altered));
        assertEquals(original, TwitterObjectFactory.createUser(TwitterObjectFactory.getRawJSON(original)));
        assertEquals(altered, TwitterObjectFactory.createUser(TwitterObjectFactory.getRawJSON(altered)));
        twitter1.updateProfile(original.getName(), original.getURL().toString(), original.getLocation(), original.getDescription());
        assertEquals(newName, altered.getName());
        assertEquals(newURL, altered.getURL().toString());
        assertEquals(newLocation, altered.getLocation());
        assertEquals(newDescription, altered.getDescription());

        User eu;
        eu = twitter1.updateProfileColors("f00", "f0f", "0ff", "0f0", "f0f");
        assertNotNull(TwitterObjectFactory.getRawJSON(eu));
        assertEquals(eu, TwitterObjectFactory.createUser(TwitterObjectFactory.getRawJSON(eu)));
        assertEquals("FF0000", eu.getProfileBackgroundColor());
        assertEquals("FF00FF", eu.getProfileTextColor());
        assertEquals("00FFFF", eu.getProfileLinkColor());
        assertEquals("00FF00", eu.getProfileSidebarFillColor());
        assertEquals("FF00FF", eu.getProfileSidebarBorderColor());
        assertFalse(eu.isProfileUseBackgroundImage());
        assertFalse(eu.isShowAllInlineMedia());
        assertTrue(0 <= eu.getListedCount());
        eu = twitter1.updateProfileColors("87bc44", "9ae4e8", "000000", "0000ff", "e0ff92");
{'fraction_non_alphanumeric': 0.11905964203557201, 'fraction_numerical': 0.01217527913370364, 'mean_word_length': 3.412973508294132, 'pattern_counts': {'":': 0, '<': 34, '<?xml version=': 0, '>': 22, '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': '4626171', 'n_tokens_mistral': 4830, 'n_tokens_neox': 4646, 'n_words': 850}