This is an automated email from the ASF dual-hosted git repository.
voidmatcha pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/zeppelin.git
The following commit(s) were added to refs/heads/master by this push:
new 8c46e755a6 [ZEPPELIN-6485] Add unit tests for PropertiesUtil
8c46e755a6 is described below
commit 8c46e755a6ec5bf7eaa2922114492efd1db98a31
Author: Chaiwon Hwang <[email protected]>
AuthorDate: Sat Sep 26 00:49:58 2026 +0900
[ZEPPELIN-6485] Add unit tests for PropertiesUtil
### What is this PR for?
This PR adds unit tests for `PropertiesUtil` in the `zeppelin-interpreter`
module.
The tests cover the behavior of `getString`, `getLong`, and `getInt`,
including missing properties, empty and whitespace-only values, successful
numeric parsing, parsing failures, and numeric boundary values.
No production code is changed.
### What type of PR is it?
Improvement
### Todos
- [x] Add tests for missing properties
- [x] Add tests for empty and whitespace-only values
- [x] Add tests for valid positive and negative numeric values
- [x] Add tests for numeric boundary values
- [x] Add tests for invalid and out-of-range numeric values
### What is the Jira issue?
https://issues.apache.org/jira/browse/ZEPPELIN-6485
### How should this be tested?
Run the new unit tests:
```bash
./mvnw test -pl zeppelin-interpreter -Dtest=PropertiesUtilTest
```
Expected result:
```text
Tests run: 6, Failures: 0, Errors: 0, Skipped: 0
BUILD SUCCESS
```
### Screenshots (if appropriate)
This PR does not change the user interface.
### Questions:
- Does the license files need to update? No.
- Is there breaking changes for older versions? No.
- Does this needs documentation? No.
Closes #5493 from uommou/fix/ZEPPELIN-6485.
Signed-off-by: YONGJAE LEE <[email protected]>
---
.../apache/zeppelin/util/PropertiesUtilTest.java | 115 +++++++++++++++++++++
1 file changed, 115 insertions(+)
diff --git
a/zeppelin-interpreter/src/test/java/org/apache/zeppelin/util/PropertiesUtilTest.java
b/zeppelin-interpreter/src/test/java/org/apache/zeppelin/util/PropertiesUtilTest.java
new file mode 100644
index 0000000000..e0a48a4a1c
--- /dev/null
+++
b/zeppelin-interpreter/src/test/java/org/apache/zeppelin/util/PropertiesUtilTest.java
@@ -0,0 +1,115 @@
+/*
+ * 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.zeppelin.util;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import java.util.Properties;
+
+import org.junit.jupiter.api.Test;
+
+class PropertiesUtilTest {
+
+ private static final String KEY = "property";
+
+ @Test
+ void missingPropertyReturnsDefault() {
+ Properties properties = new Properties();
+
+ assertEquals("default", PropertiesUtil.getString(properties, KEY,
"default"));
+ assertEquals(42L, PropertiesUtil.getLong(properties, KEY, 42L));
+ assertEquals(42, PropertiesUtil.getInt(properties, KEY, 42));
+ }
+
+ @Test
+ void getStringReturnsEmptyAndWhitespaceValuesUnchanged() {
+ Properties properties = new Properties();
+
+ properties.setProperty(KEY, "");
+ assertEquals("", PropertiesUtil.getString(properties, KEY, "default"));
+
+ properties.setProperty(KEY, " ");
+ assertEquals(" ", PropertiesUtil.getString(properties, KEY, "default"));
+ }
+
+ @Test
+ void getLongParsesValidValues() {
+ Properties properties = new Properties();
+
+ properties.setProperty(KEY, "42");
+ assertEquals(42L, PropertiesUtil.getLong(properties, KEY, 0L));
+
+ properties.setProperty(KEY, "-42");
+ assertEquals(-42L, PropertiesUtil.getLong(properties, KEY, 0L));
+
+ properties.setProperty(KEY, Long.toString(Long.MAX_VALUE));
+ assertEquals(Long.MAX_VALUE, PropertiesUtil.getLong(properties, KEY, 0L));
+
+ properties.setProperty(KEY, Long.toString(Long.MIN_VALUE));
+ assertEquals(Long.MIN_VALUE, PropertiesUtil.getLong(properties, KEY, 0L));
+ }
+
+ @Test
+ void getLongReturnsDefaultForUnparseableValues() {
+ Properties properties = new Properties();
+
+ properties.setProperty(KEY, "");
+ assertEquals(42L, PropertiesUtil.getLong(properties, KEY, 42L));
+
+ properties.setProperty(KEY, "not-a-long");
+ assertEquals(42L, PropertiesUtil.getLong(properties, KEY, 42L));
+
+ properties.setProperty(KEY, " 42 ");
+ assertEquals(42L, PropertiesUtil.getLong(properties, KEY, 42L));
+ }
+
+ @Test
+ void getIntParsesValidValues() {
+ Properties properties = new Properties();
+
+ properties.setProperty(KEY, "42");
+ assertEquals(42, PropertiesUtil.getInt(properties, KEY, 0));
+
+ properties.setProperty(KEY, "-42");
+ assertEquals(-42, PropertiesUtil.getInt(properties, KEY, 0));
+
+ properties.setProperty(KEY, Integer.toString(Integer.MAX_VALUE));
+ assertEquals(Integer.MAX_VALUE, PropertiesUtil.getInt(properties, KEY, 0));
+
+ properties.setProperty(KEY, Integer.toString(Integer.MIN_VALUE));
+ assertEquals(Integer.MIN_VALUE, PropertiesUtil.getInt(properties, KEY, 0));
+ }
+
+ @Test
+ void getIntReturnsDefaultForUnparseableValues() {
+ Properties properties = new Properties();
+
+ properties.setProperty(KEY, "");
+ assertEquals(42, PropertiesUtil.getInt(properties, KEY, 42));
+
+ properties.setProperty(KEY, "not-an-int");
+ assertEquals(42, PropertiesUtil.getInt(properties, KEY, 42));
+
+ properties.setProperty(KEY, Long.toString((long) Integer.MAX_VALUE + 1));
+ assertEquals(42, PropertiesUtil.getInt(properties, KEY, 42));
+
+ properties.setProperty(KEY, " 42 ");
+ assertEquals(42, PropertiesUtil.getInt(properties, KEY, 42));
+ }
+}