From 1f06eb4dceca711641d1930e02a3a8cae2f25258 Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Sat, 20 Nov 2021 09:42:57 -0500 Subject: [PATCH] Refactor some test fixtures. --- .../lang3/StringUtilsContainsTest.java | 26 ++-------- .../lang3/StringUtilsEqualsIndexOfTest.java | 13 ++--- .../apache/commons/lang3/Supplementary.java | 49 +++++++++++++++++++ 3 files changed, 56 insertions(+), 32 deletions(-) create mode 100644 src/test/java/org/apache/commons/lang3/Supplementary.java diff --git a/src/test/java/org/apache/commons/lang3/StringUtilsContainsTest.java b/src/test/java/org/apache/commons/lang3/StringUtilsContainsTest.java index 0f0237532..1d9f7241c 100644 --- a/src/test/java/org/apache/commons/lang3/StringUtilsContainsTest.java +++ b/src/test/java/org/apache/commons/lang3/StringUtilsContainsTest.java @@ -16,6 +16,10 @@ */ package org.apache.commons.lang3; +import static org.apache.commons.lang3.Supplementary.CharU20000; +import static org.apache.commons.lang3.Supplementary.CharU20001; +import static org.apache.commons.lang3.Supplementary.CharUSuppCharHigh; +import static org.apache.commons.lang3.Supplementary.CharUSuppCharLow; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -29,28 +33,6 @@ * Unit tests {@link org.apache.commons.lang3.StringUtils} - Contains methods */ public class StringUtilsContainsTest { - /** - * Supplementary character U+20000 - * See http://www.oracle.com/technetwork/articles/javase/supplementary-142654.html - */ - private static final String CharU20000 = "\uD840\uDC00"; - /** - * Supplementary character U+20001 - * See http://www.oracle.com/technetwork/articles/javase/supplementary-142654.html - */ - private static final String CharU20001 = "\uD840\uDC01"; - /** - * Incomplete supplementary character U+20000, high surrogate only. - * See http://www.oracle.com/technetwork/articles/javase/supplementary-142654.html - */ - private static final String CharUSuppCharHigh = "\uDC00"; - - /** - * Incomplete supplementary character U+20000, low surrogate only. - * See http://www.oracle.com/technetwork/articles/javase/supplementary-142654.html - */ - private static final String CharUSuppCharLow = "\uD840"; - @Test public void testContains_Char() { assertFalse(StringUtils.contains(null, ' ')); diff --git a/src/test/java/org/apache/commons/lang3/StringUtilsEqualsIndexOfTest.java b/src/test/java/org/apache/commons/lang3/StringUtilsEqualsIndexOfTest.java index 86f8702a7..51a7d45f3 100644 --- a/src/test/java/org/apache/commons/lang3/StringUtilsEqualsIndexOfTest.java +++ b/src/test/java/org/apache/commons/lang3/StringUtilsEqualsIndexOfTest.java @@ -16,6 +16,8 @@ */ package org.apache.commons.lang3; +import static org.apache.commons.lang3.Supplementary.CharU20000; +import static org.apache.commons.lang3.Supplementary.CharU20001; import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; @@ -31,17 +33,8 @@ * Unit tests {@link org.apache.commons.lang3.StringUtils} - Equals/IndexOf methods */ public class StringUtilsEqualsIndexOfTest { + private static final String BAR = "bar"; - /** - * Supplementary character U+20000 - * See http://www.oracle.com/technetwork/articles/javase/supplementary-142654.html - */ - private static final String CharU20000 = "\uD840\uDC00"; - /** - * Supplementary character U+20001 - * See http://www.oracle.com/technetwork/articles/javase/supplementary-142654.html - */ - private static final String CharU20001 = "\uD840\uDC01"; private static final String FOO = "foo"; diff --git a/src/test/java/org/apache/commons/lang3/Supplementary.java b/src/test/java/org/apache/commons/lang3/Supplementary.java new file mode 100644 index 000000000..97d41185f --- /dev/null +++ b/src/test/java/org/apache/commons/lang3/Supplementary.java @@ -0,0 +1,49 @@ +/* + * 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.commons.lang3; + +/** + * Supplementary character test fixtures. + * + * See http://www.oracle.com/technetwork/articles/javase/supplementary-142654.html + */ +public class Supplementary { + + /** + * Supplementary character U+20000 See http://www.oracle.com/technetwork/articles/javase/supplementary-142654.html + */ + static final String CharU20000 = "\uD840\uDC00"; + + /** + * Supplementary character U+20001 See http://www.oracle.com/technetwork/articles/javase/supplementary-142654.html + */ + static final String CharU20001 = "\uD840\uDC01"; + + /** + * Incomplete supplementary character U+20000, high surrogate only. See + * http://www.oracle.com/technetwork/articles/javase/supplementary-142654.html + */ + static final String CharUSuppCharHigh = "\uDC00"; + + /** + * Incomplete supplementary character U+20000, low surrogate only. See + * http://www.oracle.com/technetwork/articles/javase/supplementary-142654.html + */ + static final String CharUSuppCharLow = "\uD840"; + +}