Skip to content

Commit

Permalink
Add validation test for Serializable lambda in Kotlin (#1699)
Browse files Browse the repository at this point in the history
  • Loading branch information
Godin authored Dec 19, 2024
1 parent 22ead5e commit 70a82d9
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*******************************************************************************
* Copyright (c) 2009, 2024 Mountainminds GmbH & Co. KG and Contributors
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Evgeny Mandrikov - initial API and implementation
*
*******************************************************************************/
package org.jacoco.core.test.validation.kotlin;

import static org.junit.Assert.assertEquals;

import java.lang.reflect.Method;
import java.util.Collections;
import java.util.HashSet;

import org.jacoco.core.test.validation.ValidationTestBase;
import org.jacoco.core.test.validation.kotlin.targets.KotlinLambdaSerializableTarget;
import org.junit.Test;

/**
* Test of code coverage in {@link KotlinLambdaSerializableTarget}.
*/
public class KotlinLambdaSerializableTest extends ValidationTestBase {

public KotlinLambdaSerializableTest() {
super(KotlinLambdaSerializableTarget.class);
}

@Test
public void compiler_should_generate_synthetic_deserializeLambda() {
final HashSet<String> names = new HashSet<String>();
for (final Method method : KotlinLambdaSerializableTarget.class
.getDeclaredMethods()) {
if (method.isSynthetic()) {
names.add(method.getName());
}
}

assertEquals(Collections.singleton("$deserializeLambda$"), names);
}

@Test
public void test_method_count() {
assertMethodCount(/* main + lambda */ 2);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*******************************************************************************
* Copyright (c) 2009, 2024 Mountainminds GmbH & Co. KG and Contributors
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Evgeny Mandrikov - initial API and implementation
*
*******************************************************************************/
package org.jacoco.core.test.validation.kotlin.targets

import org.jacoco.core.test.validation.targets.Stubs.execSerializable
import org.jacoco.core.test.validation.targets.Stubs.nop

/**
* Test target with [java.io.Serializable] lambda.
*/
object KotlinLambdaSerializableTarget {

@JvmStatic
fun main(args: Array<String>) {

execSerializable {
nop() // assertFullyCovered()
}

}

}

0 comments on commit 70a82d9

Please sign in to comment.