mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-12-21 05:50:18 +08:00
Fixes failing of test when Hastebin is not available
This commit is contained in:
parent
2a12e93ef7
commit
44fcb9ec7b
@ -66,7 +66,7 @@ public class Hastebin {
|
||||
* @param content The content
|
||||
* @return The link to the content
|
||||
*/
|
||||
private static String upload(String content) throws IOException, ParseException {
|
||||
public static String upload(String content) throws IOException, ParseException {
|
||||
HttpsURLConnection connection = null;
|
||||
try {
|
||||
URL url = new URL("https://hastebin.com/documents");
|
||||
|
@ -4,6 +4,8 @@ import com.google.common.collect.Iterables;
|
||||
import main.java.com.djrapitops.plan.Log;
|
||||
import main.java.com.djrapitops.plan.utilities.file.dump.Hastebin;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.json.simple.parser.ParseException;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.powermock.core.classloader.annotations.PowerMockIgnore;
|
||||
@ -12,6 +14,9 @@ import org.powermock.modules.junit4.PowerMockRunner;
|
||||
import test.java.utils.RandomData;
|
||||
import test.java.utils.TestInit;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import static junit.framework.TestCase.assertEquals;
|
||||
import static junit.framework.TestCase.assertNotNull;
|
||||
|
||||
@ -23,11 +28,44 @@ import static junit.framework.TestCase.assertNotNull;
|
||||
@PrepareForTest(JavaPlugin.class)
|
||||
public class HastebinTest {
|
||||
|
||||
private String content = RandomData.randomString(400000);
|
||||
private AtomicBoolean hastebinAvailable = new AtomicBoolean();
|
||||
|
||||
@Before
|
||||
public void checkAvailability() throws Exception {
|
||||
TestInit.init();
|
||||
|
||||
Thread thread = new Thread(() -> {
|
||||
String link = null;
|
||||
try {
|
||||
link = Hastebin.upload(RandomData.randomString(10));
|
||||
} catch (IOException e) {
|
||||
if (e.getMessage().contains("503")) {
|
||||
hastebinAvailable.set(false);
|
||||
return;
|
||||
}
|
||||
} catch (ParseException e) {
|
||||
/* Ignored */
|
||||
}
|
||||
|
||||
if (link == null) {
|
||||
hastebinAvailable.set(false);
|
||||
}
|
||||
|
||||
Log.info("Availability Test Link: " + link);
|
||||
});
|
||||
|
||||
try {
|
||||
thread.join(5000);
|
||||
} catch (InterruptedException e) {
|
||||
hastebinAvailable.set(false);
|
||||
}
|
||||
|
||||
Log.info("Hastebin Available: " + hastebinAvailable.get());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSplitting() {
|
||||
Iterable<String> parts = Hastebin.split(content);
|
||||
Iterable<String> parts = Hastebin.split(RandomData.randomString(500000));
|
||||
|
||||
int expPartCount = 2;
|
||||
int partCount = Iterables.size(parts);
|
||||
@ -37,10 +75,13 @@ public class HastebinTest {
|
||||
|
||||
@Test
|
||||
public void testUpload() throws Exception {
|
||||
if (!hastebinAvailable.get()) {
|
||||
return;
|
||||
}
|
||||
|
||||
TestInit.init();
|
||||
|
||||
String link = Hastebin.safeUpload(content);
|
||||
|
||||
String link = Hastebin.safeUpload(RandomData.randomString(10));
|
||||
assertNotNull(link);
|
||||
|
||||
Log.info("Hastebin Link: " + link);
|
||||
|
Loading…
Reference in New Issue
Block a user