Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove confusing and almost unused Asserts class #7659

Merged
merged 2 commits into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ public boolean aclTrustChannelAccess(Map<String, Object> ctx, String[] params) {
Long cid = getAsLong(ctx.get("cid"));
Channel c = ChannelFactory.lookupById(cid);

return c.getOrg().getId() == user.getOrg().getId();
return c.getOrg().getId().equals(user.getOrg().getId());
}

/**
Expand Down
175 changes: 0 additions & 175 deletions java/code/src/com/redhat/rhn/common/util/Asserts.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public static XccdfTestResult lookupTestResultById(Long xid) {
*/
public static XccdfTestResult lookupTestResultByIdAndSid(Long xid, Long sid) {
XccdfTestResult result = lookupTestResultById(xid);
if (result == null || result.getServer().getId() != sid) {
if (result == null || !result.getServer().getId().equals(sid)) {
LocalizationService ls = LocalizationService.getInstance();
throw new LookupException("Could not find XCCDF scan " + xid + " for system " + sid,
ls.getMessage("lookup.xccdfscan.title"), null, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,10 @@ public ActionForward execute(ActionMapping mapping,
for (RhnSetElement element : groupSet.getElements()) {
Long gid = element.getElement();
if (groupMap.containsKey(gid)) {
if (element.getElementTwo() == SSMGroupManageAction.ADD) {
if (element.getElementTwo().equals(SSMGroupManageAction.ADD)) {
addList.add(groupMap.get(gid));
}
else if (element.getElementTwo() == SSMGroupManageAction.REMOVE) {
else if (element.getElementTwo().equals(SSMGroupManageAction.REMOVE)) {
removeList.add(groupMap.get(gid));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ public final ActionForward execute(ActionMapping mapping,
throw new BadParameterException("Missing min, max and/or ksid for ks ip range");
}
// make sure org has permission
else if (user.getOrg().getId() !=
cmd.getKickstartData().getOrg().getId()) {
else if (!user.getOrg().getId().equals(cmd.getKickstartData().getOrg().getId())) {
throw new BadParameterException("Invalid uid for /rhn/kickstart/");
}
// delete ip range from kickstart
Expand All @@ -80,7 +79,7 @@ else if (user.getOrg().getId() !=
request.getParameter(MIN),
request.getParameter(MAX));
if (success) {
createSuccessMessage(request, getSuccessKey(),
createSuccessMessage(request, "kickstart.iprange_delete.success",
cmd.getKickstartData().getLabel());
}
else {
Expand All @@ -97,13 +96,4 @@ else if (user.getOrg().getId() !=
return strutsDelegate.forwardParams(mapping.findForward(RhnHelper.DEFAULT_FORWARD),
params);
}

/**
*
* @return i18n key
*/
private String getSuccessKey() {
return "kickstart.iprange_delete.success";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public ActionForward execute(ActionMapping mapping,
ActionForward retval = mapping.findForward(RhnHelper.DEFAULT_FORWARD);

// protect self from removing sat admin role
if (current.getId() == u.getId()) {
if (current.getId().equals(u.getId())) {
//make sure we always have at least one sat admin
if (SatManager.getActiveSatAdmins().size() == 1) {
createErrorMessage(request, "satadmin.jsp.error.lastsatadmin",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,8 @@ else if (daForm.get(AUTO_UPDATE) == null) {

// Set the contact method
Long contactId = (Long) daForm.get(CONTACT_METHOD);
if (contactId != null && (contactId != s.getContactMethod().getId()) &&
!s.asMinionServer().isPresent()) {
if (contactId != null && !contactId.equals(s.getContactMethod().getId()) &&
s.asMinionServer().isEmpty()) {
s.setContactMethod(ServerFactory.findContactMethodById(contactId));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
*/
package com.redhat.rhn.frontend.struts;

import com.redhat.rhn.common.util.Asserts;
import com.redhat.rhn.common.util.DatePicker;
import com.redhat.rhn.common.util.ServletUtils;
import com.redhat.rhn.common.validator.ValidationMessage;
Expand Down Expand Up @@ -97,7 +96,9 @@ public ActionForward forwardParam(ActionForward base, String param, String value
* param and value.
*/
public ActionForward forwardParams(ActionForward base, Map params) {
Asserts.assertNotNull(base, "base");
if (base == null) {
throw new IllegalArgumentException("Base should not be null");
}
String newPath = ServletUtils.pathWithParams(base.getPath(), params);

ActionForward af = new ActionForward(newPath, base.getRedirect());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public List<RuleResultComparator> getData() {
public List<RuleResultComparator> getData(Boolean differs) {
List<RuleResultComparator> result = new ArrayList<>();
for (RuleResultComparator item : dataMap.values()) {
if (item.getDiffers() == differs) {
if (item.getDiffers().equals(differs)) {
result.add(item);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void removeTokensByIds(List<Long> ids) {
Set<Token> tokenSetCopy = new HashSet<>();
tokenSetCopy.addAll(this.getKickstartData().getDefaultRegTokens());
for (Token token : tokenSetCopy) {
if (token.getId() == id) {
if (token.getId().equals(id)) {
this.getKickstartData().getDefaultRegTokens().remove(token);
keysToRemove.add(ActivationKeyFactory.lookupByToken(token).getKey());
}
Expand Down
9 changes: 6 additions & 3 deletions java/code/src/com/redhat/rhn/manager/rhnset/RhnSetDecl.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
*/
package com.redhat.rhn.manager.rhnset;

import com.redhat.rhn.common.util.Asserts;
import com.redhat.rhn.domain.channel.Channel;
import com.redhat.rhn.domain.rhnset.RhnSet;
import com.redhat.rhn.domain.rhnset.SetCleanup;
Expand Down Expand Up @@ -375,7 +374,9 @@ public void clear(User u) {
* @return the created set
*/
public RhnSet create(User u) {
Asserts.assertNotNull(u, "u");
if (u == null) {
throw new IllegalArgumentException("user should not be null");
}
return RhnSetManager.createSet(u.getId(), label, cleanup);
}

Expand All @@ -387,7 +388,9 @@ public RhnSet create(User u) {
* @return the set for user <code>u</code>
*/
public RhnSet get(User u) {
Asserts.assertNotNull(u, "u");
if (u == null) {
throw new IllegalArgumentException("user should not be null");
}
RhnSet s = lookup(u);
if (s == null) {
s = create(u);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public long storeMirrorCredentials(MirrorCredentialsDto creds,
// Check if the supplied user name already exists in stored credentials
for (Credentials existingCred : CredentialsFactory.listSCCCredentials()) {
if (existingCred.getUsername().equals(creds.getUser()) &&
(creds.getId() != existingCred.getId())) {
(!creds.getId().equals(existingCred.getId()))) {
throw new MirrorCredentialsNotUniqueException("Username already exists");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3699,7 +3699,7 @@ public static void setUserSystemPreferenceBulk(User user, String preference,
params.put("pref", preference);
mode.execute(params, new HashMap<>());
// preference values have a default, only insert if not default
if (value != defaultIn) {
if (!value.equals(defaultIn)) {
mode = ModeFactory.getCallableMode("System_queries",
"set_user_system_preference_bulk");
params = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ private List<Long> invalidateActionRecursive(Long serverId, Long actionId) {
Server s = ServerFactory.lookupById(serverId);
Action a = ActionFactory.lookupById(actionId);
ServerAction sa = ActionFactory.getServerActionForServerAndAction(s, a);
if (sa.getStatus().getName() != "Failed") {
if (!"Failed".equals(sa.getStatus().getName())) {
sa.fail(-100L, "Prerequisite failed", sa.getPickupTime());

s.asMinionServer()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@

package com.redhat.rhn.taskomatic.task.payg.dimensions.rules.test;

import static com.redhat.rhn.common.util.Asserts.assertTrue;
import static org.jmock.AbstractExpectations.returnValue;
import static org.junit.jupiter.api.Assertions.assertTrue;

import com.redhat.rhn.domain.product.SUSEProduct;
import com.redhat.rhn.domain.product.SUSEProductSet;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public static String updateFiltersOfProject(Request req, Response res, User user
.filter(filterId ->
!dbContentProject.getProjectFilters()
.stream()
.filter(filter -> filter.getId() == filterId)
.filter(filter -> filter.getId().equals(filterId))
.findFirst()
.isPresent()
)
Expand Down