Skip to content

Commit

Permalink
Adds a mock tweeter implementation
Browse files Browse the repository at this point in the history
Signed-off-by: Patrick Reinhart <[email protected]>
  • Loading branch information
reinhapa committed Oct 9, 2024
1 parent 4ddf0cd commit 7f3a225
Show file tree
Hide file tree
Showing 15 changed files with 1,149 additions and 0 deletions.
14 changes: 14 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,20 @@ updates:
directory: "/tweet-impl-mastodon4j"
# Raise pull requests for version updates on `master` branch
target-branch: "master"
schedule:
interval: "daily"
# Check for npm updates at 0815hrs UTC
time: "08:15"
reviewers:
- "TweetWallFX/tweetwallfx-admins"
# Allow up to N open pull requests (independant of source)
open-pull-requests-limit: 50

- package-ecosystem: "gradle"
# Any gradle based dependencies
directory: "/tweet-impl-mock"
# Raise pull requests for version updates on `master` branch
target-branch: "master"
schedule:
interval: "daily"
# Check for npm updates at 0815hrs UTC
Expand Down
1 change: 1 addition & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ includeWithName ':transitions', 'tweetwallfx-transitions'
includeWithName ':tweet-api', 'tweetwallfx-tweet-api'
includeWithName ':tweet-impl-twitter4j', 'tweetwallfx-tweet-impl-twitter4j'
includeWithName ':tweet-impl-mastodon4j', 'tweetwallfx-tweet-impl-mastodon4j'
includeWithName ':tweet-impl-mock', 'tweetwallfx-tweet-impl-mock'
includeWithName ':mqtt', 'tweetwallfx-mqtt'
includeWithName ':util', 'tweetwallfx-utility'

Expand Down
3 changes: 3 additions & 0 deletions spotbugs-exclude.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
<Class name="org.tweetwallfx.stepengine.steps.PauseStep$Config" />
<Class name="org.tweetwallfx.stepengine.steps.visual.HideAction$Config" />
<Class name="org.tweetwallfx.stepengine.steps.visual.ShowAction$Config" />
<Class name="org.tweetwallfx.tweet.impl.mock.config.MockSettings" />
<Class name="org.tweetwallfx.tweet.impl.mock.MockPost" />
<Class name="org.tweetwallfx.tweet.StringPropertyAppender" />
<Package name="org.tweetwallfx.devoxx.api.cfp.client" />
</Or>
Expand All @@ -61,6 +63,7 @@
<Class name="org.tweetwallfx.transitions.FlipOutXTransition" />
<Class name="org.tweetwallfx.transitions.FontSizeTransition" />
<Class name="org.tweetwallfx.transitions.LocationTransition" />
<Class name="org.tweetwallfx.tweet.impl.mock.MockPost" />
<Class name="org.tweetwallfx.twod.TagTweets" />
<Package name="org.tweetwallfx.devoxx.api.cfp.client" />
</Or>
Expand Down
33 changes: 33 additions & 0 deletions tweet-impl-mock/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2024 TweetWallFX
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

dependencies {
api project(':tweetwallfx-tweet-api')

implementation 'net.datafaker:datafaker:2.2.2'
implementation 'org.jsoup:jsoup:1.17.2'
implementation 'org.slf4j:slf4j-api'

testRuntimeOnly 'org.simplify4u:slf4j2-mock'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2024 TweetWallFX
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.tweetwallfx.tweet.impl.mock;

import org.tweetwallfx.tweet.api.Tweet;
import org.tweetwallfx.tweet.api.User;
import org.tweetwallfx.tweet.api.entry.EmojiTweetEntry;
import org.tweetwallfx.tweet.api.entry.HashtagTweetEntry;
import org.tweetwallfx.tweet.api.entry.MediaTweetEntry;
import org.tweetwallfx.tweet.api.entry.SymbolTweetEntry;
import org.tweetwallfx.tweet.api.entry.UrlTweetEntry;
import org.tweetwallfx.tweet.api.entry.UserMentionTweetEntry;

import java.time.LocalDateTime;
import java.util.List;

public record MockPost(long id, String text, User user, LocalDateTime created,
Tweet originPost,
int favoriteCount, int repostCount,
List<MediaTweetEntry> mediaTweetEntries) implements Tweet {

public MockPost(long id, String text, User user, LocalDateTime created,
Tweet originPost,
int favoriteCount, int repostCount,
MediaTweetEntry... mediaTweetEntries) {
this(id, text, user, created, originPost, favoriteCount, repostCount, List.of(mediaTweetEntries));
}

@Override
public Tweet originPost() {
return originPost;
}

@Override
public LocalDateTime getCreatedAt() {
return created;
}

@Override
public int getFavoriteCount() {
return favoriteCount;
}

@Override
public long getId() {
return id;
}

@Override
public long getInReplyToTweetId() {
return 0;
}

@Override
public long getInReplyToUserId() {
return 0;
}

@Override
public String getInReplyToScreenName() {
return null; //TODO
}

@Override
public String getLang() {
return null; //TODO
}

@Override
public int getRetweetCount() {
return repostCount;
}

@Override
public Tweet getRetweetedTweet() {
return null; //TODO
}

@Override
public Tweet getOriginTweet() {
if (originPost != null) {
return originPost;
}
return this;
}

@Override
public String getText() {
return text;
}

@Override
public User getUser() {
return user;
}

@Override
public boolean isRetweet() {
return originPost != null;
}

@Override
public boolean isTruncated() {
return false;
}

@Override
public HashtagTweetEntry[] getHashtagEntries() {
return new HashtagTweetEntry[0];
}

@Override
public MediaTweetEntry[] getMediaEntries() {
return mediaTweetEntries.toArray(MediaTweetEntry[]::new);
}

@Override
public SymbolTweetEntry[] getSymbolEntries() {
return new SymbolTweetEntry[0];
}

@Override
public UrlTweetEntry[] getUrlEntries() {
return new UrlTweetEntry[0];
}

@Override
public UserMentionTweetEntry[] getUserMentionEntries() {
return new UserMentionTweetEntry[0];
}

@Override
public EmojiTweetEntry[] getEmojiEntries() {
return Tweet.super.getEmojiEntries();
}

@Override
public String getDisplayEnhancedText() {
return Tweet.super.getDisplayEnhancedText();
}

@Override
public TextExtractor getDisplayEnhancedTextExtractor() {
return Tweet.super.getDisplayEnhancedTextExtractor();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2024 TweetWallFX
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.tweetwallfx.tweet.impl.mock;

import org.tweetwallfx.tweet.api.entry.MediaTweetEntry;
import org.tweetwallfx.tweet.api.entry.MediaTweetEntryType;

import java.util.Map;

public record MockPostMedia(long id, int with, int height) implements MediaTweetEntry {
@Override
public long getId() {
return id;
}

@Override
public String getMediaUrl() {
return STR."https://picsum.photos/id/\{id}/\{height}/\{with}";
}

@Override
public Map<Integer, Size> getSizes() {
return Map.of(0,
MediaTweetEntry.createSize(
with,
height,
1));
}

@Override
public MediaTweetEntryType getType() {
return MediaTweetEntryType.photo;
}

@Override
public String getText() {
return getMediaUrl();
}

@Override
public int getStart() {
return 0;
}

@Override
public int getEnd() {
return 0;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2024 TweetWallFX
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.tweetwallfx.tweet.impl.mock;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.tweetwallfx.tweet.api.Tweet;
import org.tweetwallfx.tweet.api.TweetStream;

import java.util.concurrent.CopyOnWriteArrayList;
import java.util.function.Consumer;

final class MockPostStream implements TweetStream, Consumer<Tweet> {
private static final Logger LOGGER = LoggerFactory.getLogger(MockPostStream.class);

private final CopyOnWriteArrayList<Consumer<Tweet>> consumers;

MockPostStream() {
consumers = new CopyOnWriteArrayList<>();
}

@Override
public void onTweet(Consumer<Tweet> tweetConsumer) {
LOGGER.debug("onTweet({})", tweetConsumer);
consumers.add(tweetConsumer);
}

@Override
public void accept(Tweet post) {
LOGGER.debug("Notify post:\n{}", post);
consumers.forEach(tweetConsumer -> tweetConsumer.accept(post));
}
}
Loading

0 comments on commit 7f3a225

Please sign in to comment.