/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You 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 org.apache.shardingsphere.shardingproxy.transport.mysql.packet.command.query.text;

import org.apache.shardingsphere.shardingproxy.transport.mysql.payload.MySQLPacketPayload;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;

import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

@RunWith(MockitoJUnitRunner.class)
public final class MySQLTextResultSetRowPacketTest {
    
    @Mock
    private MySQLPacketPayload payload;
    
    @Test
    public void assertWrite() {
        when(payload.readInt1()).thenReturn(1);
        when(payload.readStringLenenc()).thenReturn("value_a", null, "value_c");
        MySQLTextResultSetRowPacket actual = new MySQLTextResultSetRowPacket(payload, 3);
        assertThat(actual.getSequenceId(), is(1));
        actual.write(payload);
        verify(payload).writeStringLenenc("value_a");
        verify(payload).writeStringLenenc("value_c");
        verify(payload).writeInt1(0xfb);
    }
}

@@ -1106,16 +1106,71 @@
 unner;%0A%0A
+import java.math.BigDecimal;%0Aimport java.util.Arrays;%0A%0A
 import s
@@ -1248,16 +1248,57 @@
 rtThat;%0A
+import static org.mockito.Mockito.times;%0A
 import s
@@ -1556,13 +1556,11 @@
 sert
-Write
+New
 () %7B
@@ -1830,16 +1830,273 @@
 is(1));%0A
+        verify(payload, times(3)).readStringLenenc();%0A    %7D%0A    %0A    @Test%0A    public void assertWrite() %7B%0A        MySQLTextResultSetRowPacket actual = new MySQLTextResultSetRowPacket(1, Arrays.%3CObject%3EasList(null, %22value%22, BigDecimal.ONE, new byte%5B%5D %7B%7D));%0A
         
@@ -2151,30 +2151,17 @@
 rite
-StringLenenc(%22value_a%22
+Int1(0xfb
 );%0A 
@@ -2203,26 +2203,24 @@
 enenc(%22value
-_c
 %22);%0A        
@@ -2236,32 +2236,39 @@
 yload).write
-Int1(0xfb
+StringLenenc(%221%22
 );%0A    %7D%0A%7D%0A

add assertNew for MySQLTextResultSetRowPacket