/*
 * Copyright (c) 2013-2019 Cinchapi Inc.
 *
 * 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.cinchapi.concourse.thrift;

import org.apache.commons.lang.StringUtils;
import org.junit.Assert;
import org.junit.Test;

import com.cinchapi.concourse.Tag;
import com.cinchapi.concourse.util.Convert;
import com.cinchapi.concourse.util.Random;

/**
 * Unit tests for the constraints promised by the
 * {@link com.cinchapi.concourse.thrift.TObject}
 * class.
 *
 * @author Jeff Nelson
 */
public class TObjectTest {

    @Test
    public void testTagAndStringAreEqual() {
        String base = Random.getString();
        TObject string = Convert.javaToThrift(base);
        TObject tag = Convert.javaToThrift(Tag.create(base));
        Assert.assertEquals(tag, string);
    }

    @Test
    public void testTagAndStringHaveSameHashCode() {
        String base = Random.getString();
        TObject string = Convert.javaToThrift(base);
        TObject tag = Convert.javaToThrift(Tag.create(base));
        Assert.assertEquals(tag.hashCode(), string.hashCode());
    }

    @Test
    public void testTagAndStringDoNotMatch() {
        String base = Random.getString();
        TObject string = Convert.javaToThrift(base);
        TObject tag = Convert.javaToThrift(Tag.create(base));
        Assert.assertFalse(tag.matches(string));
        Assert.assertFalse(string.matches(tag));
    }

    @Test
    public void testNullIsAlwaysBlank() {
        Assert.assertTrue(TObject.NULL.isBlank());
    }

    @Test
    public void testIsBlankPositive() {
        int count = Random.getScaleCount();
        String s = "";
        for (int i = 0; i < count; ++i) {
            s += " ";
        }
        TObject t = Convert.javaToThrift(s);
        Assert.assertTrue(t.isBlank());
    }

    @Test
    public void testIsBlankNegative() {
        int count = Random.getScaleCount();
        String s = "";
        for (int i = 0; i < count; ++i) {
            s += " ";
        }
        String extra = "";
        while (StringUtils.isBlank(extra)) {
            extra = Random.getString();
        }
        s += extra;
        count = Random.getScaleCount();
        for (int i = 0; i < count; ++i) {
            s += " ";
        }
        TObject t = Convert.javaToThrift(s);
        Assert.assertFalse(t.isBlank());
    }

}

@@ -2826,10 +2826,295 @@
 %0A    %7D%0A%0A
+    @Test%0A    public void testCompareTo() %7B%0A        TObject big = Convert.javaToThrift(1564359884275001L);%0A        TObject small = Convert.javaToThrift(1564359884211000L);%0A        Assert.assertTrue(big.compareTo(small) %3E 0);%0A        Assert.assertTrue(small.compareTo(big) %3C 0);%0A    %7D%0A%0A
 %7D%0A

add unit test to ensure TObject#compareTo is implemented correctly