@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 testGetFilterFromString() throws Exception { String string = ""; doReturn(TestZuulFilter.class).when(compiler).compile(string, string); ZuulFilter filter = loader.getFilter(string, string); assertNotNull(filter); assertTrue(filter.getClass() == TestZuulFilter.class); // assertTrue(loader.filterInstanceMapSize() == 1); }
@Test public void testGetFilterFromString() throws Exception { String string = ""; doReturn(TestZuulFilter.class).when(compiler).compile(string, string); ZuulFilter filter = loader.getFilter(string, string); assertNotNull(filter); assertTrue(filter.getClass() == TestZuulFilter.class); // assertTrue(loader.filterInstanceMapSize() == 1); }
static Context mockPackageResourceContext() { Context context = mock(Context.class); PackageManager pm = mock(PackageManager.class); Resources res = mock(Resources.class); doReturn(pm).when(context).getPackageManager(); try { doReturn(res).when(pm).getResourcesForApplication(RESOURCE_PACKAGE); } catch (PackageManager.NameNotFoundException e) { throw new RuntimeException(e); } doReturn(RESOURCE_ID_1).when(res).getIdentifier(RESOURCE_NAME, RESOURCE_TYPE, RESOURCE_PACKAGE); return context; }
@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 testProcessRow_StreamIsNull() throws Exception { PGBulkLoader pgBulkLoaderStreamIsNull = mock( PGBulkLoader.class ); doReturn( null ).when( pgBulkLoaderStreamIsNull ).getRow(); PGBulkLoaderMeta meta = mock( PGBulkLoaderMeta.class ); PGBulkLoaderData data = mock( PGBulkLoaderData.class ); assertEquals( false, pgBulkLoaderStreamIsNull.processRow( meta, data ) ); }
@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); }
ReadableTransactionState build() { final ReadableTransactionState mock = Mockito.mock( ReadableTransactionState.class ); doReturn( new UnmodifiableMap<>( updates ) ).when( mock ).getIndexUpdates( any( SchemaDescriptor.class ) ); final TreeMap<ValueTuple, MutableLongDiffSetsImpl> sortedMap = new TreeMap<>( ValueTuple.COMPARATOR ); sortedMap.putAll( updates ); doReturn( sortedMap ).when( mock ).getSortedIndexUpdates( any( SchemaDescriptor.class ) ); return mock; } }
@Test public void sampleMultiple() { setupLogger(10 * Constants.SECOND_MS); doReturn(true).when(mBaseLogger).isWarnEnabled(); for (int i = 0; i < 10; i++) { mSamplingLogger.warn("warning1"); mSamplingLogger.warn("warning2"); } verify(mBaseLogger, times(1)).warn("warning1"); verify(mBaseLogger, times(1)).warn("warning2"); }
@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")); }
@Test public void testRequestQuoterWithNull() throws Exception { HttpServletRequest request = Mockito.mock(HttpServletRequest.class); Mockito.doReturn(null).when(request).getParameterValues("dummy"); RequestQuoter requestQuoter = new RequestQuoter(request); String[] parameterValues = requestQuoter.getParameterValues("dummy"); Assert.assertEquals("It should return null " + "when there are no values for the parameter", null, parameterValues); }
@Test public void testWriteFile() throws Exception { String path = getClass().getResource( "repositories.xml" ).getPath().replace( "repositories.xml", "new-repositories.xml" ); doReturn( path ).when( repoMeta ).getKettleUserRepositoriesFile(); repoMeta.writeData(); InputStream resourceAsStream = getClass().getResourceAsStream( "new-repositories.xml" ); assertEquals( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + Const.CR + "<repositories>" + Const.CR + " </repositories>" + Const.CR, IOUtils.toString( resourceAsStream ) ); new File( path ).delete(); }
@Test public void getLocationFrom() { HttpPost postMethod = mock( HttpPost.class ); Header locationHeader = new BasicHeader( LOCATION_HEADER, TEST_URL ); doReturn( locationHeader ).when( postMethod ).getFirstHeader( LOCATION_HEADER ); assertEquals( TEST_URL, WebService.getLocationFrom( postMethod ) ); }
@Test public void testNewTransformationsWithContainerObjectId() throws Exception { TransMeta meta = mock( TransMeta.class ); doReturn( new String[] { "X", "Y", "Z" } ).when( meta ).listVariables(); doReturn( new String[] { "A", "B", "C" } ).when( meta ).listParameters(); doReturn( "XYZ" ).when( meta ).getVariable( anyString() ); doReturn( "" ).when( meta ).getParameterDescription( anyString() ); doReturn( "" ).when( meta ).getParameterDefault( anyString() ); doReturn( "ABC" ).when( meta ).getParameterValue( anyString() ); String carteId = UUID.randomUUID().toString(); doReturn( carteId ).when( meta ).getContainerObjectId(); Trans trans = new Trans( meta ); assertEquals( carteId, trans.getContainerObjectId() ); }
@Test public void shouldReturnSdkCommand() throws Exception { TfsCommand expectedTfsCommand = mock(TfsCommand.class); TfsCommandFactory spyCommandFactory = spy(tfsCommandFactory); TfsSDKCommandBuilder commandBuilder = mock(TfsSDKCommandBuilder.class); doReturn(commandBuilder).when(spyCommandFactory).getSDKBuilder(); when(commandBuilder.buildTFSSDKCommand("fingerprint", URL, DOMAIN, USERNAME, PASSWORD, computedWorkspaceName, PROJECT_PATH)).thenReturn(expectedTfsCommand); TfsCommand actualTfsCommand = spyCommandFactory.create(executionContext, URL, DOMAIN, USERNAME, PASSWORD, "fingerprint", PROJECT_PATH); assertThat(actualTfsCommand, is(expectedTfsCommand)); verify(commandBuilder).buildTFSSDKCommand("fingerprint", URL, DOMAIN, USERNAME, PASSWORD, computedWorkspaceName, PROJECT_PATH); }