Skip to content

Commit 5b767bc

Browse files
committed
Add validation test for Serializable lambda in Kotlin
1 parent 1e37ea8 commit 5b767bc

File tree

2 files changed

+84
-0
lines changed

2 files changed

+84
-0
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2009, 2024 Mountainminds GmbH & Co. KG and Contributors
3+
* This program and the accompanying materials are made available under
4+
* the terms of the Eclipse Public License 2.0 which is available at
5+
* http://www.eclipse.org/legal/epl-2.0
6+
*
7+
* SPDX-License-Identifier: EPL-2.0
8+
*
9+
* Contributors:
10+
* Evgeny Mandrikov - initial API and implementation
11+
*
12+
*******************************************************************************/
13+
package org.jacoco.core.test.validation.kotlin;
14+
15+
import static org.junit.Assert.assertEquals;
16+
17+
import java.lang.reflect.Method;
18+
import java.util.Collections;
19+
import java.util.HashSet;
20+
21+
import org.jacoco.core.test.validation.ValidationTestBase;
22+
import org.jacoco.core.test.validation.kotlin.targets.KotlinLambdaSerializableTarget;
23+
import org.junit.Test;
24+
25+
/**
26+
* Test of code coverage in {@link KotlinLambdaSerializableTarget}.
27+
*/
28+
public class KotlinLambdaSerializableTest extends ValidationTestBase {
29+
30+
public KotlinLambdaSerializableTest() {
31+
super(KotlinLambdaSerializableTarget.class);
32+
}
33+
34+
@Test
35+
public void compiler_should_generate_synthetic_deserializeLambda() {
36+
final HashSet<String> names = new HashSet<String>();
37+
for (final Method method : KotlinLambdaSerializableTarget.class
38+
.getDeclaredMethods()) {
39+
if (method.isSynthetic()) {
40+
names.add(method.getName());
41+
}
42+
}
43+
44+
assertEquals(Collections.singleton("$deserializeLambda$"), names);
45+
}
46+
47+
@Test
48+
public void test_method_count() {
49+
assertMethodCount(/* main + lambda */ 2);
50+
}
51+
52+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2009, 2024 Mountainminds GmbH & Co. KG and Contributors
3+
* This program and the accompanying materials are made available under
4+
* the terms of the Eclipse Public License 2.0 which is available at
5+
* http://www.eclipse.org/legal/epl-2.0
6+
*
7+
* SPDX-License-Identifier: EPL-2.0
8+
*
9+
* Contributors:
10+
* Evgeny Mandrikov - initial API and implementation
11+
*
12+
*******************************************************************************/
13+
package org.jacoco.core.test.validation.kotlin.targets
14+
15+
import org.jacoco.core.test.validation.targets.Stubs.execSerializable
16+
import org.jacoco.core.test.validation.targets.Stubs.nop
17+
18+
/**
19+
* Test target with [java.io.Serializable] lambda.
20+
*/
21+
object KotlinLambdaSerializableTarget {
22+
23+
@JvmStatic
24+
fun main(args: Array<String>) {
25+
26+
execSerializable {
27+
nop() // assertFullyCovered()
28+
}
29+
30+
}
31+
32+
}

0 commit comments

Comments
 (0)