@Test public void setDataSource_forNoDataSource_asserts() { try { mediaPlayer.setDataSource("some unspecified data source"); fail("Expected exception thrown"); } catch (IllegalArgumentException a) { assertThat(a.getMessage()).named("assertionMessage") .contains("addException"); assertThat(a.getMessage()).named("assertionMessage") .contains("addMediaInfo"); } catch (Exception e) { throw new RuntimeException("Unexpected exception", e); } }
@Test public void shouldSetUpSystemResources() { Resources systemResources = Resources.getSystem(); Resources appResources = ApplicationProvider.getApplicationContext().getResources(); assertThat(systemResources).named("system resources").isNotNull(); assertThat(systemResources.getString(android.R.string.copy)).named("system resource") .isEqualTo(appResources.getString(android.R.string.copy)); assertThat(appResources.getString(R.string.howdy)).named("app resource") .isNotNull(); try { systemResources.getString(R.string.howdy); fail("Expected Exception not thrown"); } catch (Resources.NotFoundException e) { } }
@Test public void setDataSourceException_withRuntimeException() { RuntimeException e = new RuntimeException("some dummy message"); addException(toDataSource("dummy"), e); try { mediaPlayer.setDataSource("dummy"); fail("Expected exception thrown"); } catch (Exception caught) { assertThat(caught).isSameAs(e); assertThat(e.getStackTrace()[0].getClassName()) .named("Stack trace should originate in Shadow") .isEqualTo(ShadowMediaPlayer.class.getName()); } }
@Test public void setDataSourceException_withAllowedException() { RuntimeException e = new RuntimeException("some dummy message"); addException(toDataSource(path), e); try { retriever.setDataSource(path); fail("Expected exception"); } catch (Exception caught) { assertThat(caught).isSameAs(e); assertThat(e.getStackTrace()[0].getClassName()) .named("Stack trace should originate in Shadow") .isEqualTo(ShadowMediaMetadataRetriever.class.getName()); } } }
public CursorAssert hasRow(Object... values) { assertThat(cursor.moveToNext()).named("row " + (row + 1) + " exists").isTrue(); row += 1; assertThat(cursor.getColumnCount()).named("column count").isEqualTo(values.length); for (int i = 0; i < values.length; i++) { assertThat(cursor.getString(i)) .named("row " + row + " column '" + cursor.getColumnName(i) + "'") .isEqualTo(values[i]); } return this; }
@Test public void callConstructorReflectively_whenMultipleSignaturesExistForTheConstructor_callsConstructorWithCorrectSignature() { ExampleClass ec = ReflectionHelpers.callConstructor(ExampleClass.class, ClassParameter.from(int.class, 16)); assertThat(ec.index).named("index").isEqualTo(16); assertThat(ec.name).named("name").isNull(); }
@Test public void setDataSourceException_withIOException() { IOException e = new IOException("some dummy message"); addException(toDataSource("dummy"), e); shadowMediaPlayer.setState(IDLE); try { mediaPlayer.setDataSource("dummy"); fail("Expected exception thrown"); } catch (Exception caught) { assertThat(caught).isSameAs(e); assertThat(e.getStackTrace()[0].getClassName()) .named("Stack trace should originate in Shadow") .isEqualTo(ShadowMediaPlayer.class.getName()); assertThat(shadowMediaPlayer.getState()).named( "State after " + e + " thrown should be unchanged").isSameAs(IDLE); } }
fail("Expected ISE for " + method); } catch (IllegalStateException e) { assertThat(e.getMessage()).named("Exception for " + method).contains("was " + type); assertThat(e.getMessage()) .named("Exception for " + method) .contains("Column " + columnIndex); fail("Expected ISE for " + method); } catch (IllegalStateException e) { assertThat(e.getMessage()).named("Exception for " + method).contains("was " + type); assertThat(e.getMessage()).named("Exception for " + method).contains("Column F1");
@Test public void testFullyOverwritten() { parcel.writeInt(1); // NOTE: Later, this 8-byte long gets chopped up by two 4-byte writes, but it's OK because this // byte range is not read until it has been fully overwritten. parcel.writeLong(5); parcel.writeInt(4); assertInvariants(); parcel.setDataPosition(4); parcel.writeByte((byte) 55); // Byte and int have the parceled size. parcel.writeString(null); // And so does a null string. assertInvariants(); parcel.setDataPosition(0); assertThat(parcel.readInt()).named("readInt@0").isEqualTo(1); assertThat(parcel.dataPosition()).named("position post-readInt@0").isEqualTo(4); assertThat(parcel.readByte()).named("readByte@4").isEqualTo(55); assertThat(parcel.dataPosition()).named("position post-readByte@4").isEqualTo(8); assertThat(parcel.readString()).named("readString@8").isNull(); assertThat(parcel.dataPosition()).named("position post-readString@8").isEqualTo(12); assertThat(parcel.readInt()).named("readInt@12").isEqualTo(4); }
@Test public void testInvalidOnClickAttribute() throws Exception { Activity activity = buildActivity(Activity.class).create().get(); activity.setContentView(R.layout.with_invalid_onclick); Button button = activity.findViewById(R.id.invalid_onclick_button); IllegalStateException exception = null; try { button.performClick(); } catch (IllegalStateException e) { exception = e; } assertNotNull(exception); assertThat(exception.getMessage()) .named("The error message should contain the id name of the faulty button") .contains("invalid_onclick_button"); }
@Test public void doGetWritesResponse() throws Exception { servletUnderTest.doGet(mockRequest, mockResponse); // We expect our hello world response. assertThat(responseWriter.toString()) .named("HelloAppEngine response") .contains("Hello App Engine - Standard "); }
@Test public void doGetWritesResponse() throws Exception { servletUnderTest.doGet(mockRequest, mockResponse); // We expect our hello world response. assertThat(responseWriter.toString()) .named("HelloAppEngine response") .contains("Hello App Engine - Standard "); }
/** * Returns a {@link StringSubject} that makes assertions about the contents of the actual file as * a string. */ public StringSubject contentsAsString(Charset charset) { try { return check() .that(JavaFileObjects.asByteSource(actual()).asCharSource(charset).read()) .named("the contents of " + actualAsString()); } catch (IOException e) { throw new RuntimeException(e); } }
/** * Returns a {@link StringSubject} that makes assertions about the contents of the actual file as * a string. */ public StringSubject contentsAsString(Charset charset) { try { return check() .that(JavaFileObjects.asByteSource(actual()).asCharSource(charset).read()) .named("the contents of " + actualAsString()); } catch (IOException e) { throw new RuntimeException(e); } }
@Test public void helloInfoTest() { String result = HelloAppEngine.getInfo(); assertThat(result) .named("HelloInfo.getInfo") .containsMatch("^Version:\\s+.+OS:\\s+.+User:\\s"); } }
@Test public void helloInfoTest() { String result = HelloAppEngine.getInfo(); assertThat(result) .named("HelloInfo.getInfo") .containsMatch("^Version:\\s+.+OS:\\s+.+User:\\s"); } }