/*
 * 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 com.facebook.presto.spi;

import org.testng.annotations.Test;

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

import static io.airlift.testing.Assertions.assertLessThanOrEqual;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;

public class TestStandardErrorCode
{
    @Test
    public void testUnique()
    {
        Set<Integer> codes = new HashSet<>();
        for (StandardErrorCode code : StandardErrorCode.values()) {
            assertTrue(codes.add(code.toErrorCode().getCode()), "Code already exists: " + code);
        }
        assertEquals(codes.size(), StandardErrorCode.values().length);
    }

    @Test
    public void testReserved()
    {
        for (StandardErrorCode errorCode : StandardErrorCode.values()) {
            assertLessThanOrEqual(errorCode.toErrorCode().getCode(), StandardErrorCode.EXTERNAL.toErrorCode().getCode());
        }
    }
}

@@ -669,21 +669,391 @@
 va.util.
-Set;%0A
+Iterator;%0Aimport java.util.Set;%0A%0Aimport static com.facebook.presto.spi.StandardErrorCode.EXTERNAL;%0Aimport static com.facebook.presto.spi.StandardErrorCode.INSUFFICIENT_RESOURCES;%0Aimport static com.facebook.presto.spi.StandardErrorCode.INTERNAL;%0Aimport static com.facebook.presto.spi.StandardErrorCode.USER_ERROR;%0Aimport static io.airlift.testing.Assertions.assertGreaterThan;
 %0Aimport 
@@ -1112,16 +1112,55 @@
 rEqual;%0A
+import static java.util.Arrays.asList;%0A
 import s
@@ -1475,39 +1475,21 @@
 add(code
-.toErrorCode().getC
+(c
 ode
-(
 )), %22Cod
@@ -1759,16 +1759,21 @@
 OrEqual(
+code(
 errorCod
@@ -1777,96 +1777,1281 @@
 Code
-.toErrorCode().getCode(), StandardErrorCode.EXTERNAL.toErrorCode().getCode());%0A        %7D
+), code(EXTERNAL));%0A        %7D%0A    %7D%0A%0A    @Test%0A    public void testOrdering()%0A            throws Exception%0A    %7B%0A        Iterator%3CStandardErrorCode%3E iterator = asList(StandardErrorCode.values()).iterator();%0A%0A        assertTrue(iterator.hasNext());%0A        int previous = code(iterator.next());%0A%0A        while (iterator.hasNext()) %7B%0A            StandardErrorCode code = iterator.next();%0A            int current = code(code);%0A            assertGreaterThan(current, previous, %22Code is out of order: %22 + code);%0A            if ((code != INTERNAL) && (code != INSUFFICIENT_RESOURCES) && (code != EXTERNAL)) %7B%0A                assertEquals(current, previous + 1, %22Code is not sequential: %22 + code);%0A            %7D%0A            previous = current;%0A        %7D%0A        assertEquals(previous, code(EXTERNAL), %22Last code is not EXTERNAL%22);%0A    %7D%0A%0A    @Test%0A    public void testCategoryCodes()%0A            throws Exception%0A    %7B%0A        assertEquals(code(USER_ERROR), 0);%0A        assertGreaterThan(code(INTERNAL), code(USER_ERROR));%0A        assertGreaterThan(code(INSUFFICIENT_RESOURCES), code(INTERNAL));%0A        assertGreaterThan(code(EXTERNAL), code(INSUFFICIENT_RESOURCES));%0A    %7D%0A%0A    private static int code(StandardErrorCode error)%0A    %7B%0A        return error.toErrorCode().getCode();
 %0A   

Add additional tests for StandardErrorCode