Open
Description
Description
Unused import of java.net.UnknownHostException
To Reproduce
- Run the 'utbot' project in IntelliJ Idea 2022.2.4 Ultimate
- Install plugin built from unit-test-bot/rc3102023 branch
- Set Fuzzing 100% in Settings -> Tools -> UnitTestBot
- Generate tests for the following code:
public class SecurityCheck {
public int connect(Socket socket) throws IOException {
socket.connect(new InetSocketAddress("0.0.0.0", 22));
return 0;
}
}
Expected behavior
There should be no unused imports.
Actual behavior
There is import java.net.UnknownHostException that is not used in test code.
Visual proofs (screenshots, logs, images)
The following test is generated by Fuzzing:
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.DisplayName;
import java.net.Socket;
import java.net.UnknownHostException;
import java.io.IOException;
public final class SecurityCheckTest {
///region Test suites for executable SecurityCheck.connect
///region FUZZER: SECURITY for method connect(java.net.Socket)
/**
* @utbot.classUnderTest {@link SecurityCheck}
* @utbot.methodUnderTest {@link SecurityCheck#connect(Socket)}
*/
@Test
@DisplayName("connect: socket = Socket()")
@org.junit.jupiter.api.Disabled(value = "Disabled due to sandbox")
public void testConnect() {
SecurityCheck securityCheck = new SecurityCheck();
Socket socket = new Socket();
/* This test fails because method [SecurityCheck.connect] produces [java.security.AccessControlException: access denied ("java.net.SocketPermission" "0.0.0.0:22" "connect,resolve")]
java.security.AccessControlContext.checkPermission(AccessControlContext.java:472)
java.security.AccessController.checkPermission(AccessController.java:886)
java.lang.SecurityManager.checkPermission(SecurityManager.java:549)
java.lang.SecurityManager.checkConnect(SecurityManager.java:1051)
java.net.Socket.connect(Socket.java:608)
java.net.Socket.connect(Socket.java:561)
SecurityCheck.connect(SecurityCheck.java:22) */
}
/**
* @utbot.classUnderTest {@link SecurityCheck}
* @utbot.methodUnderTest {@link SecurityCheck#connect(Socket)}
*/
@Test
@DisplayName("connect: socket = Socket(String, int)")
@org.junit.jupiter.api.Disabled(value = "Disabled due to sandbox")
public void testConnect1() throws IOException {
SecurityCheck securityCheck = new SecurityCheck();
Socket socket = new Socket("abc", Integer.MIN_VALUE);
/* This test fails because method [SecurityCheck.connect] produces [java.security.AccessControlException: access denied ("java.net.SocketPermission" "abc" "resolve")] */
}
/**
* @utbot.classUnderTest {@link SecurityCheck}
* @utbot.methodUnderTest {@link SecurityCheck#connect(Socket)}
*/
@Test
@DisplayName("connect: socket = Socket(String, int, boolean)")
@org.junit.jupiter.api.Disabled(value = "Disabled due to sandbox")
public void testConnect2() throws IOException {
SecurityCheck securityCheck = new SecurityCheck();
Socket socket = new Socket("", 0, true);
/* This test fails because method [SecurityCheck.connect] produces [java.security.AccessControlException: access denied ("java.net.SocketPermission" "127.0.0.1:0" "connect,resolve")] */
}
/**
* @utbot.classUnderTest {@link SecurityCheck}
* @utbot.methodUnderTest {@link SecurityCheck#connect(Socket)}
*/
@Test
@DisplayName("connect: socket = Socket(String, int, boolean)")
@org.junit.jupiter.api.Disabled(value = "Disabled due to sandbox")
public void testConnect3() throws IOException {
SecurityCheck securityCheck = new SecurityCheck();
Socket socket = new Socket("\u0086", 0, true);
/* This test fails because method [SecurityCheck.connect] produces [java.security.AccessControlException: access denied ("java.net.SocketPermission" "�" "resolve")] */
}
/**
* @utbot.classUnderTest {@link SecurityCheck}
* @utbot.methodUnderTest {@link SecurityCheck#connect(Socket)}
*/
@Test
@DisplayName("connect: socket = Socket(String, int, boolean)")
@org.junit.jupiter.api.Disabled(value = "Disabled due to sandbox")
public void testConnect4() throws IOException {
SecurityCheck securityCheck = new SecurityCheck();
Socket socket = new Socket("\u0086", Integer.MIN_VALUE, true);
/* This test fails because method [SecurityCheck.connect] produces [java.security.AccessControlException: access denied ("java.net.SocketPermission" "�" "resolve")] */
}
/**
* @utbot.classUnderTest {@link SecurityCheck}
* @utbot.methodUnderTest {@link SecurityCheck#connect(Socket)}
*/
@Test
@DisplayName("connect: socket = Socket(String, int, boolean)")
@org.junit.jupiter.api.Disabled(value = "Disabled due to sandbox")
public void testConnect5() throws IOException {
SecurityCheck securityCheck = new SecurityCheck();
Socket socket = new Socket("0.0.0.0", 0, false);
/* This test fails because method [SecurityCheck.connect] produces [java.security.AccessControlException: access denied ("java.net.SocketPermission" "0.0.0.0:0" "connect,resolve")] */
}
/**
* @utbot.classUnderTest {@link SecurityCheck}
* @utbot.methodUnderTest {@link SecurityCheck#connect(Socket)}
*/
@Test
@DisplayName("connect: socket = Socket(String, int)")
@org.junit.jupiter.api.Disabled(value = "Disabled due to sandbox")
public void testConnect6() throws IOException {
SecurityCheck securityCheck = new SecurityCheck();
Socket socket = new Socket("abc", 0);
/* This test fails because method [SecurityCheck.connect] produces [java.security.AccessControlException: access denied ("java.net.SocketPermission" "abc" "resolve")] */
}
/**
* @utbot.classUnderTest {@link SecurityCheck}
* @utbot.methodUnderTest {@link SecurityCheck#connect(Socket)}
*/
@Test
@DisplayName("connect: socket = Socket(String, int)")
@org.junit.jupiter.api.Disabled(value = "Disabled due to sandbox")
public void testConnect7() throws IOException {
SecurityCheck securityCheck = new SecurityCheck();
Socket socket = new Socket("", 0);
/* This test fails because method [SecurityCheck.connect] produces [java.security.AccessControlException: access denied ("java.net.SocketPermission" "127.0.0.1:0" "connect,resolve")] */
}
/**
* @utbot.classUnderTest {@link SecurityCheck}
* @utbot.methodUnderTest {@link SecurityCheck#connect(Socket)}
*/
@Test
@DisplayName("connect: socket = Socket(String, int)")
@org.junit.jupiter.api.Disabled(value = "Disabled due to sandbox")
public void testConnect8() throws IOException {
SecurityCheck securityCheck = new SecurityCheck();
Socket socket = new Socket(":", 0);
/* This test fails because method [SecurityCheck.connect] produces [java.security.AccessControlException: access denied ("java.net.SocketPermission" "[:]:0" "connect,resolve")] */
}
///endregion
///region Errors report for connect
public void testConnect_errors() {
// Couldn't generate some tests. List of errors:
//
// 6099 occurrences of:
// Default concrete execution failed
}
///endregion
///endregion
}
Environment
Windows 10 Pro
IntelliJ IDEA 2022.2.4 Ultimate
Originally posted by @alisevych in #1314 (comment)
Metadata
Metadata
Assignees
Type
Projects
Status
Todo