Last active
May 18, 2024 15:03
-
-
Save mferoc/998079faeefb7906bb6a00a633b8a35f to your computer and use it in GitHub Desktop.
atividade-pos-ufscar-test-de.danoeh.antennapod.model.download
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
package de.danoeh.antennapod.model.download; | |
import org.junit.Assert; | |
import org.junit.Test; | |
public class DownloadErrorTest { | |
@Test | |
public void test_DownloadError_retorna_codigo_sucesso() { | |
var successCode = DownloadError.SUCCESS.getCode(); | |
var downloadError = DownloadError.fromCode(successCode); | |
Assert.assertEquals(DownloadError.SUCCESS, downloadError); | |
} | |
@Test | |
public void test_DownloadError_retorna_codigo_erro() { | |
Assert.assertThrows( | |
IllegalArgumentException.class, | |
() -> DownloadError.fromCode(99) | |
); | |
} | |
} |
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
package de.danoeh.antennapod.model.download; | |
import static org.junit.Assert.assertEquals; | |
import static org.junit.Assert.assertFalse; | |
import static org.junit.Assert.assertNotNull; | |
import static org.junit.Assert.assertTrue; | |
import org.junit.Before; | |
import org.junit.Test; | |
import java.util.Date; | |
import de.danoeh.antennapod.model.feed.Feed; | |
import de.danoeh.antennapod.model.feed.FeedFile; | |
public class DownloadResultTest { | |
private DownloadResult downloadResult; | |
private DownloadResult downloadResultWithId; | |
private final String title = "Test Title"; | |
private long feedfileId; | |
private int feedfileType; | |
private final long id = 1L; | |
private final DownloadError reason = DownloadError.ERROR_DOWNLOAD_CANCELLED; | |
private final boolean successful = false; | |
private final String reasonDetailed = "Test Reason Detailed"; | |
private final Date completionDate = new Date(); | |
@Before | |
public void setUp() { | |
FeedFile feedFile = new Feed(); | |
feedfileId = feedFile.getId(); | |
feedfileType = feedFile.getTypeAsInt(); | |
downloadResult = new DownloadResult(feedFile, title, reason, successful, reasonDetailed); | |
downloadResultWithId = new DownloadResult(id, title, feedfileId, feedfileType, successful, reason, completionDate, reasonDetailed); | |
} | |
@Test | |
public void test_ConstructorWithFeedFile_sucesso() { | |
assertEquals(title, downloadResult.getTitle()); | |
assertEquals(feedfileId, downloadResult.getFeedfileId()); | |
assertEquals(feedfileType, downloadResult.getFeedfileType()); | |
assertEquals(reason, downloadResult.getReason()); | |
assertEquals(successful, downloadResult.isSuccessful()); | |
assertNotNull(downloadResult.getCompletionDate()); | |
assertEquals(reasonDetailed, downloadResult.getReasonDetailed()); | |
} | |
@Test | |
public void test_ConstructorWithAllFields_sucesso() { | |
assertEquals(id, downloadResultWithId.getId()); | |
assertEquals(title, downloadResultWithId.getTitle()); | |
assertEquals(feedfileId, downloadResultWithId.getFeedfileId()); | |
assertEquals(feedfileType, downloadResultWithId.getFeedfileType()); | |
assertEquals(reason, downloadResultWithId.getReason()); | |
assertEquals(successful, downloadResultWithId.isSuccessful()); | |
assertEquals(completionDate, downloadResultWithId.getCompletionDate()); | |
assertEquals(reasonDetailed, downloadResultWithId.getReasonDetailed()); | |
} | |
@Test | |
public void test_SetId() { | |
downloadResult.setId(2L); | |
assertEquals(2L, downloadResult.getId()); | |
} | |
@Test | |
public void test_SetSuccessful() { | |
downloadResult.setSuccessful(); | |
assertTrue(downloadResult.isSuccessful()); | |
assertEquals(DownloadError.SUCCESS, downloadResult.getReason()); | |
} | |
@Test | |
public void test_SetFailed() { | |
downloadResult.setFailed(DownloadError.ERROR_DOWNLOAD_CANCELLED, "Failed for testing"); | |
assertFalse(downloadResult.isSuccessful()); | |
assertEquals(DownloadError.ERROR_DOWNLOAD_CANCELLED, downloadResult.getReason()); | |
assertEquals("Failed for testing", downloadResult.getReasonDetailed()); | |
} | |
@Test | |
public void test_SetCancelled() { | |
downloadResult.setCancelled(); | |
assertFalse(downloadResult.isSuccessful()); | |
assertEquals(DownloadError.ERROR_DOWNLOAD_CANCELLED, downloadResult.getReason()); | |
} | |
@Test | |
public void test_ToString() { | |
String expectedString = "DownloadStatus [id=" + downloadResultWithId.getId() + ", title=" + downloadResultWithId.getTitle() + ", reason=" | |
+ downloadResultWithId.getReason() + ", reasonDetailed=" + downloadResultWithId.getReasonDetailed() | |
+ ", successful=" + downloadResultWithId.isSuccessful() + ", completionDate=" + downloadResultWithId.getCompletionDate() | |
+ ", feedfileId=" + downloadResultWithId.getFeedfileId() + ", feedfileType=" + downloadResultWithId.getFeedfileType() + "]"; | |
assertEquals(expectedString, downloadResultWithId.toString()); | |
} | |
} |
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
package de.danoeh.antennapod.model.download; | |
import org.junit.Assert; | |
import org.junit.Test; | |
public class DownloadStatusTest { | |
@Test | |
public void test_DownloadStatus_deve_retornar_sucesso() { | |
int state = DownloadStatus.STATE_RUNNING; | |
int progress = 42; | |
var downloadStatus = new DownloadStatus(state, progress); | |
Assert.assertEquals(state, downloadStatus.getState()); | |
Assert.assertEquals(progress, downloadStatus.getProgress()); | |
} | |
} |
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
package de.danoeh.antennapod.model.download; | |
import static org.junit.Assert.assertEquals; | |
import org.junit.Test; | |
import java.net.Proxy; | |
public class ProxyConfigTest { | |
@Test | |
public void test_ProxyConfig_deve_retornar_sucesso() { | |
Proxy.Type proxyType = Proxy.Type.HTTP; | |
String host = "http://localhost"; | |
int port = ProxyConfig.DEFAULT_PORT; | |
String username = "test-user"; | |
String password = "testpassword123"; | |
var proxyConfig = new ProxyConfig( | |
proxyType, | |
host, | |
port, | |
username, | |
password | |
); | |
assertEquals(proxyType, proxyConfig.type); | |
assertEquals(host, proxyConfig.host); | |
assertEquals(port, proxyConfig.port); | |
assertEquals(username, proxyConfig.username); | |
assertEquals(password, proxyConfig.password); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment