Skip to content

Commit

Permalink
Minor test refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
mackdk committed Sep 14, 2023
1 parent e002bd5 commit 7e095ce
Showing 1 changed file with 21 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
*/
package com.redhat.rhn.domain.notification.types.test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

import com.redhat.rhn.common.conf.ConfigDefaults;
import com.redhat.rhn.domain.notification.NotificationMessage;
Expand All @@ -29,12 +29,10 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.io.IOException;

class UpdateAvailableTest extends MockObjectTestCase {

private static Runtime runtimeMock;
private static Process processMock;
private Runtime runtimeMock;
private Process processMock;

@BeforeEach
public void setUp() {
Expand Down Expand Up @@ -62,40 +60,30 @@ public void testPropertiesAndStrings() {
}

@Test
public void testUpdatesAvailable() {
public void testUpdatesAvailable() throws Exception {
// Return 0 on all invocations of exec() -> an update is available
try {
checking(new Expectations() {{
allowing(runtimeMock).exec(with(any(String[].class)));
will(returnValue(processMock));
allowing(processMock).waitFor();
allowing(processMock).exitValue();
will(returnValue(0));
}});
}
catch (IOException | InterruptedException e) {
e.printStackTrace();
}
checking(new Expectations() {{
allowing(runtimeMock).exec(with(any(String[].class)));
will(returnValue(processMock));
allowing(processMock).waitFor();
allowing(processMock).exitValue();
will(returnValue(0));
}});

UpdateAvailable notification = new UpdateAvailable(runtimeMock);
assertTrue(notification.updateAvailable());
}

@Test
public void testNoUpdatesAvailable() {
public void testNoUpdatesAvailable() throws Exception {
// Return 1 on all invocations of exec() -> no update is available
try {
checking(new Expectations() {{
allowing(runtimeMock).exec(with(any(String[].class)));
will(returnValue(processMock));
allowing(processMock).waitFor();
allowing(processMock).exitValue();
will(returnValue(1));
}});
}
catch (IOException | InterruptedException e) {
e.printStackTrace();
}
checking(new Expectations() {{
allowing(runtimeMock).exec(with(any(String[].class)));
will(returnValue(processMock));
allowing(processMock).waitFor();
allowing(processMock).exitValue();
will(returnValue(1));
}});

UpdateAvailable notification = new UpdateAvailable(runtimeMock);
assertFalse(notification.updateAvailable());
Expand Down

0 comments on commit 7e095ce

Please sign in to comment.