Skip to content

Commit

Permalink
Fixed log verification test and moved test to new folder to keep cons…
Browse files Browse the repository at this point in the history
…istent structure.
  • Loading branch information
leandrumartin committed Sep 22, 2024
1 parent 4a96fb4 commit 8253fac
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*
*/
public class LEDHelper {
private static final Logger log = LoggerFactory.getLogger(LEDHelper.class);
private static Logger log = LoggerFactory.getLogger(LEDHelper.class);

private final DigitalOutput ledOutput;

Expand Down Expand Up @@ -82,4 +82,13 @@ public void blink (int duration) {

ledOutput.blink(duration, TimeUnit.MILLISECONDS);
}

/**
* Sets the logger object.
*
* @param log Logger object to set the logger to.
*/
public void setLog(Logger log) {
this.log = log;
}
}
Original file line number Diff line number Diff line change
@@ -1,38 +1,21 @@
package com.opensourcewithslu;
package com.opensourcewithslu.outputdevices;

import com.pi4j.io.gpio.digital.DigitalOutput;
import org.junit.jupiter.api.*;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.mockito.Spy;
import org.slf4j.Logger;

import java.util.concurrent.TimeUnit;

import static org.mockito.Mockito.*;

import com.opensourcewithslu.outputdevices.LEDHelper;

class LEDHelperTest {
@Mock
// @Spy
Logger log;
@Mock
DigitalOutput ledOutput;
@InjectMocks
LEDHelper ledHelper;

private AutoCloseable closeable;
DigitalOutput ledOutput = mock(DigitalOutput.class);
LEDHelper ledHelper = new LEDHelper(ledOutput);
Logger log = mock(Logger.class);

@BeforeEach
public void openMocks() {
closeable = MockitoAnnotations.openMocks(this);
}

@AfterEach
public void releaseMocks() throws Exception {
closeable.close();
ledHelper.setLog(log);
}

@Test
Expand Down

0 comments on commit 8253fac

Please sign in to comment.