Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * MappingsTest.java criado em 27/12/2013
   * 
   * Propriedade de Objectos Fábrica de Software LTDA.
   * Reprodução parcial ou total proibida.
   */
  package br.com.objectos.way.etc;
  
  import static com.google.common.collect.Lists.transform;
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.hamcrest.Matchers.equalTo;
 
 import java.io.File;
 import java.util.List;
 import java.util.UUID;
 
 
 

Author(s):
marcio.endo@objectos.com.br (Marcio Endo)
 
 @Guice(modules = { EtcTestModule.class })
 public class MappingsTest {
 
   @Inject
   private Mappings mappings;
 
   public void scalar_single() {
     String text = EtcFiles.readLines("/scalar-single.yaml");
 
     Mapping res = .read(text);
 
     assertThat(res.getString("string"), equalTo("abc"));
     assertThat(res.getBoolean("boolean"), equalTo(true));
     assertThat(res.getInt("int"), equalTo(123));
     assertThat(res.getLong("long"), equalTo(9223372036854775807l));
     assertThat(res.getFloat("float"), equalTo(1.23f));
     assertThat(res.getDouble("double"), equalTo(4.56d));
 
     List<MappingseqScalar = res.getSequence("seq-scalar");
     assertThat(seqScalar.size(), equalTo(3));
   }
 
   public void scalar_many() {
     String text = EtcFiles.readLines("/scalar-many.yaml");
 
     List<Mappingres = .readAll(text);
 
     assertThat(res.size(), equalTo(2));
 
     Mapping r0 = res.get(0);
     assertThat(r0.getString("string"), equalTo("abc"));
     assertThat(r0.getBoolean("boolean"), equalTo(true));
     assertThat(r0.getInt("int"), equalTo(123));
     assertThat(r0.getLong("long"), equalTo(9223372036854775807l));
     assertThat(r0.getFloat("float"), equalTo(1.23f));
     assertThat(r0.getDouble("double"), equalTo(4.56d));
   }
 
   public void sequence_with_loader() {
     String text = EtcFiles.readLines("/sequence-with-loader.yaml");
 
     Mapping map = .read(text);
 
     assertThat(map.getString("prop0"), equalTo("whatever"));
     assertThat(map.getString("prop1"), equalTo("whatever"));
 
     List<Userres = map.loadSequence("users".);
     assertThat(res.size(), equalTo(3));
 
     List<Stringnames = transform(res.);
     assertThat(names.get(0), equalTo("userA"));
     assertThat(names.get(1), equalTo("userB"));
     assertThat(names.get(2), equalTo("userC"));
 
     List<Stringmail = transform(res.);
     assertThat(mail.get(0), equalTo("a@objectos.com.br"));
     assertThat(mail.get(1), equalTo("b@objectos.com.br"));
     assertThat(mail.get(2), equalTo("c@objectos.com.br"));
   }
 
   public void on_file_not_found_empty_mapping() {
     UUID uuid = UUID.randomUUID();
     String random = uuid.toString();
     File file = new File(random);
 
     Mapping res = .read(file);
 
     assertThat(res.getString("x"), equalTo(""));
     assertThat(res.getBoolean("x"), equalTo(false));
    assertThat(res.getInt("x"), equalTo(0));
    assertThat(res.getLong("x"), equalTo(0l));
    assertThat(res.getFloat("x"), equalTo(0f));
    assertThat(res.getDouble("x"), equalTo(0d));
  }
New to GrepCode? Check out our FAQ X