You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by ha...@apache.org on 2015/10/14 15:08:18 UTC
[2/4] incubator-brooklyn git commit: Not anonymous inner classes in
functions
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/f22b3eb4/utils/common/src/test/java/org/apache/brooklyn/util/guava/MaybeFunctionsTest.java
----------------------------------------------------------------------
diff --git a/utils/common/src/test/java/org/apache/brooklyn/util/guava/MaybeFunctionsTest.java b/utils/common/src/test/java/org/apache/brooklyn/util/guava/MaybeFunctionsTest.java
new file mode 100644
index 0000000..134978c
--- /dev/null
+++ b/utils/common/src/test/java/org/apache/brooklyn/util/guava/MaybeFunctionsTest.java
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.brooklyn.util.guava;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
+
+import org.testng.annotations.Test;
+
+public class MaybeFunctionsTest {
+
+ @Test
+ public void testWrap() throws Exception {
+ Maybe<Object> result = MaybeFunctions.wrap().apply("myval");
+ assertEquals(result.get(), "myval");
+
+ Maybe<Object> result2 = MaybeFunctions.wrap().apply(null);
+ assertFalse(result2.isPresent());
+ }
+
+ @Test
+ public void testGet() throws Exception {
+ assertEquals(MaybeFunctions.<String>get().apply(Maybe.of("myval")), "myval");
+ }
+
+ @Test
+ public void testOr() throws Exception {
+ assertEquals(MaybeFunctions.or("mydefault").apply(Maybe.of("myval")), "myval");
+ assertEquals(MaybeFunctions.or("mydefault").apply(Maybe.<String>absent()), "mydefault");
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/f22b3eb4/utils/common/src/test/java/org/apache/brooklyn/util/math/MathFunctionsTest.java
----------------------------------------------------------------------
diff --git a/utils/common/src/test/java/org/apache/brooklyn/util/math/MathFunctionsTest.java b/utils/common/src/test/java/org/apache/brooklyn/util/math/MathFunctionsTest.java
index 31ed402..a3daf7a 100644
--- a/utils/common/src/test/java/org/apache/brooklyn/util/math/MathFunctionsTest.java
+++ b/utils/common/src/test/java/org/apache/brooklyn/util/math/MathFunctionsTest.java
@@ -19,19 +19,31 @@
package org.apache.brooklyn.util.math;
import org.apache.brooklyn.test.FixedLocaleTest;
-import org.apache.brooklyn.util.math.MathFunctions;
import org.testng.Assert;
import org.testng.annotations.Test;
public class MathFunctionsTest extends FixedLocaleTest {
@Test
- public void testAdd() {
+ public void testPlus() {
Assert.assertEquals(MathFunctions.plus(3).apply(4), (Integer)7);
+ Assert.assertEquals(MathFunctions.plus(3L).apply(4L), (Long)7L);
Assert.assertEquals(MathFunctions.plus(0.3).apply(0.4).doubleValue(), 0.7, 0.00000001);
}
@Test
+ public void testTimes() {
+ Assert.assertEquals(MathFunctions.times(3).apply(4), (Integer)12);
+ Assert.assertEquals(MathFunctions.times(3L).apply(4L), (Long)12L);
+ Assert.assertEquals(MathFunctions.times(0.3).apply(0.4).doubleValue(), 0.12, 0.00000001);
+ }
+
+ @Test
+ public void testDivide() {
+ Assert.assertEquals(MathFunctions.divide(2.0).apply(8), 4.0, 0.00000001);
+ }
+
+ @Test
public void testReadableString() {
Assert.assertEquals(MathFunctions.readableString(3, 5).apply(0.0123456), "1.23E-2");
}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/f22b3eb4/utils/common/src/test/java/org/apache/brooklyn/util/text/StringFunctionsTest.java
----------------------------------------------------------------------
diff --git a/utils/common/src/test/java/org/apache/brooklyn/util/text/StringFunctionsTest.java b/utils/common/src/test/java/org/apache/brooklyn/util/text/StringFunctionsTest.java
index d00b6a2..808de9e 100644
--- a/utils/common/src/test/java/org/apache/brooklyn/util/text/StringFunctionsTest.java
+++ b/utils/common/src/test/java/org/apache/brooklyn/util/text/StringFunctionsTest.java
@@ -18,10 +18,12 @@
*/
package org.apache.brooklyn.util.text;
-import org.apache.brooklyn.util.text.StringFunctions;
import org.testng.Assert;
import org.testng.annotations.Test;
+import com.google.common.base.CaseFormat;
+import com.google.common.collect.ImmutableList;
+
public class StringFunctionsTest {
@Test
@@ -37,6 +39,19 @@ public class StringFunctionsTest {
@Test
public static void testFormatterForArray() {
Assert.assertEquals(StringFunctions.formatterForArray("Hello %s").apply(new Object[] { "World" }), "Hello World");
+ Assert.assertEquals(StringFunctions.formatterForArray("Hello").apply(new Object[0]), "Hello");
+ }
+
+ @Test
+ public static void testFormatterForArrayMulti() {
+ Assert.assertEquals(StringFunctions.formatterForArray("1 %s 2 %s").apply(new Object[] {"val1", "val2"}), "1 val1 2 val2");
+ }
+
+ @Test
+ public static void testFormatterForIterable() {
+ Assert.assertEquals(StringFunctions.formatterForIterable("Hello %s").apply(ImmutableList.of("World")), "Hello World");
+ Assert.assertEquals(StringFunctions.formatterForIterable("Hello").apply(ImmutableList.of()), "Hello");
+ Assert.assertEquals(StringFunctions.formatterForIterable("Hello").apply(null), "Hello");
}
@Test
@@ -54,4 +69,28 @@ public class StringFunctionsTest {
Assert.assertEquals(StringFunctions.toUpperCase().apply("Hello World"), "HELLO WORLD");
}
+ @Test
+ public static void testConvertCase() {
+ Assert.assertEquals(StringFunctions.convertCase(CaseFormat.UPPER_UNDERSCORE, CaseFormat.UPPER_CAMEL).apply("HELLO_WORLD"), "HelloWorld");
+ }
+
+ @Test
+ public static void testJoiner() {
+ Assert.assertEquals(StringFunctions.joiner(",").apply(ImmutableList.of("a", "b", "c")), "a,b,c");
+ }
+
+ @Test
+ public static void testJoinerForArray() {
+ Assert.assertEquals(StringFunctions.joinerForArray(",").apply(new Object[] {"a", "b", "c"}), "a,b,c");
+ }
+
+ @Test
+ public static void testLength() {
+ Assert.assertEquals(StringFunctions.length().apply("abc"), (Integer)3);
+ }
+
+ @Test
+ public static void testTrim() {
+ Assert.assertEquals(StringFunctions.trim().apply(" abc "), "abc");
+ }
}