Skip to content

Commit

Permalink
✅ add tests for DefaultBlueSkyLoader #23
Browse files Browse the repository at this point in the history
  • Loading branch information
McPringle committed Nov 30, 2024
1 parent 779a7f0 commit 8ab9363
Showing 1 changed file with 51 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Apus - A social wall for conferences with additional features.
* Copyright (C) Marcus Fihlon and the individual contributors to Apus.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package swiss.fihlon.apus.plugin.social.bluesky;

import org.json.JSONArray;
import org.junit.jupiter.api.Test;
import social.bigbone.api.entity.Status;
import swiss.fihlon.apus.plugin.social.mastodon.DefaultMastodonLoader;
import swiss.fihlon.apus.plugin.social.mastodon.MastodonException;

import java.util.List;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;

class DefaultBlueSkyLoaderTest {

@Test
void getPosts() throws BlueSkyException {
final JSONArray jsonPosts = new DefaultBlueSkyLoader()
.getPosts("public.api.bsky.app", "java", "https://%s/xrpc/app.bsky.feed.searchPosts?q=%s");
assertNotNull(jsonPosts);
assertFalse(jsonPosts.isEmpty());
}

@Test
void throwException() {
final var exception = assertThrows(BlueSkyException.class,
() -> new DefaultBlueSkyLoader()
.getPosts("non.existent.server", "java", "https://%s/xrpc/app.bsky.feed.searchPosts?q=%s"));
assertEquals("Unable to load posts with hashtag 'java' from BlueSky instance 'non.existent.server'", exception.getMessage());
}

}

0 comments on commit 8ab9363

Please sign in to comment.