Created
July 15, 2019 11:17
-
-
Save nucatus/6b4b7d2d62100c97987f94a743877564 to your computer and use it in GitHub Desktop.
Asserting times
This file contains hidden or 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
package spcx.octopus.test; | |
import org.apache.commons.lang3.StringUtils; | |
import org.assertj.core.api.Assertions; | |
import org.junit.Assert; | |
import org.junit.Test; | |
import org.slf4j.Logger; | |
import java.time.Instant; | |
import static org.slf4j.LoggerFactory.getLogger; | |
public class AssertTimeTests | |
{ | |
private static final Logger LOG = getLogger( AssertTimeTests.class ); | |
public static final int LEFT_PADDING_SIZE = 70; | |
@Test | |
public void assertTimeTest() | |
{ | |
TestValues t1 = TestValues.SCREW; | |
long startMillis = Instant.now().toEpochMilli(); | |
Assert.assertEquals( t1, TestValues.SCREW ); | |
LOG.debug( "Evaluation {} took {}ms", | |
StringUtils.leftPad( | |
"org.junit.Assert.assertEquals", | |
LEFT_PADDING_SIZE ), | |
Instant.now().toEpochMilli() - startMillis ); | |
startMillis = Instant.now().toEpochMilli(); | |
Assert.assertNotEquals( t1, TestValues.DRIVER ); | |
LOG.debug( "Evaluation {} took {}ms", | |
StringUtils.leftPad( | |
"org.junit.Assert.assertNotEquals", | |
LEFT_PADDING_SIZE ), | |
Instant.now().toEpochMilli() - startMillis ); | |
startMillis = Instant.now().toEpochMilli(); | |
Assertions.assertThat( t1 ).isEqualTo( TestValues.SCREW ); | |
LOG.debug( "Evaluation {} took {}ms", | |
StringUtils.leftPad( | |
"org.assertj.core.api.Assertions.assertThat(T).isEqualTo(T)", | |
LEFT_PADDING_SIZE ), | |
Instant.now().toEpochMilli() - startMillis ); | |
startMillis = Instant.now().toEpochMilli(); | |
Assertions.assertThat( t1 ).isNotEqualTo( TestValues.DRIVER ); | |
LOG.debug( "Evaluation {} took {}ms", | |
StringUtils.leftPad( | |
"org.assertj.core.api.Assertions.assertThat(T).isNotEqualTo(T)", | |
LEFT_PADDING_SIZE ), | |
Instant.now().toEpochMilli() - startMillis ); | |
startMillis = Instant.now().toEpochMilli(); | |
assert t1 == TestValues.SCREW; | |
LOG.debug( "Evaluation {} took {}ms", | |
StringUtils.leftPad( | |
"java.lang.assert ==", | |
LEFT_PADDING_SIZE ), | |
Instant.now().toEpochMilli() - startMillis ); | |
startMillis = Instant.now().toEpochMilli(); | |
assert t1 != TestValues.DRIVER; | |
LOG.debug( "Evaluation {} took {}ms", | |
StringUtils.leftPad( | |
"java.lang.assert !=", | |
LEFT_PADDING_SIZE ), | |
Instant.now().toEpochMilli() - startMillis ); | |
} | |
enum TestValues | |
{ | |
SCREW, DRIVER | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment