-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
102 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.lgtoledo; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import com.lgtoledo.utils.CodeGenerator; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
public class CodeGeneratorTest { | ||
|
||
@Test | ||
public void testGenerateCode() { | ||
String code = CodeGenerator.generateCode(6); | ||
assertNotNull(code); | ||
assertEquals(6, code.length()); | ||
} | ||
|
||
@Test | ||
public void testGenerateCodeWithZeroLength() { | ||
String code = CodeGenerator.generateCode(0); | ||
assertNotNull(code); | ||
assertEquals("", code); | ||
} | ||
|
||
} |
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,77 @@ | ||
package com.lgtoledo; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import com.lgtoledo.utils.Utils; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.Optional; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
public class UtilsTest { | ||
|
||
@Test | ||
public void testIsValidUrl() { | ||
String longUrlRegex = "^https://.*$"; | ||
assertFalse(Utils.isValidUrl(Optional.of("http://www.mercadolibre.com"), longUrlRegex)); | ||
assertTrue(Utils.isValidUrl(Optional.of("https://www.mercadolibre.com"), longUrlRegex)); | ||
assertFalse(Utils.isValidUrl(Optional.of("www.mercadolibre.com"), longUrlRegex)); | ||
assertFalse(Utils.isValidUrl(Optional.of("http://www.mercadolibre"), longUrlRegex)); | ||
assertFalse(Utils.isValidUrl(Optional.of("http://www.mercadolibre."), longUrlRegex)); | ||
assertFalse(Utils.isValidUrl(Optional.of("http://www.mercadolibre.com/"), longUrlRegex)); | ||
assertFalse(Utils.isValidUrl(Optional.empty(), longUrlRegex)); | ||
} | ||
|
||
@Test | ||
public void testExtractLastPart() { | ||
String shortUrl = "http://localhost:8080/abc123"; | ||
String lastPart = Utils.extractLastPart(shortUrl); | ||
assertEquals("abc123", lastPart); | ||
} | ||
|
||
@Test | ||
public void testGetCurrentUtcDateTime() { | ||
LocalDateTime dateTime = Utils.getCurrentUtcDateTime(); | ||
assertNotNull(dateTime); | ||
} | ||
|
||
@Test | ||
public void testValidShortLink() { | ||
String baseUrl = "https://short.link"; | ||
assertTrue(Utils.isShortLinkValid(baseUrl, "https://short.link/l/abc123")); | ||
} | ||
|
||
@Test | ||
public void testInvalidShortLinkWrongLength() { | ||
String baseUrl = "https://short.link"; | ||
assertFalse(Utils.isShortLinkValid(baseUrl, "https://short.link/l/abc12345")); | ||
} | ||
|
||
@Test | ||
public void testInvalidShortLinkWrongChars() { | ||
String baseUrl = "https://short.link"; | ||
assertFalse(Utils.isShortLinkValid(baseUrl, "https://short.link/l/abc_!@")); | ||
} | ||
|
||
@Test | ||
public void testInvalidShortLinkWithoutL() { | ||
String baseUrl = "https://short.link"; | ||
assertFalse(Utils.isShortLinkValid(baseUrl, "https://short.link/abc123")); | ||
} | ||
|
||
// test if short link is null | ||
@Test | ||
public void testInvalidShortLinkNull() { | ||
String baseUrl = "https://short.link"; | ||
assertFalse(Utils.isShortLinkValid(baseUrl, null)); | ||
} | ||
|
||
// test if short link is empty | ||
@Test | ||
public void testInvalidShortLinkEmpty() { | ||
String baseUrl = "https://short.link"; | ||
assertFalse(Utils.isShortLinkValid(baseUrl, "")); | ||
} | ||
|
||
} |