This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-net.git

commit 5403a868cab27c6844e33ff58daa8859f7f53ad4
Author: Gary Gregory <garydgreg...@gmail.com>
AuthorDate: Tue May 28 08:51:58 2024 -0400

    Add teste
---
 .../org/apache/commons/net/time/TimeUDPClient.java | 17 ++++++-----
 .../apache/commons/net/time/TimeUDPClientTest.java | 33 ++++++++++++++++++++++
 2 files changed, 43 insertions(+), 7 deletions(-)

diff --git a/src/main/java/org/apache/commons/net/time/TimeUDPClient.java 
b/src/main/java/org/apache/commons/net/time/TimeUDPClient.java
index d3888170..28c4ed2d 100644
--- a/src/main/java/org/apache/commons/net/time/TimeUDPClient.java
+++ b/src/main/java/org/apache/commons/net/time/TimeUDPClient.java
@@ -45,6 +45,15 @@ public final class TimeUDPClient extends 
DatagramSocketClient {
      */
     public static final long SECONDS_1900_TO_1970 = 2208988800L;
 
+    static long toTime(final byte[] timeData) {
+        long time = 0L;
+        time |= (timeData[0] & 0xff) << 24 & 0xffffffffL;
+        time |= (timeData[1] & 0xff) << 16 & 0xffffffffL;
+        time |= (timeData[2] & 0xff) << 8 & 0xffffffffL;
+        time |= timeData[3] & 0xff & 0xffffffffL;
+        return time;
+    }
+
     /**
      * Same as <code>getTime(host, DEFAULT_PORT);</code>
      *
@@ -98,13 +107,7 @@ public final class TimeUDPClient extends 
DatagramSocketClient {
         checkOpen().send(sendPacket);
         checkOpen().receive(receivePacket);
 
-        long time = 0L;
-        time |= (timeData[0] & 0xff) << 24 & 0xffffffffL;
-        time |= (timeData[1] & 0xff) << 16 & 0xffffffffL;
-        time |= (timeData[2] & 0xff) << 8 & 0xffffffffL;
-        time |= timeData[3] & 0xff & 0xffffffffL;
-
-        return time;
+        return toTime(timeData);
     }
 
 }
diff --git a/src/test/java/org/apache/commons/net/time/TimeUDPClientTest.java 
b/src/test/java/org/apache/commons/net/time/TimeUDPClientTest.java
new file mode 100644
index 00000000..681f54a8
--- /dev/null
+++ b/src/test/java/org/apache/commons/net/time/TimeUDPClientTest.java
@@ -0,0 +1,33 @@
+/*
+ * 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.net.time;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Tests {@link TimeUDPClient}.
+ */
+public class TimeUDPClientTest {
+
+    @Test
+    public void test() {
+        final byte[] timeData = new byte[4];
+        assertEquals(0, TimeUDPClient.toTime(timeData));
+    }
+}

Reply via email to