/*-
 * -\-\-
 * github-api
 * --
 * Copyright (C) 2016 - 2020 Spotify AB
 * --
 * 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.spotify.github.http;

import static java.util.stream.Collectors.toList;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.MatcherAssert.assertThat;

import java.util.Arrays;
import java.util.List;
import org.junit.jupiter.api.Test;

public class LinkTest {

  @Test
  public void testFromLinkString() {
    final String link =
        "<https://github.com/api/v3/repositories/44219/issues/53/comments?page=2>; rel=\"next\", <https://github.com/api/v3/repositories/44219/issues/53/comments?page=4>; rel=\"last\"";

    final List<Link> links =
        Arrays.stream(link.split(","))
            .map(linkString -> Link.from(linkString.split(";")))
            .collect(toList());

    assertThat(
        links.get(0).url().toString(),
        is("https://github.com/api/v3/repositories/44219/issues/53/comments?page=2"));
  }
}
