public void assertEquals(FakeExtractorOutput expected) { assertThat(numberOfTracks).isEqualTo(expected.numberOfTracks); assertThat(tracksEnded).isEqualTo(expected.tracksEnded); if (expected.seekMap == null) { assertThat(seekMap).isNull(); } else { // TODO: Bulk up this check if possible. assertThat(seekMap).isNotNull(); assertThat(seekMap.getClass()).isEqualTo(expected.seekMap.getClass()); assertThat(seekMap.isSeekable()).isEqualTo(expected.seekMap.isSeekable()); assertThat(seekMap.getSeekPoints(0)).isEqualTo(expected.seekMap.getSeekPoints(0)); } for (int i = 0; i < numberOfTracks; i++) { assertThat(trackOutputs.keyAt(i)).isEqualTo(expected.trackOutputs.keyAt(i)); trackOutputs.valueAt(i).assertEquals(expected.trackOutputs.valueAt(i)); } }
@Test public void cachesProxyClass() { ProxyMaker maker = new ProxyMaker(IDENTITY_NAME); Thing thing1 = mock(Thing.class); Thing thing2 = mock(Thing.class); Thing proxy1 = maker.createProxy(Thing.class, thing1); Thing proxy2 = maker.createProxy(Thing.class, thing2); assertThat(proxy1.getClass()).isSameAs(proxy2.getClass()); }
@GwtIncompatible("ClassSubject.java") public final ClassSubject that(@NullableDecl Class<?> actual) { return new ClassSubject(metadata(), actual); }
/** * Make a different ClassLoader that loads the same URLs as this one, and use it to compile * an {@code @RetroWeibo} class. If Velocity loads its managers using the context class loader, * and that loader is still the original one that loaded this test, then it will find the * original copy of the Velocity classes rather than the one from the new loader, and fail. * * <p>This test assumes that the test class was loaded by a URLClassLoader and that that loader's * URLs also include the Velocity classes. */ public void testClassLoaderHack() throws Exception { URLClassLoader myLoader = (URLClassLoader) getClass().getClassLoader(); URLClassLoader newLoader = new URLClassLoader(myLoader.getURLs(), myLoader.getParent()); String velocityClassName = Velocity.class.getName(); Class<?> myVelocity = myLoader.loadClass(velocityClassName); Class<?> newVelocity = newLoader.loadClass(velocityClassName); assertThat(myVelocity).isNotEqualTo(newVelocity); Runnable test = (Runnable) newLoader.loadClass(RunInClassLoader.class.getName()).newInstance(); assertThat(test.getClass()).isNotEqualTo(RunInClassLoader.class); test.run(); }
@Test public void testGenericParameterClass() { class ClassA<S, I> {} /*String, Integer*/ class ClassB<I, S, C extends Collection> extends ClassA<S, I> {} /*Integer, String, Set*/ class ClassC<S extends Comparable<String>, D, I> extends ClassB<I, S, Set<Long>> {} /*String, Double, Integer*/ class ClassD<I, D extends Comparable<Double>> extends ClassC<String, D, I> implements InterfaceB<D, I> {} /*Integer, Double*/ class ClassE extends ClassD<Integer, Double> {} class ClassF<B, L> extends ClassE {} /*Byte, Long*/ class ClassG extends ClassF<Byte, Long> {} final Class<?> classG = ClassG.class; assertThat(RxViper.getGenericParameterClass(classG, ClassA.class, 1)).isNotSameAs(String.class); assertThat(RxViper.getGenericParameterClass(classG, ClassA.class, 0)).isSameAs(String.class); assertThat(RxViper.getGenericParameterClass(classG, ClassA.class, 1)).isSameAs(Integer.class); assertThat(RxViper.getGenericParameterClass(classG, ClassB.class, 0)).isSameAs(Integer.class); assertThat(RxViper.getGenericParameterClass(classG, ClassB.class, 1)).isSameAs(String.class); assertThat(RxViper.getGenericParameterClass(classG, ClassB.class, 2)).isSameAs(Set.class); assertThat(RxViper.getGenericParameterClass(classG, ClassC.class, 0)).isSameAs(String.class); assertThat(RxViper.getGenericParameterClass(classG, ClassC.class, 1)).isSameAs(Double.class); assertThat(RxViper.getGenericParameterClass(classG, ClassC.class, 2)).isSameAs(Integer.class); assertThat(RxViper.getGenericParameterClass(classG, ClassD.class, 0)).isSameAs(Integer.class); assertThat(RxViper.getGenericParameterClass(classG, ClassD.class, 1)).isSameAs(Double.class); assertThat(RxViper.getGenericParameterClass(classG, ClassF.class, 0)).isSameAs(Byte.class); assertThat(RxViper.getGenericParameterClass(classG, ClassF.class, 1)).isSameAs(Long.class); assertThat(RxViper.getGenericParameterClass(classG, InterfaceA.class, 0)).isSameAs(Integer.class); assertThat(RxViper.getGenericParameterClass(classG, InterfaceB.class, 0)).isSameAs(Double.class); assertThat(RxViper.getGenericParameterClass(classG, InterfaceB.class, 1)).isSameAs(Integer.class); thrown.expect(EmptyStackException.class); assertThat(RxViper.getGenericParameterClass(classG, ClassE.class, 0)).isSameAs(Double.class); }
@Test public void proxyCall() { ProxyMaker maker = new ProxyMaker(IDENTITY_NAME); Thing mock = mock(Thing.class); Thing proxy = maker.createProxyFactory(Thing.class).createProxy(Thing.class, mock); assertThat(proxy.getClass()).isNotSameAs(Thing.class); proxy.returnNothing(); verify(mock).returnNothing(); when(mock.returnInt()).thenReturn(42); assertThat(proxy.returnInt()).isEqualTo(42); verify(mock).returnInt(); proxy.argument("hello"); verify(mock).argument("hello"); }
/** * Make a different ClassLoader that loads the same URLs as this one, and use it to compile * an {@code @AutoJson} class. If Velocity loads its managers using the context class loader, * and that loader is still the original one that loaded this test, then it will find the * original copy of the Velocity classes rather than the one from the new loader, and fail. * * <p>This test assumes that the test class was loaded by a URLClassLoader and that that loader's * URLs also include the Velocity classes. */ public void testClassLoaderHack() throws Exception { URLClassLoader myLoader = (URLClassLoader) getClass().getClassLoader(); URLClassLoader newLoader = new URLClassLoader(myLoader.getURLs(), myLoader.getParent()); String velocityClassName = Velocity.class.getName(); Class<?> myVelocity = myLoader.loadClass(velocityClassName); Class<?> newVelocity = newLoader.loadClass(velocityClassName); assertThat(myVelocity).isNotEqualTo(newVelocity); Runnable test = (Runnable) newLoader.loadClass(RunInClassLoader.class.getName()).newInstance(); assertThat(test.getClass()).isNotEqualTo(RunInClassLoader.class); test.run(); }
@Test public void findPlugin_shouldPickHighestPriorityClass() throws Exception { pluginClasses.addAll(asList(ImplMinus1.class, ImplZeroA.class, ImplOne.class, ImplZeroB.class)); assertThat(pluginFinder.findPlugin(Iface.class)) .isEqualTo(ImplOne.class); }
/** * Make a different ClassLoader that loads the same URLs as this one, and use it to compile * an {@code @RetroFacebook} class. If Velocity loads its managers using the context class loader, * and that loader is still the original one that loaded this test, then it will find the * original copy of the Velocity classes rather than the one from the new loader, and fail. * * <p>This test assumes that the test class was loaded by a URLClassLoader and that that loader's * URLs also include the Velocity classes. */ public void testClassLoaderHack() throws Exception { URLClassLoader myLoader = (URLClassLoader) getClass().getClassLoader(); URLClassLoader newLoader = new URLClassLoader(myLoader.getURLs(), myLoader.getParent()); String velocityClassName = Velocity.class.getName(); Class<?> myVelocity = myLoader.loadClass(velocityClassName); Class<?> newVelocity = newLoader.loadClass(velocityClassName); assertThat(myVelocity).isNotEqualTo(newVelocity); Runnable test = (Runnable) newLoader.loadClass(RunInClassLoader.class.getName()).newInstance(); assertThat(test.getClass()).isNotEqualTo(RunInClassLoader.class); test.run(); }
assertEquals(1, scenario.getModelBuilders().size()); assertThat(scenario.getModelBuilders().iterator().next() .getAssociatedType()).isSameAs(RoadUser.class);
@CheckReturnValue @GwtIncompatible("ClassSubject.java") public ClassSubject that(Class<?> target) { return new ClassSubject(getFailureStrategy(), target); }
@Test @Config(minSdk = LOLLIPOP) public void shouldSetView_withLayoutId() throws Exception { AlertDialog.Builder builder = new AlertDialog.Builder(application); builder.setView(R.layout.custom_layout); AlertDialog alert = builder.create(); View view = shadowOf(alert).getView(); assertThat(view.getClass()).isEqualTo(CustomView.class); }
/** * Make a different ClassLoader that loads the same URLs as this one, and use it to compile * an {@code @RetroFacebook} class. If Velocity loads its managers using the context class loader, * and that loader is still the original one that loaded this test, then it will find the * original copy of the Velocity classes rather than the one from the new loader, and fail. * * <p>This test assumes that the test class was loaded by a URLClassLoader and that that loader's * URLs also include the Velocity classes. */ public void testClassLoaderHack() throws Exception { URLClassLoader myLoader = (URLClassLoader) getClass().getClassLoader(); URLClassLoader newLoader = new URLClassLoader(myLoader.getURLs(), myLoader.getParent()); String velocityClassName = Velocity.class.getName(); Class<?> myVelocity = myLoader.loadClass(velocityClassName); Class<?> newVelocity = newLoader.loadClass(velocityClassName); assertThat(myVelocity).isNotEqualTo(newVelocity); Runnable test = (Runnable) newLoader.loadClass(RunInClassLoader.class.getName()).newInstance(); assertThat(test.getClass()).isNotEqualTo(RunInClassLoader.class); test.run(); }
@CheckReturnValue @GwtIncompatible("ClassSubject.java") public static ClassSubject assertThat(Class<?> target) { return new ClassSubject(getFailureStrategy(), target); }
@Test public void shouldReturnWifiInfo() { assertThat(wifiManager.getConnectionInfo().getClass()).isEqualTo(WifiInfo.class); }
@Test public void shouldConvertFromMethodSignature() throws Exception { InvocationProfile profile = new InvocationProfile("android/view/View/invalidate()V", false, getClass().getClassLoader()); assertThat(profile.clazz).isEqualTo(View.class); assertThat(profile.methodName).isEqualTo("invalidate"); assertThat(profile.isStatic).isEqualTo(false); assertThat(profile.paramTypes).isEmpty(); }
@Test public void setupWithBundle_callsLifecycleMethodsAndMakesVisible() { controller.setup(new Bundle()); assertThat(transcript).containsAllOf("onCreate", "onStart", "onRestoreInstanceState", "onPostCreate", "onResume", "onPostResume"); assertThat(controller.get().getWindow().getDecorView().getParent().getClass()).isEqualTo( ViewRootImpl.class); }
@Test public void setup_callsLifecycleMethodsAndMakesVisible() { controller.setup(); assertThat(transcript).containsAllOf("onCreate", "onStart", "onPostCreate", "onResume", "onPostResume"); assertThat(controller.get().getWindow().getDecorView().getParent().getClass()).isEqualTo( ViewRootImpl.class); }
@Override public boolean test(Throwable throwable) throws Exception { ApolloParseException e = (ApolloParseException) throwable; assertThat(e.getMessage()).isEqualTo("Failed to parse http response"); assertThat(e.getCause().getClass()).isEqualTo(JsonEncodingException.class); return true; } });
@Override public boolean test(Throwable throwable) throws Exception { ApolloNetworkException e = (ApolloNetworkException) throwable; assertThat(e.getMessage()).isEqualTo("Failed to execute http call"); assertThat(e.getCause().getClass()).isEqualTo(SocketTimeoutException.class); return true; } });