Skip to content

Commit

Permalink
Merge pull request #373
Browse files Browse the repository at this point in the history
[Major] allow to load mocks on non-rpi systems
  • Loading branch information
eitch authored Aug 27, 2024
2 parents ab9eacf + 9822afa commit 8b886b2
Show file tree
Hide file tree
Showing 11 changed files with 11 additions and 28 deletions.
18 changes: 0 additions & 18 deletions pi4j-core/src/main/java/com/pi4j/Pi4J.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,31 +63,13 @@ public static ContextBuilder newContextBuilder() {
* state and lifecycle. This 'Context' instance will automatically
* load all detected 'Platforms' and 'Providers' that are detected
* in the application's class-path.</p>
*
* <p>This method does not allow mock plugins to be used. If this is required, e.g. for testing then use {@link #newAutoContextAllowMocks()}</p>
*
* @return Context
*/
public static Context newAutoContext() {
logger.info("New auto context");
return newContextBuilder().autoDetect().build();
}

/**
* <p>Returns a new 'Context' instance which represents the Pi4J runtime
* state and lifecycle. This 'Context' instance will automatically
* load all detected 'Platforms' and 'Providers' that are detected
* in the application's class-path.</p>
*
* <p>In contrast to {@link #newAutoContext()} this method will allow mocks to be added to the runtime.</p>
*
* @return Context
*/
public static Context newAutoContextAllowMocks() {
logger.info("New auto context");
return newContextBuilder().autoDetect().autoDetectMockPlugins().build();
}

/**
* Returns a new empty 'Context' instance which represents the Pi4J
* runtime state and lifecycle. This empty 'Context' will not contain
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
* #L%
*/

import com.pi4j.boardinfo.util.BoardInfoHelper;
import com.pi4j.context.Context;
import com.pi4j.context.ContextBuilder;
import com.pi4j.context.ContextConfig;
Expand All @@ -50,7 +51,7 @@ public class DefaultContextBuilder implements ContextBuilder {
protected Logger logger = LoggerFactory.getLogger(DefaultContextBuilder.class);

// auto detection flags
protected boolean autoDetectMockPlugins = false;
protected boolean autoDetectMockPlugins = !BoardInfoHelper.runningOnRaspberryPi();
protected boolean autoDetectPlatforms = false;
protected boolean autoDetectProviders = false;
protected boolean autoInject = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public void beforeTest() throws Pi4JException {
// An auto context includes AUTO-DETECT BINDINGS enabled
// which will load all detected Pi4J extension libraries
// (Platforms and Providers) in the class path
pi4j = Pi4J.newAutoContextAllowMocks();
pi4j = Pi4J.newAutoContext();
}

@AfterAll
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public void beforeTest() throws Pi4JException {
// An auto context enabled AUTO-DETECT loading
// which will load any detected Pi4J extension
// libraries (Platforms and Providers) from the class path
pi4j = Pi4J.newAutoContextAllowMocks();
pi4j = Pi4J.newAutoContext();
}

@AfterEach
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public void beforeTest() throws Pi4JException {
// An auto context enabled AUTO-DETECT loading
// which will load any detected Pi4J extension
// libraries (Platforms and Providers) from the class path
pi4j = Pi4J.newAutoContextAllowMocks();
pi4j = Pi4J.newAutoContext();
}

@AfterAll
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public void beforeTest() throws Pi4JException {
// An auto context enabled AUTO-DETECT loading
// which will load any detected Pi4J extension
// libraries (Platforms and Providers) from the class path
pi4j = Pi4J.newAutoContextAllowMocks();
pi4j = Pi4J.newAutoContext();
}

@AfterEach
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void beforeTest() throws Pi4JException {
// An auto context includes AUTO-DETECT BINDINGS enabled
// which will load all detected Pi4J extension libraries
// (Platforms and Providers) in the class path
pi4j = Pi4J.newAutoContextAllowMocks();
pi4j = Pi4J.newAutoContext();
}

@AfterAll
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public void beforeTest() {
// An auto context includes AUTO-DETECT BINDINGS enabled
// which will load all detected Pi4J extension libraries
// (Platforms and Providers) in the class path
pi4j = Pi4J.newAutoContextAllowMocks();
pi4j = Pi4J.newAutoContext();
}

@AfterAll
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public void beforeTest() throws Pi4JException {
// An auto context includes AUTO-DETECT BINDINGS enabled
// which will load all detected Pi4J extension libraries
// (Platforms and Providers) in the class path
pi4j = Pi4J.newAutoContextAllowMocks();
pi4j = Pi4J.newAutoContext();
}

@AfterAll
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void beforeTest() throws Pi4JException {
// An auto context includes AUTO-DETECT BINDINGS enabled
// which will load all detected Pi4J extension libraries
// (Platforms and Providers) in the class path
pi4j = Pi4J.newAutoContextAllowMocks();
pi4j = Pi4J.newAutoContext();
}

@AfterAll
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void testRuntimeShutdownEvents() throws Pi4JException {
// An auto context includes AUTO-DETECT BINDINGS enabled
// which will load all detected Pi4J extension libraries
// (Platforms and Providers) in the class path
Context pi4j = Pi4J.newAutoContextAllowMocks();
Context pi4j = Pi4J.newAutoContext();

logger.info("-------------------------------------------------");
logger.info("Pi4J CONTEXT <acquired via factory accessor>");
Expand Down

0 comments on commit 8b886b2

Please sign in to comment.