/*
 * Copyright 2017, TeamDev Ltd. All rights reserved.
 *
 * Redistribution and use in source and/or binary forms, with or without
 * modification, must retain the above copyright notice and the following
 * disclaimer.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

package org.spine3.client;

import com.google.common.testing.EqualsTester;
import com.google.common.testing.NullPointerTester;
import com.google.protobuf.StringValue;
import org.junit.Test;

import static java.lang.String.*;
import static org.hamcrest.Matchers.containsString;
import static org.junit.Assert.assertThat;
import static org.spine3.client.QueryParameter.eq;

/**
 * @author Dmytro Dashenkov
 */
public class QueryParameterShould {

    @Test
    public void not_accept_nulls() {
        new NullPointerTester().testAllPublicStaticMethods(QueryParameter.class);
    }

    @Test
    public void support_equality() {
        final String param1 = "param1";
        final String param2 = "param2";
        final String foobar = "foobar";
        final String baz = "baz";
        final StringValue foobarValue = StringValue.newBuilder()
                                                   .setValue(foobar)
                                                   .build();

        final QueryParameter parameter1 = eq(param1, foobar);
        final QueryParameter parameter2 = eq(param1, foobarValue);
        final QueryParameter parameter3 = eq(param1, baz);
        final QueryParameter parameter4 = eq(param2, foobar);

        new EqualsTester()
                .addEqualityGroup(parameter1, parameter2)
                .addEqualityGroup(parameter3)
                .addEqualityGroup(parameter4)
                .testEquals();
    }

    @Test
    public void support_toString() {
        final String name = "myColumn";
        final int value = 42;

        final QueryParameter param = eq(name, value);
        final String stringRepr = param.toString();

        assertThat(stringRepr, containsString(name));
        assertThat(stringRepr, containsString(valueOf(value)));
    }
}

@@ -1177,16 +1177,54 @@
 gValue;%0A
+import com.google.protobuf.Timestamp;%0A
 import o
@@ -1270,17 +1270,23 @@
 .String.
-*
+valueOf
 ;%0Aimport
@@ -1331,16 +1331,61 @@
 String;%0A
+import static org.junit.Assert.assertEquals;%0A
 import s
@@ -1469,16 +1469,175 @@
 eter.eq;
+%0Aimport static org.spine3.client.QueryParameter.laterThen;%0Aimport static org.spine3.protobuf.AnyPacker.pack;%0Aimport static org.spine3.time.Time.getCurrentTime;
 %0A%0A/**%0A *
@@ -1781,16 +1781,110 @@
 Tester()
+%0A                .setDefault(Timestamp.class, Timestamp.getDefaultInstance())%0A                
 .testAll
@@ -2060,16 +2060,56 @@
 aram2%22;%0A
+        final String param3 = %22param3%22;%0A
         
@@ -2368,16 +2368,75 @@
 build();
+%0A        final Timestamp timestampValue = getCurrentTime();
 %0A%0A      
@@ -2678,16 +2678,225 @@
 foobar);
+%0A        final QueryParameter parameter5 = laterThen(param3, timestampValue);%0A        final QueryParameter parameter6 = eq(param3, timestampValue);%0A        final QueryParameter parameter7 = eq(param1, foobar);
 %0A%0A      
@@ -2972,16 +2972,28 @@
 rameter2
+, parameter7
 )%0A      
@@ -3078,16 +3078,108 @@
 meter4)%0A
+                .addEqualityGroup(parameter5)%0A                .addEqualityGroup(parameter6)%0A
         
@@ -3537,22 +3537,899 @@
 ing(
-valueOf(value)
+param.getOperator().toString()));%0A        assertThat(stringRepr, containsString(valueOf(value)));%0A    %7D%0A%0A    @Test%0A    public void create_EQUALS_instances() %7B%0A        final String name = %22preciseColumn%22;%0A        final Timestamp value = getCurrentTime();%0A%0A        final QueryParameter param = eq(name, value);%0A%0A        assertEquals(name, param.getColumnName());%0A        assertEquals(pack(value), param.getValue());%0A        assertEquals(QueryParameter.Operator.EQUAL, param.getOperator());%0A    %7D%0A%0A    @Test%0A    public void create_LATER_THEN_instances() %7B%0A        final String name = %22blurryColumn%22;%0A        final Timestamp value = getCurrentTime();%0A%0A        final QueryParameter param = laterThen(name, value);%0A%0A        assertEquals(name, param.getColumnName());%0A        assertEquals(pack(value), param.getValue());%0A        assertEquals(QueryParameter.Operator.GREATER_THEN, param.getOperator(
 ));%0A

Update the QueryParameter tests.