@Before public void before() throws Exception { MockitoAnnotations.initMocks(this); loader = spy(new FilterLoader(registry, compiler, filterFactory)); doReturn(TestZuulFilter.class).when(compiler).compile(file); when(file.getAbsolutePath()).thenReturn("/filters/in/SomeFilter.groovy"); }
@Test public void testFileManagerInit() throws Exception { FilterFileManagerConfig config = new FilterFileManagerConfig(new String[]{"test", "test1"}, new String[]{"com.netflix.blah.SomeFilter"}, 1); FilterFileManager manager = new FilterFileManager(config, filterLoader); manager = spy(manager); doNothing().when(manager).manageFiles(); manager.init(); verify(manager, atLeast(1)).manageFiles(); verify(manager, times(1)).startPoller(); assertNotNull(manager.poller); } }
@Test public void importSelectors() { DefaultListableBeanFactory beanFactory = spy(new DefaultListableBeanFactory()); AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(beanFactory); context.register(Config.class); context.refresh(); context.getBean(Config.class); InOrder ordered = inOrder(beanFactory); ordered.verify(beanFactory).registerBeanDefinition(eq("a"), any()); ordered.verify(beanFactory).registerBeanDefinition(eq("b"), any()); ordered.verify(beanFactory).registerBeanDefinition(eq("d"), any()); ordered.verify(beanFactory).registerBeanDefinition(eq("c"), any()); }
@Test public void allowedOptionsIncludesPatchMethod() throws Exception { MockHttpServletRequest request = new MockHttpServletRequest(getServletContext(), "OPTIONS", "/foo"); MockHttpServletResponse response = spy(new MockHttpServletResponse()); DispatcherServlet servlet = new DispatcherServlet(); servlet.setDispatchOptionsRequest(false); servlet.service(request, response); verify(response, never()).getHeader(anyString()); // SPR-10341 assertThat(response.getHeader("Allow"), equalTo("GET, HEAD, POST, PUT, DELETE, TRACE, OPTIONS, PATCH")); }
@SuppressWarnings("deprecation") @Test @RequiresApi(Build.VERSION_CODES.JELLY_BEAN_MR1) public void testDoesNotThrowIfAskedToGetManagerForFragmentPreJellyBeanMr1() { Util.setSdkVersionInt(Build.VERSION_CODES.JELLY_BEAN); Activity activity = Robolectric.buildActivity(Activity.class).create().start().resume().get(); android.app.Fragment fragment = new android.app.Fragment(); activity.getFragmentManager().beginTransaction().add(fragment, "test").commit(); android.app.Fragment spyFragment = Mockito.spy(fragment); when(spyFragment.getChildFragmentManager()).thenThrow(new NoSuchMethodError()); assertNotNull(retriever.get(spyFragment)); }
@Test public void shouldCramMultipleDecoratorsIntoOne() { // GIVEN Decorator decorator1 = spy( new IdentityDecorator() ); Decorator decorator2 = spy( new IdentityDecorator() ); Decorator multi = decorators( decorator1, decorator2 ); // WHEN InputEntityVisitor node = mock( InputEntityVisitor.class ); multi.apply( node ); // THEN InOrder order = inOrder( decorator1, decorator2 ); order.verify( decorator1, times( 1 ) ).apply( node ); order.verify( decorator2, times( 1 ) ).apply( node ); order.verifyNoMoreInteractions(); }
@Test(expected = KeyNotFoundException.class) public void testKeyNotFoundException() throws Exception { Map<String, Object> conf = Utils.readStormConfig(); String key1 = "key1"; conf.put(Config.STORM_LOCAL_DIR, "target"); LocalFsBlobStore bs = new LocalFsBlobStore(); LocalFsBlobStore spy = spy(bs); Mockito.doReturn(true).when(spy).checkForBlobOrDownload(key1); Mockito.doNothing().when(spy).checkForBlobUpdate(key1); spy.prepare(conf, null, null, null); spy.getBlob(key1, null); }
static Action mockAction(Request request, final Object target, String tag) { Action action = spy(new Action(mockPicasso(), request) { @Override void complete(RequestHandler.Result result) { } @Override void error(Exception e) { } @Override Object getTarget() { return target; } }); when(action.getTag()).thenReturn(tag != null ? tag : action); return action; }
private static void verifyOutput(String expected, AuditEvent... events) throws IOException { final OutputStream out = spy(new ByteArrayOutputStream()); final XpathFileGeneratorAuditListener listener = new XpathFileGeneratorAuditListener(out, AutomaticBean.OutputStreamOptions.CLOSE); for (AuditEvent event : events) { listener.addError(event); } listener.auditFinished(null); verify(out, times(1)).flush(); verify(out, times(1)).close(); final String actual = out.toString(); assertEquals("Invalid suppressions file content", expected, actual); } }
@Test public void shouldClearWorkingDirectoryBeforeCheckingOut() throws Exception { File workingDirectory = mock(File.class); when(workingDirectory.exists()).thenReturn(true); TfsSDKCommand spy = spy(tfsCommand); doNothing().when(spy).initializeWorkspace(workingDirectory); doNothing().when(spy).retrieveFiles(workingDirectory, null); spy.checkout(workingDirectory, null); verify(workingDirectory).exists(); }
@Test public void shouldCheckConnection() { TestSubprocessExecutionContext execCtx = new TestSubprocessExecutionContext(); TfsCommand tfsCommand = mock(TfsCommand.class); doNothing().when(tfsCommand).checkConnection(); TfsMaterial spy = spy(tfsMaterialFirstCollectionFirstProject); doReturn(tfsCommand).when(spy).tfs(execCtx); assertThat(spy.checkConnection(execCtx), is(valid())); verify(tfsCommand, times(1)).checkConnection(); }
@Test public void intoImageViewSetsPlaceholderDrawable() { PlatformLruCache cache = new PlatformLruCache(0); Picasso picasso = spy(new Picasso(RuntimeEnvironment.application, mock(Dispatcher.class), UNUSED_CALL_FACTORY, null, cache, null, NO_TRANSFORMERS, NO_HANDLERS, mock(Stats.class), ARGB_8888, false, false)); ImageView target = mockImageViewTarget(); Drawable placeHolderDrawable = mock(Drawable.class); new RequestCreator(picasso, URI_1, 0).placeholder(placeHolderDrawable).into(target); verify(target).setImageDrawable(placeHolderDrawable); verify(picasso).enqueueAndSubmit(actionCaptor.capture()); assertThat(actionCaptor.getValue()).isInstanceOf(ImageViewAction.class); }
@Test public void importSelectorsWithGroup() { DefaultListableBeanFactory beanFactory = spy(new DefaultListableBeanFactory()); AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(beanFactory); context.register(GroupedConfig.class); context.refresh(); InOrder ordered = inOrder(beanFactory); ordered.verify(beanFactory).registerBeanDefinition(eq("a"), any()); ordered.verify(beanFactory).registerBeanDefinition(eq("b"), any()); ordered.verify(beanFactory).registerBeanDefinition(eq("c"), any()); ordered.verify(beanFactory).registerBeanDefinition(eq("d"), any()); assertThat(TestImportGroup.instancesCount.get(), equalTo(1)); assertThat(TestImportGroup.imports.size(), equalTo(1)); assertThat(TestImportGroup.imports.values().iterator().next().size(), equalTo(2)); }
@Test @RequiresApi(Build.VERSION_CODES.JELLY_BEAN_MR1) public void testDoesNotThrowIfAskedToGetManagerForActivityPreJellYBeanMr1() { Util.setSdkVersionInt(Build.VERSION_CODES.JELLY_BEAN); Activity activity = Robolectric.buildActivity(Activity.class).create().start().resume().get(); Activity spyActivity = Mockito.spy(activity); when(spyActivity.isDestroyed()).thenThrow(new NoSuchMethodError()); assertNotNull(retriever.get(spyActivity)); }
@Test public void testSingleWithBackpressureFlowable() { Flowable<Integer> flowable = Flowable.just(1, 2).singleElement().toFlowable(); Subscriber<Integer> subscriber = spy(new DefaultSubscriber<Integer>() { @Override public void onStart() { request(1); } @Override public void onComplete() { } @Override public void onError(Throwable e) { } @Override public void onNext(Integer integer) { request(1); } }); flowable.subscribe(subscriber); InOrder inOrder = inOrder(subscriber); inOrder.verify(subscriber, times(1)).onError(isA(IllegalArgumentException.class)); inOrder.verifyNoMoreInteractions(); }
@Test public void shouldGetCurrentLogDirectoryByLookingAtFileAppenderOfRootLogger() throws Exception { if (WINDOWS.satisfy()) { return; } FileAppender fileAppender = new FileAppender(); fileAppender.setFile("/var/log/go-server/go-server.log"); DefaultPluginLoggingService service = Mockito.spy(new DefaultPluginLoggingService(systemEnvironment)); doReturn(fileAppender).when(service).getGoServerLogFileAppender(); String currentLogDirectory = service.getCurrentLogDirectory(); assertThat(currentLogDirectory, is("/var/log/go-server")); }
private static ResourceIterator<File> scanStoreFilesAre( LabelScanStore labelScanStore, String[] fileNames ) { ArrayList<File> files = new ArrayList<>(); mockFiles( fileNames, files, false ); ResourceIterator<File> snapshot = spy( asResourceIterator( files.iterator() ) ); when( labelScanStore.snapshotStoreFiles() ).thenReturn( snapshot ); return snapshot; }
@Test void testAddClassChecksWithCache() throws Exception { ValidationContext context = spy(new ValidationContext()); try { context.addClassChecks(ClassForCheck1.class); context.addClassChecks(ClassForCheck1.class); } finally { context.clearCache(); } //collectProperty must be invoked only for first call of addClassChecks. Two calls for two annotations verify(context, times(2)).collectPropertyAnnotationChecks(any(List.class), any(PropertyDescriptor.class)); }
@Before public void setUp() throws Exception { pluginDirectory = temporaryFolder.newFolder("pluginDir"); bundleDirectory = temporaryFolder.newFolder("bundleDir"); goPluginDescriptorBuilder = spy(new GoPluginDescriptorBuilder()); doReturn(bundleDirectory).when(goPluginDescriptorBuilder).bundlePath(); }