Refine search
private void doTestCommaDelimitedListToStringArrayLegalMatch(String[] components) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < components.length; i++) { if (i != 0) { sb.append(","); } sb.append(components[i]); } String[] sa = StringUtils.commaDelimitedListToStringArray(sb.toString()); assertTrue("String array isn't null with legal match", sa != null); assertEquals("String array length is correct with legal match", components.length, sa.length); assertTrue("Output equals input", Arrays.equals(sa, components)); }
@Test public void copyFromInputStream() throws IOException { byte[] content = "content".getBytes(); ByteArrayInputStream in = new ByteArrayInputStream(content); ByteArrayOutputStream out = new ByteArrayOutputStream(content.length); int count = FileCopyUtils.copy(in, out); assertEquals(content.length, count); assertTrue(Arrays.equals(content, out.toByteArray())); }
@Test public void testCDependencies() { String[] deps = this.dependentBeansFactory.getDependentBeans("c"); assertTrue(Arrays.equals(new String[] { "int", "long" }, deps)); }
@Test @Parameters public void testGetCacheKey(DimensionSpec dimensionSpec, boolean expectedResult) { Assert.assertEquals(expectedResult, Arrays.equals(lookupDimSpec.getCacheKey(), dimensionSpec.getCacheKey())); }
@Override public Object generate(Object target, Method method, Object... params) { assertTrue("Unexpected parameters: expected: " + Arrays.toString(this.expectedParams) + " but got: " + Arrays.toString(params), Arrays.equals(expectedParams, params)); return new SimpleKey(params); } }
@Test public void testPairs() { assertEquals("AAA=", new String(Base64.encodeBase64(new byte[] { 0, 0 }))); for (int i = -128; i <= 127; i++) { final byte test[] = { (byte) i, (byte) i }; assertTrue(Arrays.equals(test, Base64.decodeBase64(Base64.encodeBase64(test)))); } }
@Test public void testCanonicalPropertyNames() { String[] original = new String[] {"map", "map[key1]", "map['key1']", "map[\"key1\"]", "map[key1][key2]", "map['key1'][\"key2\"]", "map[key1].name", "map['key1'].name", "map[\"key1\"].name"}; String[] canonical = new String[] {"map", "map[key1]", "map[key1]", "map[key1]", "map[key1][key2]", "map[key1][key2]", "map[key1].name", "map[key1].name", "map[key1].name"}; assertTrue(Arrays.equals(canonical, PropertyAccessorUtils.canonicalPropertyNames(original))); }
@SuppressWarnings("resource") // 'in' is deliberately not closed private void testCopy_inputStreamToOutputStreamWithBufferSize(final int bufferSize) throws Exception { InputStream in = new ByteArrayInputStream(inData); in = new YellOnCloseInputStream(in); final ByteArrayOutputStream baout = new ByteArrayOutputStream(); final OutputStream out = new YellOnFlushAndCloseOutputStream(baout, false, true); final long count = IOUtils.copy(in, out, bufferSize); assertEquals("Not all bytes were read", 0, in.available()); assertEquals("Sizes differ", inData.length, baout.size()); assertTrue("Content differs", Arrays.equals(inData, baout.toByteArray())); assertEquals(inData.length,count); }
@Test public void testShuffleBoolean() { final boolean[] array1 = new boolean[]{true, false, true, true, false, false, true, false, false, true}; final boolean[] array2 = ArrayUtils.clone(array1); ArrayUtils.shuffle(array1, new Random(SEED)); assertFalse(Arrays.equals(array1, array2)); assertEquals(5, ArrayUtils.removeAllOccurences(array1, true).length); }
@Test public void testAddObjectArrayBoolean() { boolean[] newArray; newArray = ArrayUtils.add(null, false); assertTrue(Arrays.equals(new boolean[]{false}, newArray)); assertEquals(Boolean.TYPE, newArray.getClass().getComponentType()); newArray = ArrayUtils.add(null, true); assertTrue(Arrays.equals(new boolean[]{true}, newArray)); assertEquals(Boolean.TYPE, newArray.getClass().getComponentType()); final boolean[] array1 = new boolean[]{true, false, true}; newArray = ArrayUtils.add(array1, false); assertTrue(Arrays.equals(new boolean[]{true, false, true, false}, newArray)); assertEquals(Boolean.TYPE, newArray.getClass().getComponentType()); }
@Test public void testBDependencies() { String[] deps = this.dependentBeansFactory.getDependentBeans("b"); assertTrue(Arrays.equals(new String[] { "c" }, deps)); }
static void assertHeader(String key, String value, Header actual) { assertEquals(key, actual.key()); assertTrue(Arrays.equals(value.getBytes(), actual.value())); }
@Test public void testDecode() throws IOException { byte[] expected = Base64 .decode(VALID_PNG.substring(VALID_PNG.indexOf(',') + 1), Base64.DEFAULT); CallBack callback = new CallBack(); fetcher.loadData(Priority.HIGH, callback); byte[] result = new byte[((ByteArrayInputStream) callback.data).available()]; assertEquals(result.length, ((ByteArrayInputStream) callback.data).read(result)); assertTrue(Arrays.equals(result, expected)); assertNull(callback.exception); }
@Test public void testIntDependencies() { String[] deps = this.dependentBeansFactory.getDependentBeans("int"); assertTrue(Arrays.equals(new String[] { "buffer" }, deps)); }
private static void checkXmlContent(final String xml, final String encoding, final String defaultEncoding) throws IOException { final ByteArrayOutputStream out = new ByteArrayOutputStream(); final XmlStreamWriter writer = new XmlStreamWriter(out, defaultEncoding); writer.write(xml); writer.close(); final byte[] xmlContent = out.toByteArray(); assertEquals(encoding, writer.getEncoding()); assertTrue(Arrays.equals(xml.getBytes(encoding), xmlContent)); }
@Test public void testWrite_charSequenceToWriter() throws Exception { final CharSequence csq = new StringBuilder(new String(inData, "US-ASCII")); final ByteArrayOutputStream baout = new ByteArrayOutputStream(); @SuppressWarnings("resource") // deliberately not closed final YellOnFlushAndCloseOutputStream out = new YellOnFlushAndCloseOutputStream(baout, true, true); final Writer writer = new OutputStreamWriter(baout, "US-ASCII"); IOUtils.write(csq, writer); out.off(); writer.flush(); assertEquals("Sizes differ", inData.length, baout.size()); assertTrue("Content differs", Arrays.equals(inData, baout.toByteArray())); }
@Test public void copyToByteArray() throws IOException { byte[] content = "content".getBytes(); ByteArrayInputStream in = new ByteArrayInputStream(content); byte[] result = FileCopyUtils.copyToByteArray(in); assertTrue(Arrays.equals(content, result)); }
private void assertLabels( LabelSet labels, int... expected ) { assertEquals( expected.length, labels.numberOfLabels() ); Arrays.sort( expected ); int[] labelArray = new int[labels.numberOfLabels()]; for ( int i = 0; i < labels.numberOfLabels(); i++ ) { labelArray[i] = labels.label( i ); } Arrays.sort( labelArray ); assertTrue( "labels match expected", Arrays.equals( expected, labelArray ) ); }
@Test public void testWrite_byteArrayToWriter() throws Exception { final ByteArrayOutputStream baout = new ByteArrayOutputStream(); @SuppressWarnings("resource") // deliberately not closed final YellOnFlushAndCloseOutputStream out = new YellOnFlushAndCloseOutputStream(baout, true, true); final Writer writer = new OutputStreamWriter(baout, "US-ASCII"); IOUtils.write(inData, writer); out.off(); writer.flush(); assertEquals("Sizes differ", inData.length, baout.size()); assertTrue("Content differs", Arrays.equals(inData, baout.toByteArray())); }
@Test public void copyFromByteArray() throws IOException { byte[] content = "content".getBytes(); ByteArrayOutputStream out = new ByteArrayOutputStream(content.length); FileCopyUtils.copy(content, out); assertTrue(Arrays.equals(content, out.toByteArray())); }