|
Play Framework/Scala example source code file (OptionTest.java)
The OptionTest.java Play Framework example source code
/*
* Copyright (C) 2009-2013 Typesafe Inc. <http://www.typesafe.com>
*/
package play;
import org.junit.Test;
import play.libs.F;
import play.libs.F.Option;
import static org.fest.assertions.Assertions.assertThat;
// see http://docs.oracle.com/javase/7/docs/api/java/util/Collection.html#toArray(T[])
public class OptionTest {
@Test
public void testSomeToArray() {
F.Option<String> a = Option.Some("a");
assertThat(a.toArray()).isEqualTo(new Object[]{"a"});
assertThat(a.toArray(new String[]{})).isEqualTo(new String[]{"a"});
assertThat(a.toArray(new CharSequence[]{})).isEqualTo(new String[]{"a"});
String[] b = {null, "b", null , "c"};
assertThat(a.toArray(b)).isEqualTo(new String[]{"a", null, null, null});
}
@Test
public void testNoneToArray() {
F.Option<String> a = Option.<String>None();
assertThat(a.toArray()).isEqualTo(new Object[]{});
assertThat(a.toArray(new String[]{})).isEqualTo(new String[]{});
assertThat(a.toArray(new CharSequence[]{})).isEqualTo(new String[]{});
String[] b = {null, "b", null , "c"};
assertThat(a.toArray(b)).isEqualTo(new String[]{null, null, null, null});
}
@Test(expected=ArrayStoreException.class)
public void throwArrayStoreException() {
F.Option<String> a = Option.Some("a");
a.toArray(new Integer[]{});
}
}
Other Play Framework source code examplesHere is a short list of links related to this Play Framework OptionTest.java source code file: |
| ... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.