name:
src/test/java/io/protobase/f7/formulas/text/CONCATENATETest.java
-rw-r--r--
2362
1package io.protobase.f7.formulas.text;
2
3import io.protobase.f7.errors.NAException;
4import io.protobase.f7.errors.ValueException;
5import io.protobase.f7.models.Grid;
6import io.protobase.f7.testutils.TestFormula;
7import org.junit.Test;
8
9import static com.google.common.truth.Truth.assertThat;
10import static org.mockito.Mockito.verify;
11import static org.mockito.Mockito.verifyNoMoreInteractions;
12import static org.mockito.Mockito.when;
13
14public class CONCATENATETest extends TestFormula {
15 @Test
16 public void testApply() {
17 assertThat(CONCATENATE.SELF.apply(null, 10.0, 10.0)).isEqualTo("1010");
18 assertThat(CONCATENATE.SELF.apply(null, "One", "Two")).isEqualTo("OneTwo");
19 assertThat(CONCATENATE.SELF.apply(null, 44182.1, "Two")).isEqualTo("44182.1Two");
20 assertThat(CONCATENATE.SELF.apply(null, true, false)).isEqualTo("TRUEFALSE");
21 assertThat(CONCATENATE.SELF.apply(null, "", "")).isEqualTo("");
22 assertThat(CONCATENATE.SELF.apply(null, "a", "b", true, "c", 10.1, "d", 11.1111)).isEqualTo("abTRUEc10.1d11.1111");
23 }
24
25 @Test
26 public void testApply_grid() {
27 assertThat(CONCATENATE.SELF.apply(null,
28 Grid.builder().add(0, 0, "Hello").add(0, 1, "One").build(),
29 Grid.builder().add(0, 0, "There").add(0, 1, "Two").build()
30 )).isEqualTo("HelloOneThereTwo");
31 assertThat(CONCATENATE.SELF.apply(null,
32 Grid.builder().add(0, 0, "Hello").build(),
33 Grid.builder().add(0, 0, "There").build()
34 )).isEqualTo("HelloThere");
35 }
36
37 @Test
38 public void test_lookup() {
39 Grid grid = Grid.builder()
40 .add(0, 0, 1.0)
41 .add(0, 1, 2.0)
42 .add(0, 2, 3.0)
43 .add(0, 3, 4.0)
44 .add(0, 4, 5.0)
45 .build();
46 CONCATENATE F = new CONCATENATE(lookup, collateralLookup);
47 when(lookup.apply(D1_TO_D5_RANGE)).thenReturn(grid);
48 assertThat(F.apply(A1, D1_TO_D5_RANGE)).isEqualTo("12345");
49 verify(lookup).apply(D1_TO_D5_RANGE);
50 verifyNoMoreInteractions(lookup);
51 }
52
53 @Test
54 public void testApply_errorsPassThrough() {
55 assertThat(CONCATENATE.SELF.apply(null, "One", new ValueException())).isEqualTo(new ValueException());
56 assertThat(CONCATENATE.SELF.apply(null, new ValueException(), "Two")).isEqualTo(new ValueException());
57 }
58
59 @Test
60 public void testApply_argumentsMismatch() {
61 assertThat(CONCATENATE.SELF.apply(null)).isEqualTo(new NAException());
62 }
63}