-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Unit tests without gradle version change
- Loading branch information
Showing
2 changed files
with
57 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
DAIRemoteApp/app/src/test/java/com/example/dairemote_app/SocketManagerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package com.example.dairemote_app; | ||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.net.DatagramPacket; | ||
import java.net.DatagramSocket; | ||
import java.net.InetAddress; | ||
import java.net.UnknownHostException; | ||
class SocketManagerTest { | ||
|
||
SocketManager socketManager; | ||
DatagramPacket packet; | ||
|
||
@BeforeEach | ||
void setUp() throws UnknownHostException { | ||
socketManager = new SocketManager(InetAddress.getByName("127.0.0.1"), 9999); | ||
} | ||
@Test | ||
void testSetSocket() { | ||
socketManager.SetSocket(); | ||
assertNotNull(socketManager.GetSocket(), "Socket should be created"); | ||
} | ||
|
||
@Test | ||
void testGetSocket() { | ||
DatagramSocket socket = socketManager.GetSocket(); | ||
assertNotNull(socket, "Socket should not be null"); | ||
} | ||
|
||
@Test | ||
void closeSocket() { | ||
socketManager.CloseSocket(); | ||
assertTrue(socketManager.socket.isClosed(), "Testing SocketManager CloseSocket(), expecting null"); | ||
} | ||
|
||
@Test | ||
void testGetData() { | ||
assertNotNull(socketManager.GetData(), "Data array should not be null"); | ||
} | ||
|
||
@Test | ||
void testSetPacket() { | ||
byte[] data = new byte[100]; | ||
DatagramPacket packet = new DatagramPacket(data, data.length); | ||
socketManager.SetPacket(packet); | ||
assertSame(packet, socketManager.GetPacket(), "Packet should be set correctly"); | ||
} | ||
|
||
@Test | ||
void testGetPacket() { | ||
DatagramPacket packet = socketManager.GetPacket(); | ||
assertNotNull(packet, "Packet should not be null"); | ||
} | ||
} |