|
| 1 | +/******************************************************************************* |
| 2 | + * Copyright (c) 2009, 2026 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 | + * https://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.internal.analysis.filter; |
| 14 | + |
| 15 | +import org.jacoco.core.internal.instr.InstrSupport; |
| 16 | +import org.junit.Test; |
| 17 | +import org.objectweb.asm.Opcodes; |
| 18 | +import org.objectweb.asm.tree.MethodNode; |
| 19 | + |
| 20 | +/** |
| 21 | + * Unit test for {@link KotlinExposeBoxedFilter}. |
| 22 | + */ |
| 23 | +public class KotlinExposeBoxedFilterTest extends FilterTestBase { |
| 24 | + |
| 25 | + private final KotlinExposeBoxedFilter filter = new KotlinExposeBoxedFilter(); |
| 26 | + |
| 27 | + /** |
| 28 | + * <pre> |
| 29 | + * @JvmExposeBoxed |
| 30 | + * fun example(v: ValueClass) = ... |
| 31 | + * </pre> |
| 32 | + */ |
| 33 | + @Test |
| 34 | + public void should_filter_when_parameter_exposed() { |
| 35 | + final MethodNode m = new MethodNode(InstrSupport.ASM_API_VERSION, 0, |
| 36 | + "example", "()LValueClass;", null, null); |
| 37 | + m.visitAnnotation("Lkotlin/jvm/JvmExposeBoxed;", false); |
| 38 | + |
| 39 | + m.visitVarInsn(Opcodes.ALOAD, 0); |
| 40 | + m.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "ValueClass", "unbox-impl", |
| 41 | + "()Ljava/lang/String;", false); |
| 42 | + |
| 43 | + filter.filter(m, context, output); |
| 44 | + |
| 45 | + assertMethodIgnored(m); |
| 46 | + } |
| 47 | + |
| 48 | + /** |
| 49 | + * <pre> |
| 50 | + * @JvmExposeBoxed(jvmName = "exposed") |
| 51 | + * fun example(): ValueClass = ... |
| 52 | + * </pre> |
| 53 | + */ |
| 54 | + @Test |
| 55 | + public void should_filter_when_return_type_exposed() { |
| 56 | + final MethodNode m = new MethodNode(InstrSupport.ASM_API_VERSION, 0, |
| 57 | + "exposed", "()LValueClass;", null, null); |
| 58 | + m.visitAnnotation("Lkotlin/jvm/JvmExposeBoxed;", false); |
| 59 | + |
| 60 | + m.visitMethodInsn(Opcodes.INVOKESTATIC, "ValueClass", "box-impl", |
| 61 | + "(Ljava/lang/String;)LValueClass;", false); |
| 62 | + m.visitInsn(Opcodes.ARETURN); |
| 63 | + |
| 64 | + filter.filter(m, context, output); |
| 65 | + |
| 66 | + assertMethodIgnored(m); |
| 67 | + } |
| 68 | + |
| 69 | + /** |
| 70 | + * <pre> |
| 71 | + * @JvmExposeBoxed |
| 72 | + * fun example() = ... |
| 73 | + * </pre> |
| 74 | + */ |
| 75 | + @Test |
| 76 | + public void should_not_filter_when_nothing_exposed() { |
| 77 | + final MethodNode m = new MethodNode(InstrSupport.ASM_API_VERSION, 0, |
| 78 | + "example", "()V", null, null); |
| 79 | + m.visitAnnotation("Lkotlin/jvm/JvmExposeBoxed;", false); |
| 80 | + |
| 81 | + filter.filter(m, context, output); |
| 82 | + |
| 83 | + assertIgnored(m); |
| 84 | + } |
| 85 | + |
| 86 | + /** |
| 87 | + * @see #should_filter_when_parameter_exposed() |
| 88 | + */ |
| 89 | + @Test |
| 90 | + public void should_not_filter_when_no_annotation() { |
| 91 | + final MethodNode m = new MethodNode(InstrSupport.ASM_API_VERSION, 0, |
| 92 | + "example", "()LValueClass;", null, null); |
| 93 | + |
| 94 | + m.visitVarInsn(Opcodes.ALOAD, 0); |
| 95 | + m.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "ValueClass", "unbox-impl", |
| 96 | + "()Ljava/lang/String;", false); |
| 97 | + |
| 98 | + filter.filter(m, context, output); |
| 99 | + |
| 100 | + assertIgnored(m); |
| 101 | + } |
| 102 | + |
| 103 | +} |
0 commit comments