-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
123 additions
and
0 deletions.
There are no files selected for viewing
96 changes: 96 additions & 0 deletions
96
pi4micronaut-utils/src/test/java/com/opensourcewithslu/inputdevices/MockDigitalInput.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
package com.opensourcewithslu.inputdevices; | ||
import com.pi4j.common.Metadata; | ||
import com.pi4j.context.Context; | ||
import com.pi4j.exception.InitializeException; | ||
import com.pi4j.exception.ShutdownException; | ||
import com.pi4j.io.binding.DigitalBinding; | ||
import com.pi4j.io.gpio.digital.*; | ||
|
||
public class MockDigitalInput implements DigitalInput { | ||
DigitalState mockState; | ||
public MockDigitalInput(){ | ||
mockState = DigitalState.UNKNOWN; | ||
} | ||
public void SetState(DigitalState fakeState) { | ||
mockState = fakeState; | ||
} | ||
@Override | ||
public DigitalState state() { | ||
return mockState; | ||
} | ||
|
||
@Override | ||
public DigitalInput addListener(DigitalStateChangeListener... digitalStateChangeListeners) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public DigitalInput removeListener(DigitalStateChangeListener... digitalStateChangeListeners) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public boolean isOn() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public DigitalInput bind(DigitalBinding... digitalBindings) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public DigitalInput unbind(DigitalBinding... digitalBindings) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public DigitalInputConfig config() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public DigitalInput name(String s) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public DigitalInput description(String s) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public DigitalInputProvider provider() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public String id() { | ||
return ""; | ||
} | ||
|
||
@Override | ||
public String name() { | ||
return ""; | ||
} | ||
|
||
@Override | ||
public String description() { | ||
return ""; | ||
} | ||
|
||
@Override | ||
public Metadata metadata() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public Object initialize(Context context) throws InitializeException { | ||
return null; | ||
} | ||
|
||
@Override | ||
public Object shutdown(Context context) throws ShutdownException { | ||
return null; | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...cronaut-utils/src/test/java/com/opensourcewithslu/inputdevices/PushButtonHelperTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.opensourcewithslu.inputdevices; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
import com.pi4j.io.gpio.digital.*; | ||
|
||
class PushButtonHelperTests { | ||
|
||
@org.junit.jupiter.api.Test | ||
void initializeStateLow() { | ||
MockDigitalInput input = new MockDigitalInput(); | ||
input.SetState(DigitalState.LOW); | ||
PushButtonHelper helper = new PushButtonHelper(input); | ||
assertFalse(helper.isPressed); | ||
} | ||
|
||
@org.junit.jupiter.api.Test | ||
void initializeStateHigh() { | ||
MockDigitalInput input = new MockDigitalInput(); | ||
input.SetState(DigitalState.HIGH); | ||
PushButtonHelper helper = new PushButtonHelper(input); | ||
assertTrue(helper.isPressed); | ||
} | ||
|
||
@org.junit.jupiter.api.Test | ||
void addEventListener() { | ||
} | ||
} |