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

CXF-8847: Get rid of EasyMock in cxf-rt-databinding-aegis #1328

Merged
merged 1 commit into from
Jul 12, 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
5 changes: 3 additions & 2 deletions rt/databinding/aegis/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,9 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.easymock</groupId>
<artifactId>easymock</artifactId>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>${cxf.mockito.version}</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,11 @@

import jakarta.activation.DataSource;

import org.easymock.MockType;
import org.junit.Test;

import static org.easymock.EasyMock.anyObject;
import static org.easymock.EasyMock.expect;
import static org.easymock.EasyMock.mock;
import static org.easymock.EasyMock.replay;
import static org.easymock.EasyMock.verify;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

/**
* Unit test for DataSourceType class, which also tests any static helper functions invoked
Expand All @@ -41,39 +38,26 @@ public class DataSourceTypeTest {

@Test
public void inputStreamShouldBeClosedOnHappyPath() throws Exception {
DataSource ds = mock(MockType.STRICT, DataSource.class);
InputStream is = mock(MockType.STRICT, InputStream.class);
expect(ds.getInputStream()).andReturn(is);
replay(ds);
expect(is.available()).andReturn(1);
expect(is.read(anyObject(byte[].class))).andReturn(-1);
DataSource ds = mock(DataSource.class);
InputStream is = mock(InputStream.class);
when(ds.getInputStream()).thenReturn(is);
when(is.available()).thenReturn(1);
when(is.read(any(byte[].class))).thenReturn(-1);
is.close();
replay(is);

DataSourceType dst = new DataSourceType(false, null);
dst.getBytes(ds);

verify(ds);
verify(is);
}

@Test(expected = RuntimeException.class)
public void inputStreamShouldBeClosedOnReadingException() throws Exception {
DataSource ds = mock(MockType.STRICT, DataSource.class);
InputStream is = mock(MockType.STRICT, InputStream.class);
expect(ds.getInputStream()).andReturn(is);
replay(ds);
expect(is.available()).andThrow(new IOException());
DataSource ds = mock(DataSource.class);
InputStream is = mock(InputStream.class);
when(ds.getInputStream()).thenReturn(is);
when(is.available()).thenThrow(new IOException());
is.close();
replay(is);

DataSourceType dst = new DataSourceType(false, null);
try {
dst.getBytes(ds);
} finally {
verify(ds);
verify(is);
}

dst.getBytes(ds);
}
}