Skip to content

Commit 3f3b0de

Browse files
committed
More nullability fixes
1 parent 53bcc39 commit 3f3b0de

11 files changed

Lines changed: 137 additions & 15 deletions

File tree

library/src/main/java/me/proxer/library/api/NotificationAdapter.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.squareup.moshi.FromJson;
44
import com.squareup.moshi.Json;
5+
import com.squareup.moshi.JsonDataException;
56
import me.proxer.library.entity.notifications.Notification;
67
import me.proxer.library.enums.NotificationType;
78
import me.proxer.library.util.ProxerUrls;
@@ -19,6 +20,10 @@ Notification fromJson(final IntermediateNotification json) {
1920
final String base = ProxerUrls.webBase().toString();
2021
final HttpUrl properContentLink = HttpUrl.parse(base.substring(0, base.length() - 1) + json.contentLink);
2122

23+
if (properContentLink == null) {
24+
throw new JsonDataException("Invalid link: " + json.contentLink);
25+
}
26+
2227
return new Notification(json.id, json.type, json.contentId, properContentLink, json.text,
2328
json.date, json.additionalDescription);
2429
}

library/src/main/java/me/proxer/library/api/ProxerException.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,16 @@ public final class ProxerException extends Exception {
2525
/**
2626
* Returns the server error type if, and only if, {@link #getErrorType()} returns {@link ErrorType#SERVER}.
2727
*/
28-
@Getter(onMethod = @__({@Nullable}))
28+
@Nullable
29+
@Getter
2930
private final ServerErrorType serverErrorType;
3031

3132
/**
3233
* Returns a error message from the server if, and only if, {@link #getErrorType()} returns
3334
* {@link ErrorType#SERVER}.
3435
*/
35-
@Getter(onMethod = @__({@Override, @Nullable}))
36+
@Nullable
37+
@Getter(onMethod = @__({@Override}))
3638
private final String message;
3739

3840
/**

library/src/main/java/me/proxer/library/entity/anime/Stream.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,30 @@ public class Stream implements ProxerIdItem, ProxerImageItem, ProxerDateItem {
6666
/**
6767
* Returns the id of the translator group, if present.
6868
*/
69-
@Getter(onMethod = @__({@Nullable}))
69+
@Nullable
70+
@Getter
7071
@Json(name = "tid")
7172
private String translatorGroupId;
7273

7374
/**
7475
* Returns the name of the translator group, if present.
7576
*/
76-
@Getter(onMethod = @__({@Nullable}))
77+
@Nullable
78+
@Getter
7779
@Json(name = "tname")
7880
private String translatorGroupName;
81+
82+
public Stream(final String id, final String hoster, final String hosterName, final String image,
83+
final String uploaderId, final String uploaderName, final Date date,
84+
@Nullable final String translatorGroupId, @Nullable final String translatorGroupName) {
85+
this.id = id;
86+
this.hoster = hoster;
87+
this.hosterName = hosterName;
88+
this.image = image;
89+
this.uploaderId = uploaderId;
90+
this.uploaderName = uploaderName;
91+
this.date = date;
92+
this.translatorGroupId = translatorGroupId;
93+
this.translatorGroupName = translatorGroupName;
94+
}
7995
}

library/src/main/java/me/proxer/library/entity/info/Industry.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ public class Industry implements ProxerIdItem {
4646
/**
4747
* Returns the link to the homepage.
4848
*/
49-
@Getter(onMethod = @__({@Nullable}))
49+
@Nullable
50+
@Getter
5051
@Json(name = "link")
5152
private HttpUrl link;
5253

@@ -55,4 +56,14 @@ public class Industry implements ProxerIdItem {
5556
*/
5657
@Json(name = "description")
5758
private String description;
59+
60+
public Industry(final String id, final String name, final IndustryType type, final Country country,
61+
@Nullable final HttpUrl link, final String description) {
62+
this.id = id;
63+
this.name = name;
64+
this.type = type;
65+
this.country = country;
66+
this.link = link;
67+
this.description = description;
68+
}
5869
}

library/src/main/java/me/proxer/library/entity/info/Relation.java

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,17 +105,42 @@ public class Relation implements ProxerIdItem {
105105
/**
106106
* Returns the year this media was aired or published.
107107
*/
108-
@Getter(onMethod = @__({@Nullable}))
108+
@Nullable
109+
@Getter
109110
@Json(name = "year")
110111
private Integer year;
111112

112113
/**
113114
* Returns the available languages.
114115
*/
115-
@Getter(onMethod = @__({@Nullable}))
116+
@Nullable
117+
@Getter
116118
@Json(name = "season")
117119
private Season season;
118120

121+
public Relation(final String id, final String name, final Set<Genre> genres,
122+
final Set<FskConstraint> fskConstraints, final String description, final Medium medium,
123+
final int episodeAmount, final MediaState state, final int ratingSum, final int ratingAmount,
124+
final int clicks, final Category category, final License license,
125+
final Set<MediaLanguage> languages, @Nullable final Integer year, @Nullable final Season season) {
126+
this.id = id;
127+
this.name = name;
128+
this.genres = genres;
129+
this.fskConstraints = fskConstraints;
130+
this.description = description;
131+
this.medium = medium;
132+
this.episodeAmount = episodeAmount;
133+
this.state = state;
134+
this.ratingSum = ratingSum;
135+
this.ratingAmount = ratingAmount;
136+
this.clicks = clicks;
137+
this.category = category;
138+
this.license = license;
139+
this.languages = languages;
140+
this.year = year;
141+
this.season = season;
142+
}
143+
119144
/**
120145
* Returns the average of all ratings.
121146
*/

library/src/main/java/me/proxer/library/entity/info/TranslatorGroup.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ public class TranslatorGroup implements ProxerIdItem, ProxerImageItem {
4747
/**
4848
* Returns the link to the homepage.
4949
*/
50-
@Getter(onMethod = @__({@Nullable}))
50+
@Nullable
51+
@Getter
5152
@Json(name = "link")
5253
private HttpUrl link;
5354

@@ -68,4 +69,17 @@ public class TranslatorGroup implements ProxerIdItem, ProxerImageItem {
6869
*/
6970
@Json(name = "cprojects")
7071
private int projectAmount;
72+
73+
public TranslatorGroup(final String id, final String name, final Country country, final String image,
74+
@Nullable final HttpUrl link, final String description, final int clicks,
75+
final int projectAmount) {
76+
this.id = id;
77+
this.name = name;
78+
this.country = country;
79+
this.image = image;
80+
this.link = link;
81+
this.description = description;
82+
this.clicks = clicks;
83+
this.projectAmount = projectAmount;
84+
}
7185
}

library/src/main/java/me/proxer/library/entity/manga/Chapter.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,15 @@ public class Chapter implements ProxerIdItem, ProxerDateItem {
6060
* Returns the id of the scan group if present.
6161
*/
6262
@Nullable
63-
@Getter(onMethod = @__({@Nullable}))
63+
@Getter
6464
@Json(name = "tid")
6565
private String scanGroupId;
6666

6767
/**
6868
* Returns the name of the scan group if present.
6969
*/
7070
@Nullable
71-
@Getter(onMethod = @__({@Nullable}))
71+
@Getter
7272
@Json(name = "tname")
7373
private String scanGroupName;
7474

@@ -83,4 +83,19 @@ public class Chapter implements ProxerIdItem, ProxerDateItem {
8383
*/
8484
@Json(name = "pages")
8585
private List<Page> pages;
86+
87+
public Chapter(final String id, final String entryId, final String title, final String uploaderId,
88+
final String uploaderName, final Date date, @Nullable final String scanGroupId,
89+
@Nullable final String scanGroupName, final String server, final List<Page> pages) {
90+
this.id = id;
91+
this.entryId = entryId;
92+
this.title = title;
93+
this.uploaderId = uploaderId;
94+
this.uploaderName = uploaderName;
95+
this.date = date;
96+
this.scanGroupId = scanGroupId;
97+
this.scanGroupName = scanGroupName;
98+
this.server = server;
99+
this.pages = pages;
100+
}
86101
}

library/src/main/java/me/proxer/library/entity/notifications/Notification.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,19 @@ public class Notification implements ProxerIdItem, ProxerDateItem {
5858
/**
5959
* Returns additional info, depending on the {@link #type}.
6060
*/
61-
@Getter(onMethod = @__({@Nullable}))
61+
@Nullable
62+
@Getter
6263
@Json(name = "description")
6364
private String additionalDescription;
65+
66+
public Notification(final String id, final NotificationType type, final String contentId, final HttpUrl contentLink,
67+
final String text, final Date date, @Nullable final String additionalDescription) {
68+
this.id = id;
69+
this.type = type;
70+
this.contentId = contentId;
71+
this.contentLink = contentLink;
72+
this.text = text;
73+
this.date = date;
74+
this.additionalDescription = additionalDescription;
75+
}
6476
}

library/src/main/java/me/proxer/library/entity/ucp/Bookmark.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ public class Bookmark implements ProxerIdItem {
7272
/**
7373
* Returns the name of the chapter if the associated media is a manga and it is uploaded.
7474
*/
75-
@Getter(onMethod = @__({@Nullable}))
75+
@Nullable
76+
@Getter
7677
@Json(name = "chapterName")
7778
private String chapterName;
7879

@@ -81,4 +82,19 @@ public class Bookmark implements ProxerIdItem {
8182
*/
8283
@Json(name = "available")
8384
private boolean available;
85+
86+
public Bookmark(final String id, final String entryId, final Category category, final String name,
87+
final int episode, final MediaLanguage language, final Medium medium, final MediaState state,
88+
@Nullable final String chapterName, final boolean available) {
89+
this.id = id;
90+
this.entryId = entryId;
91+
this.category = category;
92+
this.name = name;
93+
this.episode = episode;
94+
this.language = language;
95+
this.medium = medium;
96+
this.state = state;
97+
this.chapterName = chapterName;
98+
this.available = available;
99+
}
84100
}

library/src/test/java/me/proxer/library/api/ProxerCallTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ public void testServerError() throws Exception {
6161
.isThrownBy(() -> api.messenger().conferences().build().execute())
6262
.matches(exception -> exception.getErrorType() == ErrorType.SERVER)
6363
.matches(exception -> exception.getServerErrorType() == ServerErrorType.MESSAGES_LOGIN_REQUIRED)
64-
.matches(exception -> exception.getMessage().equals("Du bist nicht eingeloggt."));
64+
.matches(exception -> exception.getMessage() != null
65+
&& exception.getMessage().equals("Du bist nicht eingeloggt."));
6566
}
6667

6768
@Test(timeout = 1000L)

0 commit comments

Comments
 (0)