Package br.com.objectos.way.etc

Source Code of br.com.objectos.way.etc.EtcsTest

/*
* ScalarTest.java criado em 07/09/2012
*
* Propriedade de Objectos Fábrica de Software LTDA.
* Reprodução parcial ou total proibida.
*/
package br.com.objectos.way.etc;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;

import org.testng.annotations.Guice;
import org.testng.annotations.Test;

import br.com.objectos.way.etc.model.FakeGlobals;
import br.com.objectos.way.etc.model.Global;
import br.com.objectos.way.etc.model.User;

import com.google.inject.Inject;

/**
* @author marcio.endo@objectos.com.br (Marcio Endo)
*/
@Test
@Guice(modules = { EtcTestModule.class })
public class EtcsTest {

  @Inject
  private Etcs etcs;

  public void read() {
    User res = etcs.read(User.class);

    assertThat(res.getName(), equalTo("User A"));
    assertThat(res.getEmail(), equalTo("a@objectos.com.br"));
  }

  public void read_property() {
    Object res = etcs.readProperty("user.name");

    assertThat(res, equalTo((Object) "User A"));
  }

  public void write() {
    Global.FILE.delete();
    String expected = EtcFiles.readLines("/model/global-usera.yaml");

    Global global = FakeGlobals.GLOBAL_USER_A;
    etcs.write(global);

    String res = EtcFiles.readLines(Global.FILE);
    assertThat(res, equalTo(expected));
  }

  public void writeProperty() {
    Global.FILE.delete();

    Global global = FakeGlobals.GLOBAL_USER_A;
    etcs.write(global);

    Global read = etcs.read(Global.class);
    assertThat(read.getString(), equalTo(global.getString()));
    assertThat(read.getInteger(), equalTo(global.getInteger()));

    etcs.writeProperty("global.string", "xyz");
    etcs.writeProperty("global.integer", "789");

    Global res = etcs.read(Global.class);
    assertThat(res.getString(), equalTo("xyz"));
    assertThat(res.getInteger(), equalTo(789));
  }

}
TOP

Related Classes of br.com.objectos.way.etc.EtcsTest

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.