package com.asana;

import com.asana.errors.*;
import org.junit.Assert;
import org.junit.Test;

import java.io.IOException;

public class ErrorsTest extends AsanaTest
{
    @Test(expected = NoAuthorizationError.class)
    public void testNotAuthorized() throws IOException
    {
        dispatcher.registerResponse("GET", "http://app/users/me").code(401).content("{ \"errors\": [{ \"message\": \"Not Authorized\" }]}");

        client.users.me().execute();
    }

    @Test(expected = InvalidRequestError.class)
    public void testInvalidRequest() throws IOException
    {
        dispatcher.registerResponse("GET", "http://app/users/me").code(400).content("{ \"errors\": [{ \"message\": \"Missing input\" }] }");

        client.users.me().execute();
    }

    @Test(expected = ServerError.class)
    public void testServerError() throws IOException
    {
        dispatcher.registerResponse("GET", "http://app/users/me").code(500).content("{ \"errors\": [ { \"message\": \"Server Error\", \"phrase\": \"6 sad squid snuggle softly\" } ] }");

        client.users.me().option("max_retries", 0).execute();
    }

    @Test(expected = NotFoundError.class)
    public void testNotFound() throws IOException
    {
        dispatcher.registerResponse("GET", "http://app/users/me").code(404).content("{ \"errors\": [ { \"message\": \"user: Unknown object: 1234\" } ] }");

        client.users.me().execute();
    }

    @Test(expected = ForbiddenError.class)
    public void testForbidden() throws IOException
    {
        dispatcher.registerResponse("GET", "http://app/users/me").code(403).content("{ \"errors\": [ { \"message\": \"user: Forbidden\" } ] }");

        client.users.me().execute();
    }
}

@@ -1646,32 +1646,840 @@
 den%5C%22 %7D %5D %7D%22);%0A%0A
+        client.users.me().execute();%0A    %7D%0A%0A    @Test(expected = PremiumOnlyError.class)%0A    public void testPremiumOnlyError402() throws IOException%0A    %7B%0A        // Handles actual 402 errors%0A        dispatcher.registerResponse(%22GET%22, %22http://app/users/me%22).code(402).content(%0A              %22%7B %5C%22errors%5C%22: %5B %7B %5C%22message%5C%22: %5C%22Custom Fields are not available for free users or guests.%5C%22 %7D %5D %7D%22);%0A%0A        client.users.me().execute();%0A    %7D%0A%0A    @Test(expected = PremiumOnlyError.class)%0A    public void testPremiumOnlyError403() throws IOException%0A    %7B%0A        // Handles 403 errors with a premium message%0A        dispatcher.registerResponse(%22GET%22, %22http://app/users/me%22).code(403).content(%0A              %22%7B %5C%22errors%5C%22: %5B %7B %5C%22message%5C%22: %5C%22Custom Fields are not available for free users or guests.%5C%22 %7D %5D %7D%22);%0A%0A
         client.u

Add tests for 402/403 cases.