diff --git a/bom/pom.xml b/bom/pom.xml index 1fdf394..a910530 100644 --- a/bom/pom.xml +++ b/bom/pom.xml @@ -77,6 +77,8 @@ ${guava.version} + + org.codehaus.groovy groovy diff --git a/common/src/test/java/org/sonatype/goodies/basicli/common/MoreStringsTest.groovy b/common/src/test/java/org/sonatype/goodies/basicli/common/MoreStringsTest.groovy deleted file mode 100644 index f309c54..0000000 --- a/common/src/test/java/org/sonatype/goodies/basicli/common/MoreStringsTest.groovy +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (c) 2022-present Sonatype, Inc. All rights reserved. - * - * This program is licensed to you under the Apache License Version 2.0, - * and you may not use this file except in compliance with the Apache License Version 2.0. - * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the Apache License Version 2.0 is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. - */ -package org.sonatype.goodies.basicli.common - -import org.junit.jupiter.api.Test - -/** - * {@link MoreStrings} tests. - */ -class MoreStringsTest -{ - @Test - void 'blankToNull'() { - assert MoreStrings.blankToNull(null) == null - assert MoreStrings.blankToNull('') == null - assert MoreStrings.blankToNull(' ') == null - assert MoreStrings.blankToNull('foo') != null - assert MoreStrings.blankToNull(' bar ') != null - - // ensure that result is the same as given when its non-null or blank - ' bar '.with { - assert MoreStrings.blankToNull(it) == it - } - } - - @Test - void 'lower'() { - def value = 'FooBar' - assert MoreStrings.lower(value) == 'foobar' - } - - @Test - void 'upper'() { - def value = 'FooBar' - assert MoreStrings.upper(value) == 'FOOBAR' - } - - @Test - void 'dquote string value'() { - assert MoreStrings.dquote('foo') == '"foo"' - } - - @Test - void 'dquote null value'() { - assert MoreStrings.dquote(null) == null - } -} \ No newline at end of file diff --git a/common/src/test/java/org/sonatype/goodies/basicli/common/MoreStringsTest.java b/common/src/test/java/org/sonatype/goodies/basicli/common/MoreStringsTest.java new file mode 100644 index 0000000..29e5b2e --- /dev/null +++ b/common/src/test/java/org/sonatype/goodies/basicli/common/MoreStringsTest.java @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2022-present Sonatype, Inc. All rights reserved. + * + * This program is licensed to you under the Apache License Version 2.0, + * and you may not use this file except in compliance with the Apache License Version 2.0. + * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the Apache License Version 2.0 is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. + */ +package org.sonatype.goodies.basicli.common; + +import org.junit.jupiter.api.Test; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.not; +import static org.hamcrest.Matchers.nullValue; + +/** + * {@link MoreStrings} tests. + */ +public class MoreStringsTest +{ + @Test + void blankToNull() { + assertThat(MoreStrings.blankToNull(null), nullValue()); + assertThat(MoreStrings.blankToNull(""), nullValue()); + assertThat(MoreStrings.blankToNull(" "), nullValue()); + assertThat(MoreStrings.blankToNull("foo"), not(nullValue())); + assertThat(MoreStrings.blankToNull(" bar "), not(nullValue())); + + // ensure that result is the same as given when its non-null or blank + String text = " bar "; + assertThat(MoreStrings.blankToNull(text), is(text)); + } + + @Test + void lower() { + String value = "FooBar"; + assertThat(MoreStrings.lower(value), is("foobar")); + } + + @Test + void upper() { + String value = "FooBar"; + assertThat(MoreStrings.upper(value), is("FOOBAR")); + } + + @Test + void dquote_string_value() { + assertThat(MoreStrings.dquote("foo"), is("\"foo\"")); + } + + @Test + void dquote_null_value() { + assertThat(MoreStrings.dquote(null), nullValue()); + } +} \ No newline at end of file diff --git a/common/src/test/java/org/sonatype/goodies/basicli/common/ThrowableHelperTest.groovy b/common/src/test/java/org/sonatype/goodies/basicli/common/ThrowableHelperTest.groovy deleted file mode 100644 index 8d7a9e8..0000000 --- a/common/src/test/java/org/sonatype/goodies/basicli/common/ThrowableHelperTest.groovy +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Copyright (c) 2022-present Sonatype, Inc. All rights reserved. - * - * This program is licensed to you under the Apache License Version 2.0, - * and you may not use this file except in compliance with the Apache License Version 2.0. - * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the Apache License Version 2.0 is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. - */ -package org.sonatype.goodies.basicli.common - -import org.junit.jupiter.api.Test - -import static org.hamcrest.MatcherAssert.assertThat -import static org.hamcrest.Matchers.arrayWithSize -import static org.hamcrest.Matchers.is - -// copied and adjusted from: https://raw.githubusercontent.com/sonatype/goodies/master/common/src/test/java/org/sonatype/goodies/common/Throwables2Test.java - -/** - * {@link ThrowableHelper} tests. - */ -class ThrowableHelperTest -{ - @Test - void 'explain single throwable'() { - String msg = ThrowableHelper.explain(new RuntimeException('foo')) - println(msg) - assertThat(msg, is('java.lang.RuntimeException: foo')) - } - - @Test - void 'explain nested throwable'() { - String msg = ThrowableHelper.explain( - new RuntimeException('foo', - new Exception('bar') - ) - ) - println(msg) - assertThat(msg, is('java.lang.RuntimeException: foo, caused by: java.lang.Exception: bar')) - } - - @Test - void 'explain nested 3x throwable'() { - String msg = ThrowableHelper.explain( - new RuntimeException('foo', - new Exception( - new Exception('bar') - ) - ) - ) - println(msg) - assertThat(msg, is('java.lang.RuntimeException: foo, caused by: java.lang.Exception, caused by: java.lang.Exception: bar')) - } - - @Test - void 'explain nested 4x throwable'() { - String msg = ThrowableHelper.explain( - new RuntimeException('foo', - new Exception('bar', - new Exception('baz') - ) - ) - ) - println(msg) - assertThat(msg, is('java.lang.RuntimeException: foo, caused by: java.lang.Exception: bar, caused by: java.lang.Exception: baz')) - } - - @Test - void 'composite adds suppressed exceptions'() { - Throwable foo = new Exception('foo') - Throwable bar = new Exception('bar') - try { - throw ThrowableHelper.composite(new Exception('test'), foo, bar) - } - catch (Exception e) { - assertThat(e.getSuppressed(), arrayWithSize(2)) - assertThat(e.getSuppressed()[0], is(foo)) - assertThat(e.getSuppressed()[1], is(bar)) - } - } - - @Test - void 'explain composite'() { - try { - ThrowableHelper.composite( - new Exception('test'), - new Exception('foo'), - new Exception('bar') - ) - } - catch (e) { - def msg = ThrowableHelper.explain(e) - println msg - assert msg == 'java.lang.Exception: test, suppressed: java.lang.Exception: foo, suppressed: java.lang.Exception: bar' - } - } -} \ No newline at end of file diff --git a/common/src/test/java/org/sonatype/goodies/basicli/common/ThrowableHelperTest.java b/common/src/test/java/org/sonatype/goodies/basicli/common/ThrowableHelperTest.java new file mode 100644 index 0000000..cfca175 --- /dev/null +++ b/common/src/test/java/org/sonatype/goodies/basicli/common/ThrowableHelperTest.java @@ -0,0 +1,105 @@ +/* + * Copyright (c) 2022-present Sonatype, Inc. All rights reserved. + * + * This program is licensed to you under the Apache License Version 2.0, + * and you may not use this file except in compliance with the Apache License Version 2.0. + * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the Apache License Version 2.0 is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. + */ +package org.sonatype.goodies.basicli.common; + +import org.junit.jupiter.api.Test; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.arrayWithSize; +import static org.hamcrest.Matchers.is; + +// copied and adjusted from: https://raw.githubusercontent.com/sonatype/goodies/master/common/src/test/java/org/sonatype/goodies/common/Throwables2Test.java + +/** + * {@link ThrowableHelper} tests. + */ +public class ThrowableHelperTest +{ + private static void println(Object value) { + System.out.println(value); + } + + @Test + public void explain_single_throwable() { + String msg = ThrowableHelper.explain(new RuntimeException("foo")); + println(msg); + assertThat(msg, is("java.lang.RuntimeException: foo")); + } + + @Test + public void explain_nested_throwable() { + String msg = ThrowableHelper.explain( + new RuntimeException("foo", + new Exception("bar") + ) + ); + println(msg); + assertThat(msg, is("java.lang.RuntimeException: foo, caused by: java.lang.Exception: bar")); + } + + @Test + public void explain_nested_3x_throwable() { + String msg = ThrowableHelper.explain( + new RuntimeException("foo", + new Exception( + new Exception("bar") + ) + ) + ); + println(msg); + assertThat(msg, is("java.lang.RuntimeException: foo, caused by: java.lang.Exception, caused by: java.lang.Exception: bar")); + } + + @Test + public void explain_nested_4x_throwable() { + String msg = ThrowableHelper.explain( + new RuntimeException("foo", + new Exception("bar", + new Exception("baz") + ) + ) + ); + println(msg); + assertThat(msg, is("java.lang.RuntimeException: foo, caused by: java.lang.Exception: bar, caused by: java.lang.Exception: baz")); + } + + @Test + public void composite_adds_suppressed_exceptions() { + Throwable foo = new Exception("foo"); + Throwable bar = new Exception("bar"); + try { + throw ThrowableHelper.composite(new Exception("test"), foo, bar); + } + catch (Exception e) { + assertThat(e.getSuppressed(), arrayWithSize(2)); + assertThat(e.getSuppressed()[0], is(foo)); + assertThat(e.getSuppressed()[1], is(bar)); + } + } + + @Test + public void explain_composite() { + try { + ThrowableHelper.composite( + new Exception("test"), + new Exception("foo"), + new Exception("bar") + ); + } + catch (Exception e) { + String msg = ThrowableHelper.explain(e); + println(msg); + assertThat(msg, is("java.lang.Exception: test, suppressed: java.lang.Exception: foo, suppressed: java.lang.Exception: bar")); + } + } +} \ No newline at end of file diff --git a/pom.xml b/pom.xml index da3baf9..5b8f1c5 100644 --- a/pom.xml +++ b/pom.xml @@ -115,27 +115,6 @@ - - org.apache.maven.plugins - maven-compiler-plugin - - - org.codehaus.groovy - groovy-eclipse-compiler - 3.7.0 - - - org.codehaus.groovy - groovy-eclipse-batch - 3.0.8-01 - - - - - groovy-eclipse-compiler - - - com.sonatype.clm clm-maven-plugin diff --git a/testbase/pom.xml b/testbase/pom.xml index 19c8802..4eb9ebb 100644 --- a/testbase/pom.xml +++ b/testbase/pom.xml @@ -65,6 +65,8 @@ logback-classic + + org.codehaus.groovy groovy