Last active
December 21, 2015 23:48
-
-
Save renanreismartins/6384507 to your computer and use it in GitHub Desktop.
Criando objetos com Some e None.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Before | |
public void setup() { | |
names = new ArrayList<Option<String>>(); | |
names.add(new Some<String>("Renan")); | |
names.add(new None<String>()); | |
names.add(new Some<String>("Paulo")); | |
} | |
@Test | |
public void usandoGetOrElse() { | |
String[] expected = { "Renan", "Valor alternativo!", "Paulo"}; | |
System.out.println("*** Usando getOrElse:"); | |
for (int i = 0; i < names.size(); i++) { | |
Option<String> option = names.get(i); | |
String value = option.getOrElse("Valor alternativo!"); | |
System.out.println(option + " = " + value); | |
assertEquals(expected[i], option); | |
} | |
} | |
// Saída: | |
// Some(Renan) = Renan | |
// None(Valor alternativo) = Valor alternativo | |
// Some(Paulo) = Paulo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment