@Test public void testEditProfile() throws Exception { driver.get(baseUrl + "/"); driver.findElement(By.xpath("(//a[contains(text(),'log in')])[2]")).click(); driver.findElement(By.xpath("(//a[contains(text(),'log in')])[2]")).click(); driver.findElement(By.id("email")).click(); driver.findElement(By.id("email")).clear(); driver.findElement(By.id("email")).sendKeys("*****@*****.**"); driver.findElement(By.id("password")).clear(); driver.findElement(By.id("password")).sendKeys("Eliandtyler1"); driver.findElement(By.id("submit-button")).click(); driver.findElement(By.id("submit-button")).click(); driver.findElement(By.cssSelector("img.avatar-me.js-avatar-me")).click(); driver.findElement(By.cssSelector("img.avatar-me.js-avatar-me")).click(); driver.findElement(By.linkText("Edit Profile & Settings")).click(); driver.findElement(By.linkText("Edit Profile & Settings")).click(); // Warning: assertTextPresent may require manual changes assertTrue(driver.findElement(By.cssSelector("BODY")).getText().matches("^[\\s\\S]*$")); // Warning: assertTextPresent may require manual changes assertTrue(driver.findElement(By.cssSelector("BODY")).getText().matches("^[\\s\\S]*$")); // Warning: assertTextPresent may require manual changes assertTrue(driver.findElement(By.cssSelector("BODY")).getText().matches("^[\\s\\S]*$")); // Warning: assertTextPresent may require manual changes assertTrue(driver.findElement(By.cssSelector("BODY")).getText().matches("^[\\s\\S]*$")); // Warning: assertTextPresent may require manual changes assertTrue(driver.findElement(By.cssSelector("BODY")).getText().matches("^[\\s\\S]*$")); }
@Test public void testLastResponseWithTrailingHeader() { EmbeddedChannel ch = new EmbeddedChannel(new HttpResponseDecoder()); ch.writeInbound( Unpooled.copiedBuffer( "HTTP/1.1 200 OK\r\n" + "Transfer-Encoding: chunked\r\n" + "\r\n" + "0\r\n" + "Set-Cookie: t1=t1v1\r\n" + "Set-Cookie: t2=t2v2; Expires=Wed, 09-Jun-2021 10:18:14 GMT\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)); LastHttpContent lastContent = ch.readInbound(); assertThat(lastContent.content().isReadable(), is(false)); HttpHeaders headers = lastContent.trailingHeaders(); assertEquals(1, headers.names().size()); List<String> values = headers.getAll("Set-Cookie"); assertEquals(2, values.size()); assertTrue(values.contains("t1=t1v1")); assertTrue(values.contains("t2=t2v2; Expires=Wed, 09-Jun-2021 10:18:14 GMT")); lastContent.release(); assertThat(ch.finish(), is(false)); assertThat(ch.readInbound(), is(nullValue())); }
@Test public void updateUpdatesCoinbaseAccount() { Result<Customer> customerResult = gateway.customer().create(new CustomerRequest()); String customerId = customerResult.getTarget().getId(); PaymentMethodRequest venmoRequest = new PaymentMethodRequest().customerId(customerId).paymentMethodNonce(Nonce.VenmoAccount); Result<? extends PaymentMethod> venmoResult = gateway.paymentMethod().create(venmoRequest); VenmoAccount venmoAccount = (VenmoAccount) venmoResult.getTarget(); assertTrue(venmoAccount.isDefault()); PaymentMethodRequest request = new PaymentMethodRequest().customerId(customerId).paymentMethodNonce(Nonce.Coinbase); Result<? extends PaymentMethod> paymentMethodResult = gateway.paymentMethod().create(request); assertTrue(paymentMethodResult.isSuccess()); String token = paymentMethodResult.getTarget().getToken(); PaymentMethodRequest updatePaymentMethodRequest = new PaymentMethodRequest().options().makeDefault(true).done(); Result<? extends PaymentMethod> result = gateway.paymentMethod().update(token, updatePaymentMethodRequest); assertTrue(result.isSuccess()); assertTrue(result.getTarget() instanceof CoinbaseAccount); CoinbaseAccount coinbaseAccount = (CoinbaseAccount) result.getTarget(); assertTrue(coinbaseAccount.isDefault()); }
@Test public void isCglibRenamedMethod() throws SecurityException, NoSuchMethodException { @SuppressWarnings("unused") class C { public void CGLIB$m1$123() {} public void CGLIB$m1$0() {} public void CGLIB$$0() {} public void CGLIB$m1$() {} public void CGLIB$m1() {} public void m1() {} public void m1$() {} public void m1$1() {} } assertTrue(ReflectionUtils.isCglibRenamedMethod(C.class.getMethod("CGLIB$m1$123"))); assertTrue(ReflectionUtils.isCglibRenamedMethod(C.class.getMethod("CGLIB$m1$0"))); assertFalse(ReflectionUtils.isCglibRenamedMethod(C.class.getMethod("CGLIB$$0"))); assertFalse(ReflectionUtils.isCglibRenamedMethod(C.class.getMethod("CGLIB$m1$"))); assertFalse(ReflectionUtils.isCglibRenamedMethod(C.class.getMethod("CGLIB$m1"))); assertFalse(ReflectionUtils.isCglibRenamedMethod(C.class.getMethod("m1"))); assertFalse(ReflectionUtils.isCglibRenamedMethod(C.class.getMethod("m1$"))); assertFalse(ReflectionUtils.isCglibRenamedMethod(C.class.getMethod("m1$1"))); }
private static void testLastResponseWithTrailingHeaderFragmented( byte[] content, int fragmentSize) { EmbeddedChannel ch = new EmbeddedChannel(new HttpResponseDecoder()); int headerLength = 47; // split up the header for (int a = 0; a < headerLength; ) { int amount = fragmentSize; if (a + amount > headerLength) { amount = headerLength - a; } // if header is done it should produce a HttpRequest boolean headerDone = a + amount == headerLength; assertEquals(headerDone, ch.writeInbound(Unpooled.wrappedBuffer(content, a, amount))); a += amount; } ch.writeInbound(Unpooled.wrappedBuffer(content, headerLength, content.length - headerLength)); HttpResponse res = ch.readInbound(); assertThat(res.getProtocolVersion(), sameInstance(HttpVersion.HTTP_1_1)); assertThat(res.getStatus(), is(HttpResponseStatus.OK)); LastHttpContent lastContent = ch.readInbound(); assertThat(lastContent.content().isReadable(), is(false)); HttpHeaders headers = lastContent.trailingHeaders(); assertEquals(1, headers.names().size()); List<String> values = headers.getAll("Set-Cookie"); assertEquals(2, values.size()); assertTrue(values.contains("t1=t1v1")); assertTrue(values.contains("t2=t2v2; Expires=Wed, 09-Jun-2021 10:18:14 GMT")); lastContent.release(); assertThat(ch.finish(), is(false)); assertThat(ch.readInbound(), is(nullValue())); }
@Test public final void testTotalBoxedLongBoxedLongBoxedLong() { final Long[] numbers1 = convertToBoxed(NUMBERS1); final Long[] numbers2 = convertToBoxed(NUMBERS2); for (final Long n1 : numbers1) { for (final Long n2 : numbers2) { for (final Long n3 : numbers1) { @SuppressWarnings("boxing") final long expected = n1 + n2 + n3; final long actual = total(n1, n2, n3); // System.out.println("expected: " + expected + "\nactual: " + actual); assertTrue(expected == actual); } } } final Long[] numbers3 = convertToBoxed(NUMBERS3); final Long[] numbers4 = convertToBoxed(NUMBERS4); for (final Long n1 : numbers3) { for (final Long n2 : numbers4) { for (final Long n3 : numbers3) { @SuppressWarnings("boxing") final long expected = n1 + n2 + n3; final long actual = total(n1, n2, n3); // System.out.println("expected: " + expected + "\nactual: " + actual); assertTrue(expected == actual); } } } }
@Test public void testJodaTime() { sql2o .createQuery("create table testjoda(id int primary key, joda1 datetime, joda2 datetime)") .executeUpdate(); sql2o .createQuery("insert into testjoda(id, joda1, joda2) values(:id, :joda1, :joda2)") .addParameter("id", 1) .addParameter("joda1", new DateTime()) .addParameter("joda2", new DateTime().plusDays(-1)) .addToBatch() .addParameter("id", 2) .addParameter("joda1", new DateTime().plusYears(1)) .addParameter("joda2", new DateTime().plusDays(-2)) .addToBatch() .addParameter("id", 3) .addParameter("joda1", new DateTime().plusYears(2)) .addParameter("joda2", new DateTime().plusDays(-3)) .addToBatch() .executeBatch(); List<JodaEntity> list = sql2o.createQuery("select * from testjoda").executeAndFetch(JodaEntity.class); assertTrue(list.size() == 3); assertTrue(list.get(0).getJoda2().isBeforeNow()); }
@Test public void simpleMessageListener() { ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(Config.class, SimpleMessageListenerTestBean.class); JmsListenerContainerTestFactory factory = context.getBean(JmsListenerContainerTestFactory.class); assertEquals( "One container should have been registered", 1, factory.getListenerContainers().size()); MessageListenerTestContainer container = factory.getListenerContainers().get(0); JmsListenerEndpoint endpoint = container.getEndpoint(); assertEquals("Wrong endpoint type", MethodJmsListenerEndpoint.class, endpoint.getClass()); MethodJmsListenerEndpoint methodEndpoint = (MethodJmsListenerEndpoint) endpoint; assertNotNull(methodEndpoint.getBean()); assertNotNull(methodEndpoint.getMethod()); SimpleMessageListenerContainer listenerContainer = new SimpleMessageListenerContainer(); methodEndpoint.setupListenerContainer(listenerContainer); assertNotNull(listenerContainer.getMessageListener()); assertTrue("Should have been started " + container, container.isStarted()); context.close(); // Close and stop the listeners assertTrue("Should have been stopped " + container, container.isStopped()); }
@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 final void testSumLongLong() { final long[] numbers1 = NUMBERS1; final long[] numbers2 = NUMBERS2; for (final long n1 : numbers1) { for (final long n2 : numbers2) { final long expected = n1 + n2; final long actual = sum(n1, n2); // System.out.println("expected: " + expected + "\nactual: " + actual); assertTrue(expected == actual); } } final long[] numbers3 = NUMBERS3; final long[] numbers4 = NUMBERS4; for (final long n1 : numbers3) { for (final long n2 : numbers4) { final long expected = n1 + n2; final long actual = sum(n1, n2); // System.out.println("expected: " + expected + "\nactual: " + actual); assertTrue(expected == actual); } } }
@Test public void testCaseInsensitive() { sql2o .createQuery( "create table testCI(id2 int primary key, value2 varchar(20), sometext varchar(20), valwithgetter varchar(20))") .executeUpdate(); Query query = sql2o.createQuery( "insert into testCI(id2, value2, sometext, valwithgetter) values(:id, :value, :someText, :valwithgetter)"); for (int i = 0; i < 20; i++) { query .addParameter("id", i) .addParameter("value", "some text " + i) .addParameter("someText", "whatever " + i) .addParameter("valwithgetter", "spaz" + i) .addToBatch(); } query.executeBatch(); List<CIEntity> ciEntities = sql2o .createQuery("select * from testCI") .setCaseSensitive(false) .executeAndFetch(CIEntity.class); assertTrue(ciEntities.size() == 20); // test defaultCaseSensitive; sql2o.setDefaultCaseSensitive(false); List<CIEntity> ciEntities2 = sql2o.createQuery("select * from testCI").executeAndFetch(CIEntity.class); assertTrue(ciEntities2.size() == 20); }
@Test public void testUntitled() throws Exception { driver.get(baseUrl + "en/login"); driver.findElement(By.id("signin_username")).clear(); driver.findElement(By.id("signin_username")).sendKeys("admin"); driver.findElement(By.id("signin_password")).clear(); driver.findElement(By.id("signin_password")).sendKeys("admin"); driver.findElement(By.cssSelector("button.button")).click(); driver.get(baseUrl + "/en/profile/edit"); driver.findElement(By.xpath("(//img[@alt='Leave this community'])[3]")).click(); assertTrue(closeAlertAndGetItsText().matches("^Are you sure[\\s\\S]$")); driver.findElement(By.xpath("(//img[@alt='Leave this community'])[2]")).click(); assertTrue(closeAlertAndGetItsText().matches("^Are you sure[\\s\\S]$")); driver.findElement(By.cssSelector("a[alt=\"Leave\"]")).click(); assertTrue(closeAlertAndGetItsText().matches("^Are you sure[\\s\\S]$")); driver.findElement(By.id("profile_community_comunity")).click(); new Select(driver.findElement(By.id("profile_community_community"))) .selectByVisibleText("My Sample Community #1"); driver.findElement(By.cssSelector("button")).click(); new Select(driver.findElement(By.id("profile_community_community"))) .selectByVisibleText("My Sample Community #2"); driver.findElement(By.cssSelector("button")).click(); new Select(driver.findElement(By.id("profile_community_community"))) .selectByVisibleText("CAPS"); driver.findElement(By.cssSelector("button")).click(); driver.findElement(By.cssSelector("button.button.submitButton")).click(); }
@Test public void canVaultOnTransactionCreate() { TransactionRequest request = new TransactionRequest() .amount(TransactionAmount.AUTHORIZE.amount) .paymentMethodNonce(Nonce.Coinbase) .options() .submitForSettlement(true) .storeInVaultOnSuccess(true) .done(); Result<Transaction> authResult = gateway.transaction().sale(request); assertTrue(authResult.isSuccess()); Transaction transaction = authResult.getTarget(); assertNotNull(transaction); CoinbaseDetails details = transaction.getCoinbaseDetails(); assertNotNull(details); String token = details.getToken(); assertNotNull(token); PaymentMethod account = gateway.paymentMethod().find(token); assertTrue(account instanceof CoinbaseAccount); assertNotNull(account); }
@Test public void test() throws Exception { AsyncMutex mutex = new AsyncMutex(); final RichFuture<Permit> fPermit1 = mutex.acquire(); final RichFuture<Permit> fPermit2 = mutex.acquire(); final RichFuture<Permit> fPermit3 = mutex.acquire(); assertThat(mutex.getNumPermitsAvailable(), is(0)); assertThat(mutex.getNumWaiters(), is(2)); Permit permit1 = fPermit1.apply(); Future<Permit> waitPermit2 = executor.submit( new Callable<Permit>() { public Permit call() throws Exception { return fPermit2.apply(); } }); Future<Permit> waitPermit3 = executor.submit( new Callable<Permit>() { public Permit call() throws Exception { return fPermit3.apply(); } }); try { waitPermit2.get(10, TimeUnit.MILLISECONDS); fail("permit 2"); } catch (TimeoutException e) { assertTrue(true); } try { waitPermit3.get(10, TimeUnit.MILLISECONDS); fail("permit 3"); } catch (TimeoutException e) { assertTrue(true); } assertThat(mutex.getNumPermitsAvailable(), is(0)); assertThat(mutex.getNumWaiters(), is(2)); permit1.release(); assertThat(mutex.getNumPermitsAvailable(), is(0)); assertThat(mutex.getNumWaiters(), is(1)); Permit permitEither = getEither(waitPermit2, waitPermit3); assertThat(mutex.getNumPermitsAvailable(), is(0)); assertThat(mutex.getNumWaiters(), is(1)); permitEither.release(); assertThat(mutex.getNumPermitsAvailable(), is(0)); assertThat(mutex.getNumWaiters(), is(0)); }
// Test some basic stuff; add a few keys, remove a few keys public void testBasic() { assertTrue(_nbhm.isEmpty()); assertThat(_nbhm.putIfAbsent("k1", "v1"), nullValue()); checkSizes(1); assertThat(_nbhm.putIfAbsent("k2", "v2"), nullValue()); checkSizes(2); assertTrue(_nbhm.containsKey("k2")); assertThat(_nbhm.put("k1", "v1a"), is("v1")); assertThat(_nbhm.put("k2", "v2a"), is("v2")); checkSizes(2); assertThat(_nbhm.putIfAbsent("k2", "v2b"), is("v2a")); assertThat(_nbhm.remove("k1"), is("v1a")); assertFalse(_nbhm.containsKey("k1")); checkSizes(1); assertThat(_nbhm.remove("k1"), nullValue()); assertThat(_nbhm.remove("k2"), is("v2a")); checkSizes(0); assertThat(_nbhm.remove("k2"), nullValue()); assertThat(_nbhm.remove("k3"), nullValue()); assertTrue(_nbhm.isEmpty()); assertThat(_nbhm.put("k0", "v0"), nullValue()); assertTrue(_nbhm.containsKey("k0")); checkSizes(1); assertThat(_nbhm.remove("k0"), is("v0")); assertFalse(_nbhm.containsKey("k0")); checkSizes(0); assertThat(_nbhm.replace("k0", "v0"), nullValue()); assertFalse(_nbhm.containsKey("k0")); assertThat(_nbhm.put("k0", "v0"), nullValue()); assertEquals(_nbhm.replace("k0", "v0a"), "v0"); assertEquals(_nbhm.get("k0"), "v0a"); assertThat(_nbhm.remove("k0"), is("v0a")); assertFalse(_nbhm.containsKey("k0")); checkSizes(0); assertThat(_nbhm.replace("k1", "v1"), nullValue()); assertFalse(_nbhm.containsKey("k1")); assertThat(_nbhm.put("k1", "v1"), nullValue()); assertEquals(_nbhm.replace("k1", "v1a"), "v1"); assertEquals(_nbhm.get("k1"), "v1a"); assertThat(_nbhm.remove("k1"), is("v1a")); assertFalse(_nbhm.containsKey("k1")); checkSizes(0); // Insert & Remove KeyBonks until the table resizes and we start // finding Tombstone keys- and KeyBonk's equals-call with throw a // ClassCastException if it sees a non-KeyBonk. NonBlockingIdentityHashMap<KeyBonk, String> dumb = new NonBlockingIdentityHashMap<KeyBonk, String>(); for (int i = 0; i < 10000; i++) { final KeyBonk happy1 = new KeyBonk(i); assertThat(dumb.put(happy1, "and"), nullValue()); if ((i & 1) == 0) dumb.remove(happy1); final KeyBonk happy2 = new KeyBonk(i); // 'equals' but not '==' dumb.get(happy2); } }
@Ignore // TODO: SPR-6327 @Test public void testImportDifferentResourceTypes() { AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(SubResourceConfig.class); assertTrue(ctx.containsBean("propertiesDeclaredBean")); assertTrue(ctx.containsBean("xmlDeclaredBean")); }
@Test public void testImportXml() { AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(ImportXmlConfig.class); assertTrue("did not contain java-declared bean", ctx.containsBean("javaDeclaredBean")); assertTrue("did not contain xml-declared bean", ctx.containsBean("xmlDeclaredBean")); TestBean tb = ctx.getBean("javaDeclaredBean", TestBean.class); assertEquals("myName", tb.getName()); }
@Test public void testImportXmlIsMergedFromSuperclassDeclarations() { AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(SecondLevelSubConfig.class); assertTrue( "failed to pick up second-level-declared XML bean", ctx.containsBean("secondLevelXmlDeclaredBean")); assertTrue("failed to pick up parent-declared XML bean", ctx.containsBean("xmlDeclaredBean")); }
/** * equalsRelative testen * * @throws PolygonShapeException */ @Test public void testEqualsRelative() throws PolygonShapeException { Point move = new Point(0, 0); assertFalse(poly.equalsRelative(null, move)); assertFalse(poly.equalsRelative(new Circle(50, move), move)); // Leeres Polygon assertTrue(poly.equalsRelative(poly, move)); assertFalse(poly.equalsRelative(poly, move.copy().move(2, 1))); // Punkte hinzufügen ArrayList<Point> points = new ArrayList<Point>(); for (int i = 0; i < 20; ++i) points.add(new Point(i, i)); poly.setPoints(points); // Andres Polygon - leer, also sollte nicht gleich sein Polygon poly2 = new Polygon(); assertFalse(poly.equalsRelative(poly2, move)); // Test mit gleichen Punkten poly2.setPoints(points); assertTrue(poly.equalsRelative(poly2, move)); // Alle Punkte verschieben move = new Point(3, 5); for (Point p : points) p.move(move.getX(), move.getY()); poly2.setPoints(points); // Kein Verschiebungsvektor: ungleich assertFalse(poly.equalsRelative(poly2, new Point(0, 0))); // mit Verschiebungsvektor assertTrue(poly.equalsRelative(poly2, move)); // Andere Farben poly.setColor(Color.black); poly2.setColor(Color.green); assertFalse(poly.equalsRelative(poly2, move)); poly2.setColor(poly.getColor()); assertTrue(poly.equalsRelative(poly2, move)); // Verschiedene 'solid' parameter for (int i = 0; i < 4; ++i) { // alle möglichen Werte durchprobieren boolean a = i >= 2; boolean b = i % 2 == 0; poly.setSolid(a); poly2.setSolid(b); // Wenn solid gleich ist, sollte das Polygon auch gleich sein assertThat(a == b, is(equalTo(poly.equalsRelative(poly2, move)))); } }
@Test public void testOptionalNestedFieldClass01() throws Exception { OptionalBaseClass src = new OptionalBaseClass(); src.f1 = null; byte[] raw = MessagePack.pack(src); OptionalBaseClass dst = MessagePack.unpack(raw, OptionalBaseClass.class); assertTrue(src.f0 == dst.f0); assertTrue(src.f1 == dst.f1); }
@Test public void testInterfaceType01() throws Exception { try { TemplateBuilder builder = BuilderSelectorRegistry.getInstance().select(SampleInterface.class); Assert.assertNull(builder); BuilderSelectorRegistry.getInstance().getForceBuilder().buildTemplate(SampleInterface.class); fail(); } catch (TemplateBuildException e) { assertTrue(true); } assertTrue(true); }
@Test public void testOptionalEnumTypeForOrdinal00() throws Exception { SampleOptionalEnumFieldClass src = new SampleOptionalEnumFieldClass(); src.f0 = 0; src.f1 = SampleOptionalEnum.ONE; byte[] raw = MessagePack.pack(src); SampleOptionalEnumFieldClass dst = MessagePack.unpack(raw, SampleOptionalEnumFieldClass.class); assertTrue(src.f0 == dst.f0); assertTrue(src.f1 == dst.f1); }
@Test public void testGeneratePossibleTeam() throws Exception { // Given sut.setTeamSize(5); setExamplePlayerFavor(); List<List<Integer>> exampleTeamList = generateExampleTeamList(); // When sut.generatePossibleTeam(); // Then assertTrue(sut.getTeamList().containsAll(exampleTeamList)); assertTrue(exampleTeamList.containsAll(sut.getTeamList())); }
public void testTimestampAndParams() throws ExecutionException, InterruptedException { NodesHotThreadsResponse response = client().admin().cluster().prepareNodesHotThreads().execute().get(); for (NodeHotThreads node : response.getNodesMap().values()) { String result = node.getHotThreads(); assertTrue(result.indexOf("Hot threads at") != -1); assertTrue(result.indexOf("interval=500ms") != -1); assertTrue(result.indexOf("busiestThreads=3") != -1); assertTrue(result.indexOf("ignoreIdleThreads=true") != -1); } }
@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 testNestedFieldClass00() throws Exception { BaseClass src = new BaseClass(); NestedClass src2 = new NestedClass(); src.f0 = 0; src2.f2 = 2; src.f1 = src2; byte[] raw = MessagePack.pack(src); BaseClass dst = MessagePack.unpack(raw, BaseClass.class); assertTrue(src.f0 == dst.f0); assertTrue(src.f1.f2 == dst.f1.f2); }
@Test public void testOptionalMessagePackMessageFieldClass00() throws Exception { OptionalBaseClass2 src = new OptionalBaseClass2(); OptionalMessagePackMessageClass2 src2 = new OptionalMessagePackMessageClass2(); src.f0 = 0; src2.f2 = 2; src.f1 = src2; byte[] raw = MessagePack.pack(src); OptionalBaseClass2 dst = MessagePack.unpack(raw, OptionalBaseClass2.class); assertTrue(src.f0 == dst.f0); assertTrue(src.f1.f2 == dst.f1.f2); }
/** Test of setExtensions method, of class BitstreamFormat. */ @Test public void setExtensions(String[] exts) { assertThat("setExtensions 0", bf.getExtensions()[0], equalTo("xml")); bf.setExtensions(new String[] {"1", "2", "3"}); assertThat("setExtensions 1", bf.getExtensions(), notNullValue()); assertTrue("setExtensions 2", bf.getExtensions().length == 3); assertThat("setExtensions 3", bf.getExtensions()[0], equalTo("1")); assertThat("setExtensions 4", bf.getExtensions()[1], equalTo("2")); assertThat("setExtensions 5", bf.getExtensions()[2], equalTo("3")); bf.setExtensions(new String[0]); assertThat("setExtensions 6", bf.getExtensions(), notNullValue()); assertTrue("setExtensions 7", bf.getExtensions().length == 0); }
@Test public void testTimeConverter() { String sql = "select current_time as col1 from (values(0))"; Time sqlTime = sql2o.createQuery(sql).executeScalar(Time.class); assertThat(sqlTime, is(notNullValue())); assertTrue(sqlTime.getTime() > 0); Date date = sql2o.createQuery(sql).executeScalar(Date.class); assertThat(date, is(notNullValue())); LocalTime jodaTime = sql2o.createQuery(sql).executeScalar(LocalTime.class); assertTrue(jodaTime.getMillisOfDay() > 0); assertThat(jodaTime.getHourOfDay(), is(equalTo(new LocalTime().getHourOfDay()))); }
@Test public void testUtilDate() { sql2o .createQuery("create table testutildate(id int primary key, d1 datetime, d2 timestamp)") .executeUpdate(); sql2o .createQuery("insert into testutildate(id, d1, d2) values(:id, :d1, :d2)") .addParameter("id", 1) .addParameter("d1", new Date()) .addParameter("d2", new Date()) .addToBatch() .addParameter("id", 2) .addParameter("d1", new Date()) .addParameter("d2", new Date()) .addToBatch() .addParameter("id", 3) .addParameter("d1", new Date()) .addParameter("d2", new Date()) .addToBatch() .executeBatch(); List<UtilDateEntity> list = sql2o.createQuery("select * from testutildate").executeAndFetch(UtilDateEntity.class); assertTrue(list.size() == 3); }