Skip to content

Commit bb52c2d

Browse files
CopilotkyonRay
andauthored
Add unit tests to increase JaCoCo coverage from 30.1% to 30.7% (#1)
* Initial plan * Initial setup: Upgrade Gradle to 7.6.4 for Java 17 compatibility and fix duplicate resources handling Co-authored-by: kyonRay <[email protected]> * Add unit tests for model classes and exceptions to improve coverage Co-authored-by: kyonRay <[email protected]> * Add more unit tests for model and enum classes to increase coverage Co-authored-by: kyonRay <[email protected]> * Add unit tests for crypto exception classes to increase coverage Co-authored-by: kyonRay <[email protected]> * Downgrade Gradle version to 6.3 --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: kyonRay <[email protected]>
1 parent aef619c commit bb52c2d

17 files changed

+1484
-0
lines changed

build.gradle

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,10 @@ sourceSets {
114114
}
115115
}
116116

117+
tasks.withType(ProcessResources) {
118+
duplicatesStrategy = DuplicatesStrategy.INCLUDE
119+
}
120+
117121
googleJavaFormat {
118122
toolVersion = '1.7'
119123
options style: 'AOSP'
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
package org.fisco.bcos.sdk.v3.test.config.exceptions;
2+
3+
import org.fisco.bcos.sdk.v3.config.exceptions.ConfigException;
4+
import org.junit.Assert;
5+
import org.junit.Test;
6+
7+
public class ConfigExceptionTest {
8+
9+
@Test
10+
public void testConstructorWithMessage() {
11+
String message = "Configuration error occurred";
12+
ConfigException exception = new ConfigException(message);
13+
14+
Assert.assertNotNull(exception);
15+
Assert.assertEquals(message, exception.getMessage());
16+
}
17+
18+
@Test
19+
public void testConstructorWithCause() {
20+
Exception cause = new RuntimeException("Root cause");
21+
ConfigException exception = new ConfigException(cause);
22+
23+
Assert.assertNotNull(exception);
24+
Assert.assertEquals(cause, exception.getCause());
25+
Assert.assertTrue(exception.getMessage().contains("Root cause"));
26+
}
27+
28+
@Test
29+
public void testConstructorWithMessageAndCause() {
30+
String message = "Configuration error";
31+
Exception cause = new IllegalArgumentException("Invalid argument");
32+
ConfigException exception = new ConfigException(message, cause);
33+
34+
Assert.assertNotNull(exception);
35+
Assert.assertEquals(message, exception.getMessage());
36+
Assert.assertEquals(cause, exception.getCause());
37+
}
38+
39+
@Test
40+
public void testExceptionIsThrowable() {
41+
ConfigException exception = new ConfigException("Test");
42+
Assert.assertTrue(exception instanceof Exception);
43+
Assert.assertTrue(exception instanceof Throwable);
44+
}
45+
46+
@Test
47+
public void testExceptionCanBeCaught() {
48+
try {
49+
throw new ConfigException("Test exception");
50+
} catch (ConfigException e) {
51+
Assert.assertEquals("Test exception", e.getMessage());
52+
} catch (Exception e) {
53+
Assert.fail("Should have caught ConfigException specifically");
54+
}
55+
}
56+
57+
@Test
58+
public void testNullMessage() {
59+
ConfigException exception = new ConfigException((String) null);
60+
Assert.assertNotNull(exception);
61+
Assert.assertNull(exception.getMessage());
62+
}
63+
64+
@Test
65+
public void testNullCause() {
66+
ConfigException exception = new ConfigException((Throwable) null);
67+
Assert.assertNotNull(exception);
68+
Assert.assertNull(exception.getCause());
69+
}
70+
71+
@Test
72+
public void testEmptyMessage() {
73+
String message = "";
74+
ConfigException exception = new ConfigException(message);
75+
Assert.assertEquals(message, exception.getMessage());
76+
}
77+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package org.fisco.bcos.sdk.v3.test.crypto.exceptions;
2+
3+
import org.fisco.bcos.sdk.v3.crypto.exceptions.HashException;
4+
import org.junit.Assert;
5+
import org.junit.Test;
6+
7+
public class HashExceptionTest {
8+
9+
@Test
10+
public void testConstructorWithMessage() {
11+
String message = "Hash computation failed";
12+
HashException exception = new HashException(message);
13+
14+
Assert.assertNotNull(exception);
15+
Assert.assertEquals(message, exception.getMessage());
16+
}
17+
18+
@Test
19+
public void testConstructorWithMessageAndCause() {
20+
String message = "Hash error occurred";
21+
Exception cause = new IllegalArgumentException("Invalid input");
22+
HashException exception = new HashException(message, cause);
23+
24+
Assert.assertNotNull(exception);
25+
Assert.assertEquals(message, exception.getMessage());
26+
Assert.assertEquals(cause, exception.getCause());
27+
}
28+
29+
@Test
30+
public void testExceptionIsRuntimeException() {
31+
HashException exception = new HashException("Test");
32+
Assert.assertTrue(exception instanceof RuntimeException);
33+
Assert.assertTrue(exception instanceof Exception);
34+
}
35+
36+
@Test
37+
public void testExceptionCanBeCaught() {
38+
try {
39+
throw new HashException("Hash exception");
40+
} catch (HashException e) {
41+
Assert.assertEquals("Hash exception", e.getMessage());
42+
} catch (Exception e) {
43+
Assert.fail("Should have caught HashException specifically");
44+
}
45+
}
46+
47+
@Test
48+
public void testNullMessage() {
49+
HashException exception = new HashException(null);
50+
Assert.assertNotNull(exception);
51+
Assert.assertNull(exception.getMessage());
52+
}
53+
54+
@Test
55+
public void testEmptyMessage() {
56+
String message = "";
57+
HashException exception = new HashException(message);
58+
Assert.assertEquals(message, exception.getMessage());
59+
}
60+
61+
@Test
62+
public void testNullCause() {
63+
HashException exception = new HashException("Message", null);
64+
Assert.assertNotNull(exception);
65+
Assert.assertNull(exception.getCause());
66+
}
67+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package org.fisco.bcos.sdk.v3.test.crypto.exceptions;
2+
3+
import org.fisco.bcos.sdk.v3.crypto.exceptions.KeyPairException;
4+
import org.junit.Assert;
5+
import org.junit.Test;
6+
7+
public class KeyPairExceptionTest {
8+
9+
@Test
10+
public void testConstructorWithMessage() {
11+
String message = "Key pair generation failed";
12+
KeyPairException exception = new KeyPairException(message);
13+
14+
Assert.assertNotNull(exception);
15+
Assert.assertEquals(message, exception.getMessage());
16+
}
17+
18+
@Test
19+
public void testConstructorWithMessageAndCause() {
20+
String message = "Key pair error occurred";
21+
Exception cause = new IllegalStateException("Invalid state");
22+
KeyPairException exception = new KeyPairException(message, cause);
23+
24+
Assert.assertNotNull(exception);
25+
Assert.assertEquals(message, exception.getMessage());
26+
Assert.assertEquals(cause, exception.getCause());
27+
}
28+
29+
@Test
30+
public void testExceptionIsRuntimeException() {
31+
KeyPairException exception = new KeyPairException("Test");
32+
Assert.assertTrue(exception instanceof RuntimeException);
33+
Assert.assertTrue(exception instanceof Exception);
34+
}
35+
36+
@Test
37+
public void testExceptionCanBeCaught() {
38+
try {
39+
throw new KeyPairException("Key pair exception");
40+
} catch (KeyPairException e) {
41+
Assert.assertEquals("Key pair exception", e.getMessage());
42+
} catch (Exception e) {
43+
Assert.fail("Should have caught KeyPairException specifically");
44+
}
45+
}
46+
47+
@Test
48+
public void testNullMessage() {
49+
KeyPairException exception = new KeyPairException(null);
50+
Assert.assertNotNull(exception);
51+
Assert.assertNull(exception.getMessage());
52+
}
53+
54+
@Test
55+
public void testEmptyMessage() {
56+
String message = "";
57+
KeyPairException exception = new KeyPairException(message);
58+
Assert.assertEquals(message, exception.getMessage());
59+
}
60+
61+
@Test
62+
public void testNullCause() {
63+
KeyPairException exception = new KeyPairException("Message", null);
64+
Assert.assertNotNull(exception);
65+
Assert.assertNull(exception.getCause());
66+
}
67+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package org.fisco.bcos.sdk.v3.test.crypto.exceptions;
2+
3+
import org.fisco.bcos.sdk.v3.crypto.exceptions.LoadKeyStoreException;
4+
import org.junit.Assert;
5+
import org.junit.Test;
6+
7+
public class LoadKeyStoreExceptionTest {
8+
9+
@Test
10+
public void testConstructorWithMessage() {
11+
String message = "Failed to load keystore";
12+
LoadKeyStoreException exception = new LoadKeyStoreException(message);
13+
14+
Assert.assertNotNull(exception);
15+
Assert.assertEquals(message, exception.getMessage());
16+
}
17+
18+
@Test
19+
public void testConstructorWithMessageAndCause() {
20+
String message = "Keystore load error";
21+
Exception cause = new java.io.IOException("File not found");
22+
LoadKeyStoreException exception = new LoadKeyStoreException(message, cause);
23+
24+
Assert.assertNotNull(exception);
25+
Assert.assertEquals(message, exception.getMessage());
26+
Assert.assertEquals(cause, exception.getCause());
27+
}
28+
29+
@Test
30+
public void testExceptionIsRuntimeException() {
31+
LoadKeyStoreException exception = new LoadKeyStoreException("Test");
32+
Assert.assertTrue(exception instanceof RuntimeException);
33+
Assert.assertTrue(exception instanceof Exception);
34+
}
35+
36+
@Test
37+
public void testExceptionCanBeCaught() {
38+
try {
39+
throw new LoadKeyStoreException("Load exception");
40+
} catch (LoadKeyStoreException e) {
41+
Assert.assertEquals("Load exception", e.getMessage());
42+
} catch (Exception e) {
43+
Assert.fail("Should have caught LoadKeyStoreException specifically");
44+
}
45+
}
46+
47+
@Test
48+
public void testNullMessage() {
49+
LoadKeyStoreException exception = new LoadKeyStoreException(null);
50+
Assert.assertNotNull(exception);
51+
Assert.assertNull(exception.getMessage());
52+
}
53+
54+
@Test
55+
public void testEmptyMessage() {
56+
String message = "";
57+
LoadKeyStoreException exception = new LoadKeyStoreException(message);
58+
Assert.assertEquals(message, exception.getMessage());
59+
}
60+
61+
@Test
62+
public void testNullCause() {
63+
LoadKeyStoreException exception = new LoadKeyStoreException("Message", null);
64+
Assert.assertNotNull(exception);
65+
Assert.assertNull(exception.getCause());
66+
}
67+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package org.fisco.bcos.sdk.v3.test.crypto.exceptions;
2+
3+
import org.fisco.bcos.sdk.v3.crypto.exceptions.SignatureException;
4+
import org.junit.Assert;
5+
import org.junit.Test;
6+
7+
public class SignatureExceptionTest {
8+
9+
@Test
10+
public void testConstructorWithMessage() {
11+
String message = "Signature verification failed";
12+
SignatureException exception = new SignatureException(message);
13+
14+
Assert.assertNotNull(exception);
15+
Assert.assertEquals(message, exception.getMessage());
16+
}
17+
18+
@Test
19+
public void testConstructorWithMessageAndCause() {
20+
String message = "Signature error occurred";
21+
Exception cause = new IllegalArgumentException("Invalid signature");
22+
SignatureException exception = new SignatureException(message, cause);
23+
24+
Assert.assertNotNull(exception);
25+
Assert.assertEquals(message, exception.getMessage());
26+
Assert.assertEquals(cause, exception.getCause());
27+
}
28+
29+
@Test
30+
public void testExceptionIsRuntimeException() {
31+
SignatureException exception = new SignatureException("Test");
32+
Assert.assertTrue(exception instanceof RuntimeException);
33+
Assert.assertTrue(exception instanceof Exception);
34+
}
35+
36+
@Test
37+
public void testExceptionCanBeCaught() {
38+
try {
39+
throw new SignatureException("Signature exception");
40+
} catch (SignatureException e) {
41+
Assert.assertEquals("Signature exception", e.getMessage());
42+
} catch (Exception e) {
43+
Assert.fail("Should have caught SignatureException specifically");
44+
}
45+
}
46+
47+
@Test
48+
public void testNullMessage() {
49+
SignatureException exception = new SignatureException(null);
50+
Assert.assertNotNull(exception);
51+
Assert.assertNull(exception.getMessage());
52+
}
53+
54+
@Test
55+
public void testEmptyMessage() {
56+
String message = "";
57+
SignatureException exception = new SignatureException(message);
58+
Assert.assertEquals(message, exception.getMessage());
59+
}
60+
61+
@Test
62+
public void testNullCause() {
63+
SignatureException exception = new SignatureException("Message", null);
64+
Assert.assertNotNull(exception);
65+
Assert.assertNull(exception.getCause());
66+
}
67+
}

0 commit comments

Comments
 (0)