From c8f51290fde95fe9f652380d1485ba4884765bbb Mon Sep 17 00:00:00 2001 From: Tamas Cservenak Date: Wed, 8 May 2024 12:34:20 +0200 Subject: [PATCH] Add more tests to improve coverage Sonar reports error due coverage check failing. The coverage went off related to this change: bfbca8a52ad6134d7d48105f1bc1c01ff33bf997 --- .../org/eclipse/sisu/bean/LifecycleTest.java | 5 +++ .../sisu/bean/alpha/SisuOverriddenPublic.java | 35 +++++++++++++++++++ .../eclipse/sisu/bean/alpha/SisuPublic.java | 33 +++++++++++++++++ 3 files changed, 73 insertions(+) create mode 100644 org.eclipse.sisu.inject/src/test/java/org/eclipse/sisu/bean/alpha/SisuOverriddenPublic.java create mode 100644 org.eclipse.sisu.inject/src/test/java/org/eclipse/sisu/bean/alpha/SisuPublic.java diff --git a/org.eclipse.sisu.inject/src/test/java/org/eclipse/sisu/bean/LifecycleTest.java b/org.eclipse.sisu.inject/src/test/java/org/eclipse/sisu/bean/LifecycleTest.java index dd2d557b..6dac55a7 100644 --- a/org.eclipse.sisu.inject/src/test/java/org/eclipse/sisu/bean/LifecycleTest.java +++ b/org.eclipse.sisu.inject/src/test/java/org/eclipse/sisu/bean/LifecycleTest.java @@ -39,6 +39,7 @@ protected void configure() void testBaseLifecycle() { assertEquals( "a", injector.getInstance( org.eclipse.sisu.bean.alpha.Public.class ).results() ); + assertEquals( "a", injector.getInstance( org.eclipse.sisu.bean.alpha.SisuPublic.class ).results() ); assertEquals( "ab", injector.getInstance( org.eclipse.sisu.bean.alpha.Protected.class ).results() ); assertEquals( "abc", injector.getInstance( org.eclipse.sisu.bean.alpha.Package.class ).results() ); assertEquals( "abcd", injector.getInstance( org.eclipse.sisu.bean.alpha.Private.class ).results() ); @@ -46,6 +47,7 @@ void testBaseLifecycle() injector.getInstance( BeanManager.class ).unmanage(); assertEquals( "az", injector.getInstance( org.eclipse.sisu.bean.alpha.Public.class ).results() ); + assertEquals( "az", injector.getInstance( org.eclipse.sisu.bean.alpha.SisuPublic.class ).results() ); assertEquals( "abyz", injector.getInstance( org.eclipse.sisu.bean.alpha.Protected.class ).results() ); assertEquals( "abcxyz", injector.getInstance( org.eclipse.sisu.bean.alpha.Package.class ).results() ); assertEquals( "abcdwxyz", injector.getInstance( org.eclipse.sisu.bean.alpha.Private.class ).results() ); @@ -55,6 +57,7 @@ void testBaseLifecycle() void testOverriddenLifecycle() { assertEquals( "bcdA", injector.getInstance( org.eclipse.sisu.bean.alpha.OverriddenPublic.class ).results() ); + assertEquals( "bcdA", injector.getInstance( org.eclipse.sisu.bean.alpha.SisuOverriddenPublic.class ).results() ); assertEquals( "cdAB", injector.getInstance( org.eclipse.sisu.bean.alpha.OverriddenProtected.class ).results() ); assertEquals( "dABC", injector.getInstance( org.eclipse.sisu.bean.alpha.OverriddenPackage.class ).results() ); assertEquals( "dABCD", injector.getInstance( org.eclipse.sisu.bean.alpha.OverriddenPrivate.class ).results() ); @@ -63,6 +66,8 @@ void testOverriddenLifecycle() assertEquals( "bcdAZwxy", injector.getInstance( org.eclipse.sisu.bean.alpha.OverriddenPublic.class ).results() ); + assertEquals( "bcdAZwxy", + injector.getInstance( org.eclipse.sisu.bean.alpha.SisuOverriddenPublic.class ).results() ); assertEquals( "cdABYZwx", injector.getInstance( org.eclipse.sisu.bean.alpha.OverriddenProtected.class ).results() ); assertEquals( "dABCXYZw", diff --git a/org.eclipse.sisu.inject/src/test/java/org/eclipse/sisu/bean/alpha/SisuOverriddenPublic.java b/org.eclipse.sisu.inject/src/test/java/org/eclipse/sisu/bean/alpha/SisuOverriddenPublic.java new file mode 100644 index 00000000..788b2780 --- /dev/null +++ b/org.eclipse.sisu.inject/src/test/java/org/eclipse/sisu/bean/alpha/SisuOverriddenPublic.java @@ -0,0 +1,35 @@ +/******************************************************************************* + * Copyright (c) 2010-present Sonatype, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Stuart McCulloch (Sonatype, Inc.) - initial API and implementation + *******************************************************************************/ +package org.eclipse.sisu.bean.alpha; + +import org.eclipse.sisu.PostConstruct; +import org.eclipse.sisu.PreDestroy; + +import javax.inject.Singleton; + +@Singleton +public class SisuOverriddenPublic + extends Private +{ + @Override + @PostConstruct + public void a() + { + results.append( "A" ); + } + + @Override + @PreDestroy + public void z() + { + results.append( "Z" ); + } +} diff --git a/org.eclipse.sisu.inject/src/test/java/org/eclipse/sisu/bean/alpha/SisuPublic.java b/org.eclipse.sisu.inject/src/test/java/org/eclipse/sisu/bean/alpha/SisuPublic.java new file mode 100644 index 00000000..77c96ad7 --- /dev/null +++ b/org.eclipse.sisu.inject/src/test/java/org/eclipse/sisu/bean/alpha/SisuPublic.java @@ -0,0 +1,33 @@ +/******************************************************************************* + * Copyright (c) 2010-present Sonatype, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Stuart McCulloch (Sonatype, Inc.) - initial API and implementation + *******************************************************************************/ +package org.eclipse.sisu.bean.alpha; + +import org.eclipse.sisu.PostConstruct; +import org.eclipse.sisu.PreDestroy; + +import javax.inject.Singleton; + +@Singleton +public class SisuPublic + extends Base +{ + @PostConstruct + public void a() + { + results.append( "a" ); + } + + @PreDestroy + public void z() + { + results.append( "z" ); + } +}