< prev index next >

core/tests/org.openjdk.jmc.common.test/src/test/java/org/openjdk/jmc/common/test/unit/ContentTypeTest.java

Print this page




  46 import static org.openjdk.jmc.common.unit.UnitLookup.MEMORY;
  47 import static org.openjdk.jmc.common.unit.UnitLookup.TIMESPAN;
  48 import static org.openjdk.jmc.common.unit.UnitLookup.TIMESTAMP;
  49 
  50 import org.junit.Test;
  51 import org.openjdk.jmc.common.test.MCTestCase;
  52 import org.openjdk.jmc.common.unit.IQuantity;
  53 import org.openjdk.jmc.common.unit.IRange;
  54 import org.openjdk.jmc.common.unit.ITypedQuantity;
  55 import org.openjdk.jmc.common.unit.IUnit;
  56 import org.openjdk.jmc.common.unit.LinearKindOfQuantity;
  57 import org.openjdk.jmc.common.unit.LinearUnit;
  58 import org.openjdk.jmc.common.unit.QuantityRange;
  59 import org.openjdk.jmc.common.unit.UnitLookup;
  60 
  61 @SuppressWarnings("nls")
  62 public class ContentTypeTest extends MCTestCase {
  63 
  64         static public void assertContains(String expectedSubStr, String actual) {
  65                 if (!actual.contains(expectedSubStr)) {
  66                         fail("expected to contain:<" + expectedSubStr + "> did not:<" + actual + ">"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
  67                 }
  68         }
  69 
  70         static public void assertNotContain(String unexpectedSubStr, String actual) {
  71                 if (actual.contains(unexpectedSubStr)) {
  72                         fail("didn't expect to contain:<" + unexpectedSubStr + "> did:<" + actual + ">"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
  73                 }
  74         }
  75 
  76         @Test
  77         public void testTimestampInteractive() throws Exception {
  78                 for (IUnit unit : TIMESTAMP.getAllUnits()) {
  79                         // Doesn't work with ms, as the era designator (B.C.E) typically isn't in the used pattern.
  80 //                      IQuantity quantity = unit.quantity(-4937981208836185383L);
  81                         IQuantity quantity = unit.quantity(-49379812088L);
  82                         AdHocQuantityTest.assertInteractiveRoundtrip(quantity);
  83                         quantity = unit.quantity(4937981208836185L);
  84                         AdHocQuantityTest.assertInteractiveRoundtrip(quantity);
  85                 }
  86         }
  87 
  88         @Test
  89         public void testTimestampMilliRangeFormat() throws Exception {
  90                 IRange<IQuantity> range = QuantityRange.createWithEnd(EPOCH_MS.quantity(4200000000123L),
  91                                 EPOCH_MS.quantity(4200000000999L));
  92                 assertContains("999", range.displayUsing(AUTO));




  46 import static org.openjdk.jmc.common.unit.UnitLookup.MEMORY;
  47 import static org.openjdk.jmc.common.unit.UnitLookup.TIMESPAN;
  48 import static org.openjdk.jmc.common.unit.UnitLookup.TIMESTAMP;
  49 
  50 import org.junit.Test;
  51 import org.openjdk.jmc.common.test.MCTestCase;
  52 import org.openjdk.jmc.common.unit.IQuantity;
  53 import org.openjdk.jmc.common.unit.IRange;
  54 import org.openjdk.jmc.common.unit.ITypedQuantity;
  55 import org.openjdk.jmc.common.unit.IUnit;
  56 import org.openjdk.jmc.common.unit.LinearKindOfQuantity;
  57 import org.openjdk.jmc.common.unit.LinearUnit;
  58 import org.openjdk.jmc.common.unit.QuantityRange;
  59 import org.openjdk.jmc.common.unit.UnitLookup;
  60 
  61 @SuppressWarnings("nls")
  62 public class ContentTypeTest extends MCTestCase {
  63 
  64         static public void assertContains(String expectedSubStr, String actual) {
  65                 if (!actual.contains(expectedSubStr)) {
  66                         fail("expected to contain:<" + expectedSubStr + "> did not:<" + actual + ">");
  67                 }
  68         }
  69 
  70         static public void assertNotContain(String unexpectedSubStr, String actual) {
  71                 if (actual.contains(unexpectedSubStr)) {
  72                         fail("didn't expect to contain:<" + unexpectedSubStr + "> did:<" + actual + ">");
  73                 }
  74         }
  75 
  76         @Test
  77         public void testTimestampInteractive() throws Exception {
  78                 for (IUnit unit : TIMESTAMP.getAllUnits()) {
  79                         // Doesn't work with ms, as the era designator (B.C.E) typically isn't in the used pattern.
  80 //                      IQuantity quantity = unit.quantity(-4937981208836185383L);
  81                         IQuantity quantity = unit.quantity(-49379812088L);
  82                         AdHocQuantityTest.assertInteractiveRoundtrip(quantity);
  83                         quantity = unit.quantity(4937981208836185L);
  84                         AdHocQuantityTest.assertInteractiveRoundtrip(quantity);
  85                 }
  86         }
  87 
  88         @Test
  89         public void testTimestampMilliRangeFormat() throws Exception {
  90                 IRange<IQuantity> range = QuantityRange.createWithEnd(EPOCH_MS.quantity(4200000000123L),
  91                                 EPOCH_MS.quantity(4200000000999L));
  92                 assertContains("999", range.displayUsing(AUTO));


< prev index next >