-
-
Notifications
You must be signed in to change notification settings - Fork 109
Unit Tests for Metrics #1439
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
firasrg
wants to merge
6
commits into
develop
Choose a base branch
from
firasrg/setting-analytics-tests
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+78
−5
Open
Unit Tests for Metrics #1439
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c75dc22
Adding a first unit test for Metrics with logging
firasrg 7ba857d
Merge remote-tracking branch 'origin/develop' into firasrg/setting-an…
firasrg 29bc42e
Updates metrics test: using doAsync flag to check event persistence o…
firasrg 7b7a676
Metrics: revert access modifier for processEvent from package-private…
firasrg 356f566
Merge remote-tracking branch 'origin/develop' into firasrg/setting-an…
firasrg 7d11240
Metrics Unit test work reviewed
firasrg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
57 changes: 57 additions & 0 deletions
57
application/src/test/java/org/togetherjava/tjbot/features/analytics/MetricsTests.java
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| package org.togetherjava.tjbot.features.analytics; | ||
|
|
||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import org.togetherjava.tjbot.db.Database; | ||
| import org.togetherjava.tjbot.db.generated.tables.MetricEvents; | ||
| import org.togetherjava.tjbot.db.generated.tables.records.MetricEventsRecord; | ||
|
|
||
| import java.time.Duration; | ||
| import java.time.Instant; | ||
| import java.util.Map; | ||
| import java.util.Objects; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
|
||
| final class MetricsTests { | ||
| private Database database; | ||
| private Metrics metrics; | ||
|
|
||
| @BeforeEach | ||
| void setUp() { | ||
| database = Database.createMemoryDatabase(MetricEvents.METRIC_EVENTS); | ||
| metrics = new Metrics(database); | ||
| } | ||
|
|
||
| @Test | ||
| void countWithDoAsyncFalsePersists() { | ||
|
|
||
| String expectedEvent = "test-event"; | ||
|
|
||
| Instant expectedHappenedAt = Instant.now(); | ||
|
|
||
| metrics.count(expectedEvent, Map.of(), false); | ||
|
|
||
| MetricEventsRecord eventRecord = Objects.requireNonNull( | ||
| database.read(context -> context.selectFrom(MetricEvents.METRIC_EVENTS).fetchOne()), | ||
| "event not found"); | ||
|
|
||
| Instant actualHappenedAt = eventRecord.getHappenedAt(); | ||
|
|
||
| assertEquals(expectedEvent, eventRecord.getEvent()); | ||
| assertCloseEnough(expectedHappenedAt, actualHappenedAt); | ||
| } | ||
|
|
||
| private void assertCloseEnough(Instant expectedHappenedAt, Instant actualHappenedAt) { | ||
|
|
||
| Duration thresholdDuration = Duration.ofMinutes(1); | ||
|
|
||
| Duration actualDuration = Duration.between(expectedHappenedAt, actualHappenedAt); | ||
|
|
||
| boolean isBelowThreshold = actualDuration.compareTo(thresholdDuration) < 0; | ||
|
|
||
| assertTrue(isBelowThreshold); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please dont change the javadoc, it was this:
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was absolutely no javadocThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was. The method that was previously public facing is now not public facing anymore and the method you made public facing has a different, less detailled, javadoc:

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright then, all i have to do is to make the new one has better javadoc and done