Skip to content

Instantly share code, notes, and snippets.

@nucatus
Created July 15, 2019 11:17
Show Gist options
  • Save nucatus/6b4b7d2d62100c97987f94a743877564 to your computer and use it in GitHub Desktop.
Save nucatus/6b4b7d2d62100c97987f94a743877564 to your computer and use it in GitHub Desktop.
Asserting times
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