You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

DeclarativeMarginTestBase.java 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. * Copyright 2000-2014 Vaadin Ltd.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.vaadin.tests.server.component;
  17. import org.junit.Assert;
  18. import com.vaadin.shared.ui.MarginInfo;
  19. import com.vaadin.tests.design.DeclarativeTestBase;
  20. import com.vaadin.ui.Layout;
  21. import com.vaadin.ui.Layout.MarginHandler;
  22. public abstract class DeclarativeMarginTestBase<L extends Layout & MarginHandler>
  23. extends DeclarativeTestBase<L> {
  24. protected void testMargins(String componentTag) {
  25. for (int i = 0; i < 16; ++i) {
  26. boolean top = (i & 1) == 1;
  27. boolean right = (i & 2) == 2;
  28. boolean bottom = (i & 4) == 4;
  29. boolean left = (i & 8) == 8;
  30. MarginInfo m = new MarginInfo(top, right, bottom, left);
  31. String design = getMarginTag(componentTag, top, right, bottom, left);
  32. // The assertEquals machinery in DeclarativeTestBase uses bean
  33. // introspection and MarginInfo is not a proper bean. It ends up
  34. // considering *all* MarginInfo objects equal... (#18229)
  35. L layout = read(design);
  36. Assert.assertEquals(m, layout.getMargin());
  37. testWrite(design, layout);
  38. }
  39. }
  40. private String getMarginTag(String componentTag, boolean top,
  41. boolean right, boolean bottom, boolean left) {
  42. String s = "<" + componentTag + " ";
  43. if (left && right && top && bottom) {
  44. s += "margin";
  45. } else {
  46. if (left) {
  47. s += "margin-left ";
  48. }
  49. if (right) {
  50. s += "margin-right ";
  51. }
  52. if (top) {
  53. s += "margin-top ";
  54. }
  55. if (bottom) {
  56. s += "margin-bottom ";
  57. }
  58. }
  59. return s + " />";
  60. }
  61. }