Package br.com.objectos.way.ui

Source Code of br.com.objectos.way.ui.ParameterWrapperTest

/*
* Copyright 2014 Objectos, Fábrica de Software LTDA.
*
* 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 br.com.objectos.way.ui;

import static br.com.objectos.way.base.testing.WayMatchers.equalTo;
import static org.hamcrest.MatcherAssert.assertThat;

import java.util.Map;

import org.testng.annotations.Test;

import com.google.common.collect.ImmutableMap;
import com.google.sitebricks.headless.FakeRequestBuilder;
import com.google.sitebricks.headless.Request;

/**
* @author marcio.endo@objectos.com.br (Marcio Endo)
*/
@Test
public class ParameterWrapperTest {

  public void get_string() {
    Map<String, String> map = newMap("abc");

    ParameterWrapper req = newReq(map);
    ParameterWrapper url = newUrl(map);

    assertThat(req.get("key"), equalTo("abc"));
    assertThat(url.get("key"), equalTo("abc"));
  }

  public void get_int() {
    Map<String, String> map = newMap("123");

    ParameterWrapper req = newReq(map);
    ParameterWrapper url = newUrl(map);

    assertThat(req.getInt("key"), equalTo(123));
    assertThat(url.getInt("key"), equalTo(123));
  }

  public void get_int_error() {
    Map<String, String> map = newMap("123x");

    ParameterWrapper req = newReq(map);
    ParameterWrapper url = newUrl(map);

    assertThat(req.getInt("key"), equalTo(0));
    assertThat(url.getInt("key"), equalTo(0));
  }

  public void get_long() {
    Map<String, String> map = newMap("123");

    ParameterWrapper req = newReq(map);
    ParameterWrapper url = newUrl(map);

    assertThat(req.getLong("key"), equalTo(123l));
    assertThat(url.getLong("key"), equalTo(123l));
  }

  public void get_long_error() {
    Map<String, String> map = newMap("123x");

    ParameterWrapper req = newReq(map);
    ParameterWrapper url = newUrl(map);

    assertThat(req.getLong("key"), equalTo(0l));
    assertThat(url.getLong("key"), equalTo(0l));
  }

  private ParameterWrapper newReq(Map<String, String> map) {
    Request request = new FakeRequestBuilder()
        .paramMap(map)
        .build();
    return ParameterWrapper.of(request);
  }

  private ParameterWrapper newUrl(Map<String, String> map) {
    return ParameterWrapper.of(map);
  }

  private Map<String, String> newMap(String v1) {
    return ImmutableMap.<String, String> of("key", v1);
  }

}
TOP

Related Classes of br.com.objectos.way.ui.ParameterWrapperTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.