You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
53 lines
2.2 KiB
53 lines
2.2 KiB
/**
|
|
* Test class for Config builder pattern implementation
|
|
*/
|
|
public class ConfigTest {
|
|
|
|
/**
|
|
* Main method to run tests
|
|
* @param args Command line arguments
|
|
*/
|
|
public static void main(String[] args){
|
|
// Test 1: Using default parameters
|
|
System.out.println("Test 1: Using default parameters");
|
|
Config config1 = new Config.ConfigBuilder("http://example.com")
|
|
.build();
|
|
System.out.println("URL: " + config1.getUrl());
|
|
System.out.println("Encoding: " + config1.getEncoding());
|
|
System.out.println("Max Connections: " + config1.getMaxConnections());
|
|
System.out.println("Timeout: " + config1.getTimeout());
|
|
System.out.println();
|
|
|
|
// Test 2: Customizing all optional parameters
|
|
System.out.println("Test 2: Customizing all optional parameters");
|
|
Config config2 = new Config.ConfigBuilder("http://test.com")
|
|
.setEncoding("GBK")
|
|
.setMaxConnections(50)
|
|
.setTimeout(5000)
|
|
.build();
|
|
System.out.println("URL: " + config2.getUrl());
|
|
System.out.println("Encoding: " + config2.getEncoding());
|
|
System.out.println("Max Connections: " + config2.getMaxConnections());
|
|
System.out.println("Timeout: " + config2.getTimeout());
|
|
System.out.println();
|
|
|
|
// Test 3: Validating parameter checks
|
|
System.out.println("Test 3: Parameter validation");
|
|
try {
|
|
new Config.ConfigBuilder("")
|
|
.build();
|
|
System.out.println("Failed: Empty URL should be rejected");
|
|
} catch (IllegalArgumentException e) {
|
|
System.out.println("Success: Empty URL rejected - " + e.getMessage());
|
|
}
|
|
|
|
try {
|
|
new Config.ConfigBuilder("http://example.com")
|
|
.setMaxConnections(-1)
|
|
.build();
|
|
System.out.println("Failed: Negative max connections should be rejected");
|
|
} catch (IllegalArgumentException e) {
|
|
System.out.println("Success: Negative max connections rejected - " + e.getMessage());
|
|
}
|
|
}
|
|
} |