org.mockito.internal.stubbing.defaultanswers.ReturnsSmartNulls Java Examples

The following examples show how to use org.mockito.internal.stubbing.defaultanswers.ReturnsSmartNulls. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MapCloudhopperCharsetHandlerTest.java    From ogham with Apache License 2.0 5 votes vote down vote up
@Test
public void encodeWithKnownCharset() throws EncodingException {
	//given
	String givenContent = "méss@ge àvec des acçènts & d€$ cara©tères spécïaùx";
	String givenNioCharsetName = "charset";

	com.cloudhopper.commons.charset.Charset cloudhopperCharsetMock = Mockito.mock(com.cloudhopper.commons.charset.Charset.class, new ReturnsSmartNulls());
	charsetHandler.addCharset(givenNioCharsetName, new NamedCharset("", cloudhopperCharsetMock));

	Charset nioCharsetMock = new Charset(givenNioCharsetName, null) {
		@Override
		public CharsetEncoder newEncoder() {
			return null;
		}

		@Override
		public CharsetDecoder newDecoder() {
			return null;
		}

		@Override
		public boolean contains(Charset cs) {
			return false;
		}
	};

	BDDMockito.given(charsetProviderMock.detect(givenContent)).willReturn(nioCharsetMock);

	String expectedEncodedStr = "ok";
	BDDMockito.given(cloudhopperCharsetMock.encode(givenContent)).willReturn(expectedEncodedStr.getBytes());
	
	//when
	Encoded result = charsetHandler.encode(givenContent);
	
	//then
	Assert.assertArrayEquals(expectedEncodedStr.getBytes(), result.getBytes());
}
 
Example #2
Source File: MapCloudhopperCharsetHandlerTest.java    From ogham with Apache License 2.0 5 votes vote down vote up
@Test(expected = EncodingException.class)
public void encodeWithUnknownNioCharset() throws EncodingException {
	// given
	String givenContent = "méss@ge àvec des acçènts & d€$ cara©tères spécïaùx";
	String givenNioCharsetName = "charset";

	com.cloudhopper.commons.charset.Charset cloudhopperCharsetMock = Mockito.mock(com.cloudhopper.commons.charset.Charset.class, new ReturnsSmartNulls());
	charsetHandler.addCharset(givenNioCharsetName, new NamedCharset("", cloudhopperCharsetMock));

	BDDMockito.given(charsetProviderMock.detect(givenContent)).willReturn(null);

	// when
	charsetHandler.encode(givenContent);
}
 
Example #3
Source File: MockitoConfiguration.java    From mockito-cookbook with Apache License 2.0 4 votes vote down vote up
public Answer<Object> getDefaultAnswer() {
	return new ReturnsSmartNulls();
}