@Test public void shouldFocus() throws Exception { final Transcript transcript = new Transcript(); view.setOnFocusChangeListener( new View.OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { transcript.add(hasFocus ? "Gained focus" : "Lost focus"); } }); assertFalse(view.isFocused()); assertFalse(view.hasFocus()); transcript.assertNoEventsSoFar(); view.requestFocus(); assertTrue(view.isFocused()); assertTrue(view.hasFocus()); transcript.assertEventsSoFar("Gained focus"); view.clearFocus(); assertFalse(view.isFocused()); assertFalse(view.hasFocus()); transcript.assertEventsSoFar("Lost focus"); }
@Test public void testFocusable() { assertFalse(view.isFocusable()); view.setFocusable(true); assertTrue(view.isFocusable()); view.setFocusable(false); assertFalse(view.isFocusable()); }
@Test public void testClickable() { assertFalse(view.isClickable()); view.setClickable(true); assertTrue(view.isClickable()); view.setClickable(false); assertFalse(view.isClickable()); }
@Test public void testFilterTouchesWhenObscured() { assertFalse(view.getFilterTouchesWhenObscured()); view.setFilterTouchesWhenObscured(true); assertTrue(view.getFilterTouchesWhenObscured()); view.setFilterTouchesWhenObscured(false); assertFalse(view.getFilterTouchesWhenObscured()); }
/** Test of findByShortDescription method, of class BitstreamFormat. */ @Test public void testFindByShortDescription() throws SQLException { BitstreamFormat found = BitstreamFormat.findByShortDescription(context, "Adobe PDF"); assertThat("testFindByShortDescription 0", found, notNullValue()); assertThat("testFindByShortDescription 1", found.getShortDescription(), equalTo("Adobe PDF")); assertFalse("testFindByShortDescription 2", found.isInternal()); found = BitstreamFormat.findByShortDescription(context, "XML"); assertThat("testFindByShortDescription 3", found, notNullValue()); assertThat("testFindByShortDescription 4", found.getShortDescription(), equalTo("XML")); assertFalse("testFindByShortDescription 5", found.isInternal()); }
/** Test of findByMIMEType method, of class BitstreamFormat. */ @Test public void testFindByMIMEType() throws SQLException { BitstreamFormat found = BitstreamFormat.findByMIMEType(context, "text/plain"); assertThat("testFindByMIMEType 0", found, notNullValue()); assertThat("testFindByMIMEType 1", found.getMIMEType(), equalTo("text/plain")); assertFalse("testFindByMIMEType 2", found.isInternal()); found = BitstreamFormat.findByMIMEType(context, "text/xml"); assertThat("testFindByMIMEType 3", found, notNullValue()); assertThat("testFindByMIMEType 4", found.getMIMEType(), equalTo("text/xml")); assertFalse("testFindByMIMEType 5", found.isInternal()); }
@Test public void testResponseChunkedExceedMaxChunkSize() { EmbeddedChannel ch = new EmbeddedChannel(new HttpResponseDecoder(4096, 8192, 32)); ch.writeInbound( Unpooled.copiedBuffer( "HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\n\r\n", CharsetUtil.US_ASCII)); HttpResponse res = ch.readInbound(); assertThat(res.getProtocolVersion(), sameInstance(HttpVersion.HTTP_1_1)); assertThat(res.getStatus(), is(HttpResponseStatus.OK)); byte[] data = new byte[64]; for (int i = 0; i < data.length; i++) { data[i] = (byte) i; } for (int i = 0; i < 10; i++) { assertFalse( ch.writeInbound( Unpooled.copiedBuffer( Integer.toHexString(data.length) + "\r\n", CharsetUtil.US_ASCII))); assertTrue(ch.writeInbound(Unpooled.wrappedBuffer(data))); byte[] decodedData = new byte[data.length]; HttpContent content = ch.readInbound(); assertEquals(32, content.content().readableBytes()); content.content().readBytes(decodedData, 0, 32); content.release(); content = ch.readInbound(); assertEquals(32, content.content().readableBytes()); content.content().readBytes(decodedData, 32, 32); assertArrayEquals(data, decodedData); content.release(); assertFalse(ch.writeInbound(Unpooled.copiedBuffer("\r\n", CharsetUtil.US_ASCII))); } // Write the last chunk. ch.writeInbound(Unpooled.copiedBuffer("0\r\n\r\n", CharsetUtil.US_ASCII)); // Ensure the last chunk was decoded. LastHttpContent content = ch.readInbound(); assertFalse(content.content().isReadable()); content.release(); ch.finish(); assertNull(ch.readInbound()); }
@Test public void testFilterTouchesWhenObscuredWhenLoadedFromXml() { LinearLayout root = new LinearLayout(null); ShadowView.inflate(new Activity(), R.layout.views, root); View defaultView = root.findViewById(R.id.default_view); assertFalse(defaultView.getFilterTouchesWhenObscured()); View filterFalseView = root.findViewById(R.id.filter_touches_false_view); assertFalse(filterFalseView.getFilterTouchesWhenObscured()); View filterTrueView = root.findViewById(R.id.filter_touches_true_view); assertTrue(filterTrueView.getFilterTouchesWhenObscured()); }
@Test public void declaresException() throws Exception { Method remoteExMethod = A.class.getDeclaredMethod("foo", Integer.class); assertTrue(ReflectionUtils.declaresException(remoteExMethod, RemoteException.class)); assertTrue(ReflectionUtils.declaresException(remoteExMethod, ConnectException.class)); assertFalse(ReflectionUtils.declaresException(remoteExMethod, NoSuchMethodException.class)); assertFalse(ReflectionUtils.declaresException(remoteExMethod, Exception.class)); Method illegalExMethod = B.class.getDeclaredMethod("bar", String.class); assertTrue(ReflectionUtils.declaresException(illegalExMethod, IllegalArgumentException.class)); assertTrue(ReflectionUtils.declaresException(illegalExMethod, NumberFormatException.class)); assertFalse(ReflectionUtils.declaresException(illegalExMethod, IllegalStateException.class)); assertFalse(ReflectionUtils.declaresException(illegalExMethod, Exception.class)); }
@Test public void testFocusableWhenLoadedFromXml() { LinearLayout root = new LinearLayout(null); ShadowView.inflate(new Activity(), R.layout.views, root); View defaultView = root.findViewById(R.id.default_view); assertFalse(defaultView.isFocusable()); View focusableFalseView = root.findViewById(R.id.focusable_false_view); assertFalse(focusableFalseView.isFocusable()); View focusableTrueView = root.findViewById(R.id.focusable_true_view); assertTrue(focusableTrueView.isFocusable()); }
@Test public void testZipFileWrite() throws Exception { String outputFileName = null; try { // Get somewhere temporary to write out to outputFileName = File.createTempFile("ItemWriterTest-", ".csv.zip").getAbsolutePath(); // Configure the ItemWriter C24ItemWriter itemWriter = new C24ItemWriter(); itemWriter.setSink(new TextualSink()); itemWriter.setWriterSource(new ZipFileWriterSource()); itemWriter.setup(getStepExecution(outputFileName)); // Write the employees out itemWriter.write(employees); // Close the file itemWriter.cleanup(); // Check that we wrote out what was expected ZipFile zipFile = new ZipFile(outputFileName); Enumeration<? extends ZipEntry> entries = zipFile.entries(); assertNotNull(entries); // Make sure there's at least one entry assertTrue(entries.hasMoreElements()); ZipEntry entry = entries.nextElement(); // Make sure that the trailing .zip has been removed and the leading path has been removed assertFalse(entry.getName().contains(System.getProperty("file.separator"))); assertFalse(entry.getName().endsWith(".zip")); // Make sure that there aren't any other entries assertFalse(entries.hasMoreElements()); try { compareCsv(zipFile.getInputStream(entry), employees); } finally { if (zipFile != null) { zipFile.close(); } } } finally { if (outputFileName != null) { // Clear up our temporary file File file = new File(outputFileName); file.delete(); } } }
@Test public void shouldNotBeFocusableByDefault() throws Exception { assertFalse(view.isFocusable()); view.setFocusable(true); assertTrue(view.isFocusable()); }
@Test public void testHasExtra() throws Exception { Intent intent = new Intent(); assertSame(intent, intent.putExtra("foo", "")); assertTrue(intent.hasExtra("foo")); assertFalse(intent.hasExtra("bar")); }
@Test public void clearClassLoaderForSystemClassLoader() throws Exception { BeanUtils.getPropertyDescriptors(ArrayList.class); assertTrue(CachedIntrospectionResults.strongClassCache.containsKey(ArrayList.class)); CachedIntrospectionResults.clearClassLoader(ArrayList.class.getClassLoader()); assertFalse(CachedIntrospectionResults.strongClassCache.containsKey(ArrayList.class)); }
@Test public void getUniqueDeclaredMethods_withCovariantReturnType() throws Exception { class Parent { @SuppressWarnings("unused") public Number m1() { return new Integer(42); } } class Leaf extends Parent { @Override public Integer m1() { return new Integer(42); } } int m1MethodCount = 0; Method[] methods = ReflectionUtils.getUniqueDeclaredMethods(Leaf.class); for (Method method : methods) { if (method.getName().equals("m1")) { m1MethodCount++; } } assertThat(m1MethodCount, is(1)); assertTrue(ObjectUtils.containsElement(methods, Leaf.class.getMethod("m1"))); assertFalse(ObjectUtils.containsElement(methods, Parent.class.getMethod("m1"))); }
@Test public void dispatchOnAnimationEnd() throws Exception { TestView view1 = new TestView(new Activity()); assertFalse(view1.onAnimationEndWasCalled); shadowOf(view1).finishedAnimation(); assertTrue(view1.onAnimationEndWasCalled); }
@Test public void findsAllCustomers() throws Exception { List<Customer> result = repository.findAll(); assertThat(result, is(notNullValue())); assertFalse(result.isEmpty()); }
@Test public void findsFirstPageOfMatthews() throws Exception { Page<Customer> customers = repository.findByLastname("Matthews", new PageRequest(0, 2)); assertThat(customers.getContent().size(), is(2)); assertFalse(customers.hasPreviousPage()); }
/** Test of findUnknown method, of class BitstreamFormat. */ @Test public void testFindUnknown() throws SQLException { BitstreamFormat found = BitstreamFormat.findUnknown(context); assertThat("testFindUnknown 0", found, notNullValue()); assertThat("testFindUnknown 1", found.getShortDescription(), equalTo("Unknown")); assertFalse("testFindUnknown 2", found.isInternal()); assertThat("testFindUnknown 3", found.getSupportLevel(), equalTo(0)); }
/** Test of setInternal method, of class BitstreamFormat. */ @Test public void testSetInternal() { assertFalse("testSetInternal 0", bf.isInternal()); bf.setInternal(true); assertThat("testSetInternal 1", bf.isInternal(), equalTo(true)); }
@Test public void testBasicFeatures() { Stack stack = new Stack(); assertTrue(stack.isEmpty()); stack.push("first"); assertFalse(stack.isEmpty()); String peek = stack.peek(); assertThat(peek, is("first")); assertFalse(stack.isEmpty()); String pop = stack.pop(); assertThat(pop, is("first")); assertTrue(stack.isEmpty()); }
@Test public void doWithProtectedMethods() { ListSavingMethodCallback mc = new ListSavingMethodCallback(); ReflectionUtils.doWithMethods( TestObject.class, mc, new ReflectionUtils.MethodFilter() { @Override public boolean matches(Method m) { return Modifier.isProtected(m.getModifiers()); } }); assertFalse(mc.getMethodNames().isEmpty()); assertTrue("Must find protected method on Object", mc.getMethodNames().contains("clone")); assertTrue("Must find protected method on Object", mc.getMethodNames().contains("finalize")); assertFalse("Public, not protected", mc.getMethodNames().contains("hashCode")); assertFalse("Public, not protected", mc.getMethodNames().contains("absquatulate")); }
@Test public void testBooleanConverter() { String sql = "select true as val1, false as val2 from (values(0))"; BooleanPOJO pojo = sql2o.createQuery(sql).executeAndFetchFirst(BooleanPOJO.class); assertTrue(pojo.val1); assertFalse(pojo.val2); String sql2 = "select null as val1, null as val2 from (values(0))"; BooleanPOJO pojo2 = sql2o.createQuery(sql2).executeAndFetchFirst(BooleanPOJO.class); assertFalse(pojo2.val1); assertNull(pojo2.val2); String sql3 = "select 'false' as val1, 'true' as val2 from (values(0))"; BooleanPOJO pojo3 = sql2o.createQuery(sql3).executeAndFetchFirst(BooleanPOJO.class); assertFalse(pojo3.val1); assertTrue(pojo3.val2); }
private void testValidCopy(TestObject src, TestObject dest) { src.setName("freddie"); src.setAge(15); src.setSpouse(new TestObject()); assertFalse(src.getAge() == dest.getAge()); ReflectionUtils.shallowCopyFieldState(src, dest); assertEquals(src.getAge(), dest.getAge()); assertEquals(src.getSpouse(), dest.getSpouse()); }
@Test public void removeCalendar() throws Exception { assertFalse(jobStore.removeCalendar("foo")); jobStore.storeCalendar("calendar1", getCalendar(), false, false); assertTrue(jobStore.removeCalendar("calendar1")); assertThat(jobStore.retrieveCalendar("calendar1"), nullValue()); }
@Test public void acceptAndClearClassLoader() throws Exception { BeanWrapper bw = new BeanWrapperImpl(TestBean.class); assertTrue(bw.isWritableProperty("name")); assertTrue(bw.isWritableProperty("age")); assertTrue(CachedIntrospectionResults.strongClassCache.containsKey(TestBean.class)); ClassLoader child = new OverridingClassLoader(getClass().getClassLoader()); Class<?> tbClass = child.loadClass("org.springframework.tests.sample.beans.TestBean"); assertFalse(CachedIntrospectionResults.strongClassCache.containsKey(tbClass)); CachedIntrospectionResults.acceptClassLoader(child); bw = new BeanWrapperImpl(tbClass); assertTrue(bw.isWritableProperty("name")); assertTrue(bw.isWritableProperty("age")); assertTrue(CachedIntrospectionResults.strongClassCache.containsKey(tbClass)); CachedIntrospectionResults.clearClassLoader(child); assertFalse(CachedIntrospectionResults.strongClassCache.containsKey(tbClass)); assertTrue(CachedIntrospectionResults.strongClassCache.containsKey(TestBean.class)); }
@Test public void shouldPostActionsToTheMessageQueue() throws Exception { Robolectric.pauseMainLooper(); TestRunnable runnable = new TestRunnable(); view.post(runnable); assertFalse(runnable.wasRun); Robolectric.unPauseMainLooper(); assertTrue(runnable.wasRun); }
@Test public void shouldPostInvalidateDelayed() throws Exception { Robolectric.pauseMainLooper(); view.postInvalidateDelayed(100); ShadowView shadowView = shadowOf(view); assertFalse(shadowView.wasInvalidated()); Robolectric.unPauseMainLooper(); assertTrue(shadowView.wasInvalidated()); }
@Test public void shouldPostActionsToTheMessageQueueWithDelay() throws Exception { Robolectric.pauseMainLooper(); TestRunnable runnable = new TestRunnable(); view.postDelayed(runnable, 1); assertFalse(runnable.wasRun); Robolectric.getUiThreadScheduler().advanceBy(1); assertTrue(runnable.wasRun); }
/** Test of findNonInternal method, of class BitstreamFormat. */ @Test public void testFindNonInternal() throws SQLException { BitstreamFormat[] found = BitstreamFormat.findNonInternal(context); assertThat("testFindNonInternal 0", found, notNullValue()); int i = 0; for (BitstreamFormat b : found) { i++; assertFalse( "testFindNonInternal " + i + " (" + b.getShortDescription() + ")", b.isInternal()); } }