name:
src/test/java/io/protobase/f7/formulas/info/ISERRORTest.java
-rw-r--r--
2699
1package io.protobase.f7.formulas.info;
2
3import io.protobase.f7.errors.DivException;
4import io.protobase.f7.errors.NAException;
5import io.protobase.f7.errors.NameException;
6import io.protobase.f7.errors.NullException;
7import io.protobase.f7.errors.NumException;
8import io.protobase.f7.errors.ParseException;
9import io.protobase.f7.errors.RefException;
10import io.protobase.f7.errors.ValueException;
11import io.protobase.f7.models.Grid;
12import io.protobase.f7.testutils.TestFormula;
13import org.junit.Test;
14
15import static com.google.common.truth.Truth.assertThat;
16import static org.mockito.Mockito.verify;
17import static org.mockito.Mockito.when;
18
19public class ISERRORTest extends TestFormula {
20 @Test
21 public void test_number() {
22 assertThat(ISERROR.SELF.apply(null, 10.0)).isEqualTo(false);
23 }
24
25 @Test
26 public void test_string() {
27 assertThat(ISERROR.SELF.apply(null, "String")).isEqualTo(false);
28 }
29
30 @Test
31 public void test_boolean() {
32 assertThat(ISERROR.SELF.apply(null, true)).isEqualTo(false);
33 assertThat(ISERROR.SELF.apply(null, false)).isEqualTo(false);
34 }
35
36 @Test
37 public void test_error() {
38 assertThat(ISERROR.SELF.apply(null, new NullException())).isEqualTo(true);
39 assertThat(ISERROR.SELF.apply(null, new DivException())).isEqualTo(true);
40 assertThat(ISERROR.SELF.apply(null, new ValueException())).isEqualTo(true);
41 assertThat(ISERROR.SELF.apply(null, new RefException())).isEqualTo(true);
42 assertThat(ISERROR.SELF.apply(null, new NameException())).isEqualTo(true);
43 assertThat(ISERROR.SELF.apply(null, new NumException())).isEqualTo(true);
44 assertThat(ISERROR.SELF.apply(null, new NAException())).isEqualTo(true);
45 assertThat(ISERROR.SELF.apply(null, new ParseException())).isEqualTo(true);
46 }
47
48 @Test
49 public void test_lookup() {
50 ISERROR F = new ISERROR(lookup, collateralLookup);
51 when(collateralLookup.apply(A1, M22_RANGE)).thenReturn(new DivException());
52 assertThat(F.apply(A1, M22_RANGE)).isEqualTo(true);
53 verify(collateralLookup).apply(A1, M22_RANGE);
54 }
55
56 @Test
57 public void test_grid() {
58 assertThat(ISERROR.SELF.apply(null, Grid.builder().add(0, 0, "Still no.").build())).isEqualTo(false);
59 assertThat(ISERROR.SELF.apply(null, Grid.builder().add(0, 0, new NAException()).build())).isEqualTo(true);
60 assertThat(ISERROR.SELF.apply(null, Grid.builder()
61 .add(0, 0, new NAException())
62 .add(0, 1, "Previous one is, this isn't.")
63 .build())).isEqualTo(true);
64 }
65
66 @Test
67 public void testApply_errorFromArgumentsMismatch() {
68 assertThat(ISERROR.SELF.apply(null)).isEqualTo(new NAException());
69 assertThat(ISERROR.SELF.apply(null, "A", "B")).isEqualTo(new NAException());
70 }
71}