Skip to content

Commit

Permalink
SOLR-17618: Incorporate feedback from review
Browse files Browse the repository at this point in the history
* Add @test annotations
* Move repeated mock setup to Before method
  • Loading branch information
sandbergja committed Jan 12, 2025
1 parent 51f7b0c commit c445b5a
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions solr/core/src/test/org/apache/solr/util/TimeOutTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,42 +23,41 @@
import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.common.util.TimeSource;
import org.junit.BeforeClass;
import org.junit.Test;

public class TimeOutTest extends SolrTestCaseJ4 {
private static TimeSource mockTimeSource;

@BeforeClass
public static void setUpOnce() {
assumeWorkingMockito();
mockTimeSource = mock(TimeSource.class);
}

@Test
public void testHasTimedOut() {
TimeSource mockTimeSource = mock(TimeSource.class);
when(mockTimeSource.getTimeNs()).thenReturn(Long.valueOf(10)).thenReturn(Long.valueOf(50));

TimeOut timeOut = new TimeOut(20, NANOSECONDS, mockTimeSource);
assertTrue(timeOut.hasTimedOut());
}

@Test
public void testHasNotTimedOut() {
TimeSource mockTimeSource = mock(TimeSource.class);
when(mockTimeSource.getTimeNs()).thenReturn(Long.valueOf(10)).thenReturn(Long.valueOf(11));

TimeOut timeOut = new TimeOut(20, NANOSECONDS, mockTimeSource);
assertFalse(timeOut.hasTimedOut());
}

@Test
public void testTimeLeft() {
TimeSource mockTimeSource = mock(TimeSource.class);
when(mockTimeSource.getTimeNs()).thenReturn(Long.valueOf(10)).thenReturn(Long.valueOf(15));

TimeOut timeOut = new TimeOut(90, NANOSECONDS, mockTimeSource);
assertEquals(timeOut.timeLeft(NANOSECONDS), 85);
}

@Test
public void testTimeElapsed() {
TimeSource mockTimeSource = mock(TimeSource.class);
when(mockTimeSource.getTimeNs()).thenReturn(Long.valueOf(10)).thenReturn(Long.valueOf(25));

TimeOut timeOut = new TimeOut(70, NANOSECONDS, mockTimeSource);
assertEquals(timeOut.timeElapsed(NANOSECONDS), 15);
}
Expand Down

0 comments on commit c445b5a

Please sign in to comment.