Skip to content

Commit

Permalink
add special mode for unittests where we cannot use OSGi
Browse files Browse the repository at this point in the history
  • Loading branch information
benjamin-confino committed Dec 4, 2024
1 parent 8547ecd commit 68ae73a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.lang.ref.Reference;
import java.lang.ref.SoftReference;
import java.lang.ref.WeakReference;
import java.text.MessageFormat;
import java.util.ArrayList;
Expand Down Expand Up @@ -111,7 +113,9 @@ public ClassSourceImpl_Aggregate(
Properties props = System.getProperties();
String inUnitTest = props.getProperty("running.unit.test");

if (applicationName != ClassSource_Factory.UNNAMED_APP) {
if (inUnitTest != null && inUnitTest.equals("true")) {
this.applicationKey = new SoftReference<AppKey>(new AppKey(applicationName));
} else if (applicationName != ClassSource_Factory.UNNAMED_APP) {
AppKey appKey = keyServiceServiceCaller.run((AnnotationService_KeyService ks) -> ks.getKeyForApp(applicationName)).get();
this.applicationKey = new WeakReference<AppKey>(appKey);
} else {
Expand Down Expand Up @@ -198,7 +202,7 @@ protected String internClassName(String className, boolean doForce) {
protected final String applicationName;
protected final String moduleName;
protected final String moduleCategoryName;
protected final WeakReference<AppKey> applicationKey;
protected final Reference<AppKey> applicationKey;

/**
* <p>Answer the name of the application of this class source.</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.logging.Logger;

Expand Down Expand Up @@ -70,6 +71,9 @@ public class InfoStore_Internals_Test {
public static void setup() throws ClassSource_Exception, InfoStoreException {
UtilImpl_Factory utilImplFactory = new UtilImpl_Factory();
ClassSourceImpl_Factory factory = new ClassSourceImpl_Factory(utilImplFactory);

Properties props = System.getProperties();
props.setProperty("running.unit.test", "true");

ClassSourceImpl_Aggregate useRootClassSource =
factory.createAggregateClassSource("TestEar", "TestMod", ClassSource_Factory.UNSET_CATEGORY_NAME, factory.createOptions() );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Properties;

import org.junit.AfterClass;
import org.junit.Assert;
Expand Down Expand Up @@ -99,6 +100,9 @@ private static void setUpClassSource() throws Exception {

protected static ClassSourceImpl_Aggregate createClassSource() throws Exception {
ClassSourceImpl_Factory factory = getClassSourceFactory();

Properties props = System.getProperties();
props.setProperty("running.unit.test", "true");

ClassSourceImpl_Aggregate useRootClassSource =
factory.createAggregateClassSource(
Expand Down

0 comments on commit 68ae73a

Please sign in to comment.