-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Patrick Reinhart <[email protected]>
- Loading branch information
Showing
15 changed files
with
1,149 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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,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' | ||
} |
167 changes: 167 additions & 0 deletions
167
tweet-impl-mock/src/main/java/org/tweetwallfx/tweet/impl/mock/MockPost.java
This file contains 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,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(); | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
tweet-impl-mock/src/main/java/org/tweetwallfx/tweet/impl/mock/MockPostMedia.java
This file contains 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,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; | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
tweet-impl-mock/src/main/java/org/tweetwallfx/tweet/impl/mock/MockPostStream.java
This file contains 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,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)); | ||
} | ||
} |
Oops, something went wrong.