Skip to content

Commit 2b62359

Browse files
Add unit tests for various core classes to improve coverage. (#4270)
Added tests for: - com.codename1.javascript.JSException - com.codename1.util.regex.RESyntaxException - com.codename1.ui.BlockingDisallowedException - com.codename1.charts.renderers.DialRenderer.Type - com.codename1.ui.layouts.mig.UnitConverter - com.codename1.io.Oauth2.RefreshTokenRequest - com.codename1.charts.compat.Paint (Cap, Join, Align) - com.codename1.ui.Sheet (static methods) These tests increase coverage for classes that previously had zero coverage. Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
1 parent 05f545f commit 2b62359

File tree

9 files changed

+169
-2
lines changed

9 files changed

+169
-2
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.codename1.charts.compat;
2+
3+
import com.codename1.junit.FormTest;
4+
import com.codename1.junit.UITestBase;
5+
import com.codename1.ui.Component;
6+
import com.codename1.ui.Stroke;
7+
import org.junit.jupiter.api.Assertions;
8+
9+
public class PaintCompatTest extends UITestBase {
10+
11+
@FormTest
12+
public void testAlign() {
13+
Assertions.assertEquals(Component.CENTER, Paint.Align.CENTER);
14+
Assertions.assertEquals(Component.LEFT, Paint.Align.LEFT);
15+
Assertions.assertEquals(Component.RIGHT, Paint.Align.RIGHT);
16+
Paint.Align align = new Paint.Align();
17+
Assertions.assertNotNull(align);
18+
}
19+
20+
@FormTest
21+
public void testCap() {
22+
Assertions.assertEquals(Stroke.CAP_BUTT, Paint.Cap.BUTT);
23+
Assertions.assertEquals(Stroke.CAP_ROUND, Paint.Cap.ROUND);
24+
Assertions.assertEquals(Stroke.CAP_SQUARE, Paint.Cap.SQUARE);
25+
Paint.Cap cap = new Paint.Cap();
26+
Assertions.assertNotNull(cap);
27+
}
28+
29+
@FormTest
30+
public void testJoin() {
31+
Assertions.assertEquals(Stroke.JOIN_BEVEL, Paint.Join.BEVEL);
32+
Assertions.assertEquals(Stroke.JOIN_MITER, Paint.Join.MITER);
33+
Assertions.assertEquals(Stroke.JOIN_ROUND, Paint.Join.ROUND);
34+
Paint.Join join = new Paint.Join();
35+
Assertions.assertNotNull(join);
36+
}
37+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.codename1.charts.renderers;
2+
3+
import com.codename1.junit.FormTest;
4+
import com.codename1.junit.UITestBase;
5+
import org.junit.jupiter.api.Assertions;
6+
7+
public class DialRendererTypeTest extends UITestBase {
8+
9+
@FormTest
10+
public void testEnum() {
11+
Assertions.assertEquals(DialRenderer.Type.NEEDLE, DialRenderer.Type.valueOf("NEEDLE"));
12+
Assertions.assertEquals(DialRenderer.Type.ARROW, DialRenderer.Type.valueOf("ARROW"));
13+
Assertions.assertEquals(2, DialRenderer.Type.values().length);
14+
}
15+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.codename1.io;
2+
3+
import com.codename1.junit.FormTest;
4+
import com.codename1.junit.UITestBase;
5+
import org.junit.jupiter.api.Assertions;
6+
7+
public class Oauth2RefreshTokenRequestTest extends UITestBase {
8+
9+
@FormTest
10+
public void testRefreshTokenRequest() {
11+
// Just instantiate to cover the class definition
12+
Oauth2.RefreshTokenRequest req = new Oauth2("url", "id", "uri").new RefreshTokenRequest();
13+
Assertions.assertNotNull(req);
14+
}
15+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.codename1.javascript;
2+
3+
import com.codename1.junit.FormTest;
4+
import com.codename1.junit.UITestBase;
5+
import org.junit.jupiter.api.Assertions;
6+
7+
public class JSExceptionTest extends UITestBase {
8+
9+
@FormTest
10+
public void testConstructor() {
11+
JSException ex = new JSException("Test message");
12+
Assertions.assertEquals("Test message", ex.getMessage());
13+
Assertions.assertTrue(ex instanceof RuntimeException);
14+
}
15+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.codename1.ui;
2+
3+
import com.codename1.junit.FormTest;
4+
import com.codename1.junit.UITestBase;
5+
import org.junit.jupiter.api.Assertions;
6+
7+
public class BlockingDisallowedExceptionTest extends UITestBase {
8+
9+
@FormTest
10+
public void testConstructor() {
11+
BlockingDisallowedException ex = new BlockingDisallowedException();
12+
Assertions.assertEquals("Attempt to run invokeAndBlock while blocking is disabled.", ex.getMessage());
13+
Assertions.assertTrue(ex instanceof IllegalStateException);
14+
}
15+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.codename1.ui;
2+
3+
import com.codename1.junit.FormTest;
4+
import com.codename1.junit.UITestBase;
5+
import com.codename1.ui.layouts.BorderLayout;
6+
import org.junit.jupiter.api.Assertions;
7+
8+
public class SheetCoverageTest extends UITestBase {
9+
10+
@FormTest
11+
public void testSheetStaticMethods() {
12+
// Setup a form with a Sheet
13+
Form form = Display.getInstance().getCurrent();
14+
form.setLayout(new BorderLayout());
15+
16+
Sheet sheet = new Sheet(null, "Test Sheet");
17+
sheet.show(0);
18+
19+
// This should trigger getCurrentSheet() logic
20+
Sheet current = Sheet.getCurrentSheet();
21+
Assertions.assertEquals(sheet, current);
22+
23+
// This should trigger findContainingSheet() logic
24+
Label content = new Label("Content");
25+
sheet.getContentPane().add(content);
26+
27+
Sheet found = Sheet.findContainingSheet(content);
28+
Assertions.assertEquals(sheet, found);
29+
30+
// Test null cases
31+
Assertions.assertNull(Sheet.findContainingSheet(form));
32+
}
33+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.codename1.ui.layouts.mig;
2+
3+
import com.codename1.junit.FormTest;
4+
import com.codename1.junit.UITestBase;
5+
import org.junit.jupiter.api.Assertions;
6+
7+
public class UnitConverterTest extends UITestBase {
8+
9+
@FormTest
10+
public void testConstantsAndImpl() {
11+
Assertions.assertEquals(-87654312, UnitConverter.UNABLE);
12+
13+
UnitConverter converter = new UnitConverter() {
14+
@Override
15+
public int convertToPixels(float value, String unit, boolean isHor, float refValue, ContainerWrapper parent, ComponentWrapper comp) {
16+
return (int) value;
17+
}
18+
};
19+
20+
Assertions.assertEquals(10, converter.convertToPixels(10.5f, "px", true, 0, null, null));
21+
}
22+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.codename1.util.regex;
2+
3+
import com.codename1.junit.FormTest;
4+
import com.codename1.junit.UITestBase;
5+
import org.junit.jupiter.api.Assertions;
6+
7+
public class RESyntaxExceptionTest extends UITestBase {
8+
9+
@FormTest
10+
public void testConstructor() {
11+
RESyntaxException ex = new RESyntaxException("Invalid regex");
12+
Assertions.assertEquals("Syntax error: Invalid regex", ex.getMessage());
13+
Assertions.assertTrue(ex instanceof RuntimeException);
14+
}
15+
}

maven/java-runtime/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
<artifactId>maven-compiler-plugin</artifactId>
2929

3030
<configuration>
31-
<source>1.5</source>
32-
<target>1.5</target>
31+
<source>1.8</source>
32+
<target>1.8</target>
3333
</configuration>
3434
</plugin>
3535
</plugins>

0 commit comments

Comments
 (0)