-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGitHubMapperPropertyTest.java
More file actions
48 lines (40 loc) · 1.77 KB
/
Copy pathGitHubMapperPropertyTest.java
File metadata and controls
48 lines (40 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package net.lecigne.deezerdatasync.adapters.out.github;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.List;
import java.util.regex.Pattern;
import net.jqwik.api.ForAll;
import net.jqwik.api.Label;
import net.jqwik.api.Property;
import net.jqwik.api.constraints.StringLength;
import net.lecigne.deezerdatasync.domain.common.DeezerData;
import net.lecigne.deezerdatasync.domain.playlist.Playlist;
import net.lecigne.deezerdatasync.domain.playlist.PlaylistId;
@Label("The GitHub mapper")
public class GitHubMapperPropertyTest {
@Property(tries = 10000)
void should_create_clean_playlist_filenames_from_edge_cases(@ForAll @StringLength(min = 1, max = 100) String title) {
// Given
var playlist = Playlist.builder().playlistId(PlaylistId.of(42)).title(title).build();
var data = DeezerData.builder()
.albums(List.of())
.playlistInfos(List.of())
.playlists(List.of(playlist)).build();
// When
GitHubBackup actualBackup = new GitHubMapper().mapDataToBackup(data);
// Then
GitHubFile playlistFile = actualBackup.getGitHubFiles().get(3);
String actualPath = playlistFile.getPath();
boolean isLowercase = actualPath.equals(actualPath.toLowerCase());
boolean matchesPattern = Pattern.matches("playlists/42_[a-z0-9_]*\\.json", actualPath);
boolean noConsecutiveUnderscores = !Pattern.matches(".*__.*", actualPath);
assertThat(isLowercase)
.as(String.format("%s should be lowercase", actualPath))
.isTrue();
assertThat(matchesPattern)
.as(String.format("%s should contain only allowed characters", actualPath))
.isTrue();
assertThat(noConsecutiveUnderscores)
.as(String.format("%s should not contained repeated underscores", actualPath))
.isTrue();
}
}