/**
 * Copyright © 2016 Sascha Lamp (sascha.lamp@outlook.de)
 * <p>
 * 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
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * 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 de.lampware.racing.istats.factory;

import static de.lampware.racing.istats.assertions.model.SubsessionResultsRowAssert.assertThat;

import static org.assertj.core.api.Assertions.assertThatThrownBy;

import de.lampware.racing.istats.exception.UnexpectedDataException;
import de.lampware.racing.istats.model.SubsessionResultsRow;

import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import org.junit.Test;

/**
 * TODO JavaDoc
 */
public class SubsessionResultsRowFactoryTest {

    @Test
    public void testCreateNoJsonObject() throws Exception {
        JsonArray jsonArray = new JsonArray();

        SubsessionResultsRowFactory subsessionResultsRowFactory = new SubsessionResultsRowFactory();
        assertThatThrownBy(() -> subsessionResultsRowFactory.create(jsonArray))
                .isInstanceOf(UnexpectedDataException.class);
    }

    @Test
    public void testCreate() throws Exception {
        JsonObject jsonObject = new JsonObject();
        jsonObject.addProperty("carnum", "42");
        jsonObject.addProperty("custid", 123456);
        jsonObject.addProperty("displayname", "Some+Name");
        jsonObject.addProperty("groupid", -654321);
        jsonObject.addProperty("carclassid", 77);
        jsonObject.addProperty("simsesnum", 987654321);
        jsonObject.addProperty("startpos", 5);
        jsonObject.addProperty("lapscomplete", 56);
        jsonObject.addProperty("lapslead", 42);
        jsonObject.addProperty("oldirating", 2289);
        jsonObject.addProperty("newirating", 2346);

        SubsessionResultsRowFactory subsessionResultsRowFactory = new SubsessionResultsRowFactory();
        SubsessionResultsRow resultsRow = subsessionResultsRowFactory.create(jsonObject);

        assertThat(resultsRow)
                .hasCarNumber("42")
                .hasCustomerId(123456)
                .hasDisplayName("Some Name")
                .hasGroupId(-654321)
                .hasCarClassId(77)
                .hasSimSesNum(987654321)
                .hasStartingPosition(5)
                .hasLapsCompleted(56)
                .hasLapsLed(42)
                .hasOldIrating(2289)
                .hasNewIrating(2346);
    }
}