Java Code Examples for jdk.testlibrary.Asserts#assertNull()

The following examples show how to use jdk.testlibrary.Asserts#assertNull() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestValueDescriptorRecorded.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Throwable {
    Recording r = new Recording();
    r.enable(MyEvent.class).withoutStackTrace();
    r.start();
    MyEvent event = new MyEvent();
    event.commit();
    r.stop();

    List<RecordedEvent> events = Events.fromRecording(r);
    Events.hasEvents(events);
    RecordedEvent recordedEvent = events.get(0);

    for (ValueDescriptor desc : recordedEvent.getFields()) {
        if ("myValue".equals(desc.getName())) {
            Asserts.assertEquals(desc.getLabel(), "myLabel");
            Asserts.assertEquals(desc.getDescription(), "myDescription");
            Asserts.assertEquals(desc.getTypeName(), int.class.getName());
            Asserts.assertFalse(desc.isArray());
            Asserts.assertNull(desc.getContentType());
        }
    }
}
 
Example 2
Source File: TestTimeDuration.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Throwable {
    Recording r = new Recording();
    final Duration duration = Duration.ofMillis(30000);

    r.setDuration(duration);
    Asserts.assertNull(r.getStartTime(), "getStartTime() not null before start");
    Asserts.assertNull(r.getStopTime(), "getStopTime() not null before start");

    final Instant beforeStart = Instant.now();
    r.start();
    final Instant afterStart = Instant.now();

    Asserts.assertNotNull(r.getStartTime(), "getStartTime() null after start()");
    Asserts.assertGreaterThanOrEqual(r.getStartTime(), beforeStart, "getStartTime() < beforeStart");
    Asserts.assertLessThanOrEqual(r.getStartTime(), afterStart, "getStartTime() > afterStart");

    Asserts.assertNotNull(r.getStopTime(), "getStopTime() null after start with duration");
    Asserts.assertGreaterThanOrEqual(r.getStopTime(), beforeStart.plus(duration), "getStopTime() < beforeStart + duration");
    Asserts.assertLessThanOrEqual(r.getStopTime(), afterStart.plus(duration), "getStopTime() > afterStart + duration");

    r.close();
}
 
Example 3
Source File: TestGetId.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Throwable {
    Map<Long, Recording> recordings = new HashMap<>();

    final int iterations = 100;
    for (int i = 0; i < iterations; ++i) {
        Recording newRecording = new Recording();
        System.out.println("created: " + newRecording.getId());
        Recording oldRecording = recordings.get(newRecording.getId());
        Asserts.assertNull(oldRecording, "Duplicate recording ID: " + newRecording.getId());
        recordings.put(newRecording.getId(), newRecording);

        if (i % 3 == 0) {
            Recording closeRecording = recordings.remove(recordings.keySet().iterator().next());
            Asserts.assertNotNull(closeRecording, "Could not find recording in map. Test error.");
            closeRecording.close();
            System.out.println("closed: " + closeRecording.getId());
        }
    }

    for (Recording r : recordings.values()) {
        r.close();
    }
}
 
Example 4
Source File: TestCreateConfigFromReader.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
private static void testOkConfig() throws Exception {
    File settingsFile = new File(DIR, "settings.jfc");
    if(!settingsFile.exists()) throw new RuntimeException("File " + settingsFile.getAbsolutePath() +  " not found ");

        FileReader reader = new FileReader(settingsFile);

        Configuration config = Configuration.create(reader);
        Map<String, String> settings = config.getSettings();

        Asserts.assertEquals(4, settings.size(), "Settings size differes from the expected size");
        String[] keys = {"enabled", "stackTrace", "threshold", "custom"};
        String[] vals = {"true", "true", "1 ms", "5"};
        for(int i=0; i<keys.length; ++i) {
            String fullKey = "com.oracle.jdk.JavaMonitorWait#" + keys[i];
            Asserts.assertEquals(vals[i], settings.get(fullKey), "Settings value differs from the expected: " + keys[i]);
        }
        Asserts.assertEquals(null, settings.get("doesNotExists"), "Error getting on-existent setting");

        Asserts.assertEquals("Oracle", config.getProvider(), "Configuration provider differs from the expected");
        Asserts.assertEquals("TestSettings", config.getLabel(), "Configuration label differs from the expected");
        Asserts.assertEquals("SampleConfiguration", config.getDescription(), "Configuration description differs from the expected");
        Asserts.assertNull(config.getName(), "Name should be null if created from reader");
}
 
Example 5
Source File: TestGetAnnotation.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    EventType type = EventType.getEventType(CustomEvent.class);

    SettingDescriptor annotatedType = Events.getSetting(type, "annotatedType");
    Label al = annotatedType.getAnnotation(Label.class);
    Asserts.assertNull(al); // we should not inherit annotation from type

    Description ad = annotatedType.getAnnotation(Description.class);
    Asserts.assertNull(ad); // we should not inherit annotation from type

    Timestamp at = annotatedType.getAnnotation(Timestamp.class);
    Asserts.assertNull(at); // we should not inherit annotation from type

    SettingDescriptor newName = Events.getSetting(type, "newName");
    Label nl = newName.getAnnotation(Label.class);
    Asserts.assertEquals(nl.value(), "Annotated Method");

    Description nd = newName.getAnnotation(Description.class);
    Asserts.assertEquals(nd.value(), "Description of an annotated method");

    Timespan nt = newName.getAnnotation(Timespan.class);
    Asserts.assertEquals(nt.value(), Timespan.NANOSECONDS);
}
 
Example 6
Source File: TestGetContentType.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    EventType type = EventType.getEventType(CustomEvent.class);

    SettingDescriptor plain = Events.getSetting(type, "plain");
    Asserts.assertNull(plain.getContentType());

    SettingDescriptor annotatedType = Events.getSetting(type, "annotatedType");
    Asserts.assertNull(annotatedType.getContentType(), Timestamp.class.getName());

    SettingDescriptor newName = Events.getSetting(type, "newName");
    Asserts.assertEquals(newName.getContentType(), Timespan.class.getName());

    SettingDescriptor overridden = Events.getSetting(type, "overridden");
    Asserts.assertNull(overridden.getContentType());

    SettingDescriptor protectedBase = Events.getSetting(type, "protectedBase");
    Asserts.assertEquals(protectedBase.getContentType(), Frequency.class);

    SettingDescriptor publicBase = Events.getSetting(type, "publicBase");
    Asserts.assertEquals(publicBase.getContentType(), Timestamp.class.getName());

    SettingDescriptor packageProtectedBase = Events.getSetting(type, "packageProtectedBase");
    Asserts.assertNull(packageProtectedBase.getContentType());

    CustomEvent.assertOnDisk((x, y) -> Objects.equals(x.getContentType(), y.getContentType()) ? 0 : 1);
}
 
Example 7
Source File: TestGetLabel.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    EventType type = EventType.getEventType(CustomEvent.class);

    SettingDescriptor plain = Events.getSetting(type, "plain");
    Asserts.assertNull(plain.getLabel());

    SettingDescriptor annotatedType = Events.getSetting(type, "annotatedType");
    Asserts.assertEquals(AnnotatedSetting.LABEL, annotatedType.getLabel());

    SettingDescriptor newName = Events.getSetting(type, "newName");
    Asserts.assertEquals(newName.getLabel(), "Annotated Method");

    SettingDescriptor overridden = Events.getSetting(type, "overridden");
    Asserts.assertNull(overridden.getLabel());

    SettingDescriptor protectedBase = Events.getSetting(type, "protectedBase");
    Asserts.assertEquals(protectedBase.getLabel(), "Protected Base");

    SettingDescriptor publicBase = Events.getSetting(type, "publicBase");
    Asserts.assertEquals(publicBase.getLabel(), AnnotatedSetting.LABEL);

    SettingDescriptor packageProtectedBase = Events.getSetting(type, "packageProtectedBase");
    Asserts.assertNull(packageProtectedBase.getLabel());

    CustomEvent.assertOnDisk((x, y) -> Objects.equals(x.getLabel(), y.getLabel()) ? 0 : 1);
}
 
Example 8
Source File: TestGetDescription.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    EventType type = EventType.getEventType(CustomEvent.class);

    SettingDescriptor plain = Events.getSetting(type, "plain");
    Asserts.assertNull(plain.getDescription());

    SettingDescriptor annotatedType = Events.getSetting(type, "annotatedType");
    Asserts.assertEquals(annotatedType.getDescription(), AnnotatedSetting.DESCRIPTION);

    SettingDescriptor newName = Events.getSetting(type, "newName");
    Asserts.assertEquals(newName.getDescription(), CustomEvent.DESCRIPTION_OF_AN_ANNOTATED_METHOD);

    SettingDescriptor overridden = Events.getSetting(type, "overridden");
    Asserts.assertNull(overridden.getDescription());

    SettingDescriptor protectedBase = Events.getSetting(type, "protectedBase");
    Asserts.assertEquals(protectedBase.getDescription(), "Description of protected base");

    SettingDescriptor publicBase = Events.getSetting(type, "publicBase");
    Asserts.assertEquals(publicBase.getDescription(), AnnotatedSetting.DESCRIPTION);

    SettingDescriptor packageProtectedBase = Events.getSetting(type, "packageProtectedBase");
    Asserts.assertNull(packageProtectedBase.getDescription());

    CustomEvent.assertOnDisk((x, y) -> Objects.equals(x.getDescription(), y.getDescription()) ? 0 : 1);
}
 
Example 9
Source File: TestGetDescription.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Throwable {
    EventType defaultType = EventType.getEventType(DefaultEvent.class);
    System.out.printf("defaultType.category='%s'%n", defaultType.getCategoryNames());
    System.out.printf("defaultType.desc='%s'%n", defaultType.getDescription());
    System.out.printf("defaultType.label='%s'%n", defaultType.getLabel());

    List<String> defaultCategory = Arrays.asList(new String[] {"Uncategorized"});
    Asserts.assertEquals(defaultType.getCategoryNames(), defaultCategory, "Wrong default category");
    Asserts.assertNull(defaultType.getDescription(), "Wrong default description");
    Asserts.assertEquals(defaultType.getLabel(), null, "Wrong default label"); // JavaDoc says "not null"

    EventType annotatedType = EventType.getEventType(AnnotatedEvent.class);
    System.out.printf("annotated.category='%s'%n", annotatedType.getCategoryNames());
    System.out.printf("annotated.desc='%s'%n", annotatedType.getDescription());
    System.out.printf("annotated.label='%s'%n", annotatedType.getLabel());

    List<String> expectedCategorNames = new ArrayList<>();
    expectedCategorNames.add("MyCategory");
    Asserts.assertEquals(annotatedType.getCategoryNames(), expectedCategorNames, "Wrong default category");
    Asserts.assertEquals(annotatedType.getDescription(), "MyDesc", "Wrong default description");
    Asserts.assertEquals(annotatedType.getLabel(), "MyLabel", "Wrong default label");
}
 
Example 10
Source File: TestConstructor.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Throwable {
    ValueDescriptor vdSimple = new ValueDescriptor(String.class, "message");
    Asserts.assertNull(vdSimple.getAnnotation(Label.class), "Expected getAnnotation()==null");
    Asserts.assertEquals(0, vdSimple.getAnnotationElements().size(), "Expected getAnnotations().size() == 0");

    // Add labelA and verify we can read it back
    List<AnnotationElement> annos = new ArrayList<>();
    AnnotationElement labelA = new AnnotationElement(Label.class, "labelA");
    annos.add(labelA);
    System.out.println("labelA.getClass()" + labelA.getClass());
    ValueDescriptor vdComplex = new ValueDescriptor(String.class, "message", annos);

    final Label outLabel = vdComplex.getAnnotation(Label.class);
    Asserts.assertFalse(outLabel == null, "getLabel(Label.class) was null");
    System.out.println("outLabel.value() = " + outLabel.value());

    // Get labelA from getAnnotations() list
    Asserts.assertEquals(1, vdComplex.getAnnotationElements().size(), "Expected getAnnotations().size() == 1");
    final AnnotationElement outAnnotation = vdComplex.getAnnotationElements().get(0);
    Asserts.assertNotNull(outAnnotation, "outAnnotation was null");
    System.out.printf("Annotation: %s = %s%n", outAnnotation.getTypeName(), outAnnotation.getValue("value"));
    Asserts.assertEquals(outAnnotation, labelA, "Expected firstAnnotation == labelA");

}
 
Example 11
Source File: TestTime.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Throwable {
    Recording r = new Recording();
    Asserts.assertNull(r.getStartTime(), "getStartTime() not null before start");
    Asserts.assertNull(r.getStopTime(), "getStopTime() not null before start");

    final Instant beforeStart = Instant.now();
    r.start();
    final Instant afterStart = Instant.now();

    Asserts.assertNotNull(r.getStartTime(), "getStartTime() null after");
    Asserts.assertGreaterThanOrEqual(r.getStartTime(), beforeStart, "getStartTime() < beforeStart");
    Asserts.assertLessThanOrEqual(r.getStartTime(), afterStart, "getStartTime() > afterStart");
    Asserts.assertNull(r.getStopTime(), "getStopTime() not null before stop");

    final Instant beforeStop = Instant.now();
    r.stop();
    final Instant afterStop = Instant.now();

    Asserts.assertGreaterThanOrEqual(r.getStartTime(), beforeStart, "getStartTime() < beforeStart");
    Asserts.assertLessThanOrEqual(r.getStartTime(), afterStart, "getStartTime() > afterStart");
    Asserts.assertNotNull(r.getStopTime(), "getStopTime() null after stop");
    Asserts.assertGreaterThanOrEqual(r.getStopTime(), beforeStop, "getStopTime() < beforeStop");
    Asserts.assertLessThanOrEqual(r.getStopTime(), afterStop, "getStopTime() > afterStop");

    r.close();

    // Same checks again to make sure close() did not change the times.
    Asserts.assertGreaterThanOrEqual(r.getStartTime(), beforeStart, "getStartTime() < beforeStart");
    Asserts.assertLessThanOrEqual(r.getStartTime(), afterStart, "getStartTime() > afterStart");
    Asserts.assertNotNull(r.getStopTime(), "getStopTime() null after stop");
    Asserts.assertGreaterThanOrEqual(r.getStopTime(), beforeStop, "getStopTime() < beforeStop");
    Asserts.assertLessThanOrEqual(r.getStopTime(), afterStop, "getStopTime() > afterStop");
}
 
Example 12
Source File: TestClassLoadEvent.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Throwable {
    Recording recording = new Recording();
    recording.enable(EVENT_NAME).withThreshold(Duration.ofMillis(0));
    TestClassLoader cl = new TestClassLoader();
    recording.start();
    cl.loadClass(TEST_CLASS_NAME);
    recording.stop();

    List<RecordedEvent> events = Events.fromRecording(recording);
    boolean isLoaded = false;
    for (RecordedEvent event : events) {
        RecordedClass loadedClass = event.getValue("loadedClass");
        if (SEARCH_CLASS_NAME.equals(loadedClass.getName())) {
            System.out.println(event);
            /** unsupported now
            Events.assertClassPackage(loadedClass, SEARCH_PACKAGE_NAME);
            Events.assertClassModule(loadedClass, SEARCH_MODULE_NAME);
            */
            RecordedClassLoader initiatingClassLoader = event.getValue("initiatingClassLoader");
            Asserts.assertEquals(cl.getClass().getName(), initiatingClassLoader.getType().getName(),
                "Expected type " + cl.getClass().getName() + ", got type " + initiatingClassLoader.getType().getName());
            RecordedClassLoader definingClassLoader = loadedClass.getClassLoader();
            Asserts.assertEquals(BOOT_CLASS_LOADER_NAME, definingClassLoader.getName(),
                "Expected boot loader to be the defining class loader");
            Asserts.assertNull(definingClassLoader.getType(), "boot loader should not have a type");
            isLoaded = true;
        }
    }
    Asserts.assertTrue(isLoaded, "No class load event found for class " + SEARCH_CLASS_NAME);
}
 
Example 13
Source File: TestDestToDiskFalse.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Throwable {
    final Path dest = Paths.get(".", "my.jfr");
    Recording r = new Recording();
    SimpleEventHelper.enable(r, true);
    r.setToDisk(false);
    r.setDestination(dest);
    Asserts.assertEquals(dest, r.getDestination(), "Wrong get/set destination");
    r.start();
    SimpleEventHelper.createEvent(0);
    r.stop();

    // setToDisk(false) should not effect setDestination.
    // We should still get a file when the recording stops.
    Asserts.assertTrue(Files.exists(dest), "No recording file: " + dest);
    System.out.printf("File size=%d, getSize()=%d%n", Files.size(dest), r.getSize());
    Asserts.assertNotEquals(Files.size(dest), 0L, "File length 0. Should at least be some bytes");

    List<RecordedEvent> events = RecordingFile.readAllEvents(dest);
    Asserts.assertFalse(events.isEmpty(), "No event found");
    System.out.printf("Found event %s%n", events.get(0).getEventType().getName());

    assertEquals(r.getSize(), 0L, "getSize() should return 0, chunks should have been released at stop");
    // getDestination() should return null after recording have been written to file.
    Asserts.assertNull(r.getDestination(), "getDestination() should return null after file created");

    r.close();
}
 
Example 14
Source File: TestGetField.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Throwable {
    EventType type = EventType.getEventType(MyEvent.class);

    ValueDescriptor v = type.getField("myByte");
    Asserts.assertNotNull(v, "getFiled(myByte) was null");
    Asserts.assertEquals(v.getTypeName(), "byte", "myByte was not type byte");

    v = type.getField("myInt");
    Asserts.assertNotNull(v, "getFiled(myInt) was null");
    Asserts.assertEquals(v.getTypeName(), "int", "myInt was not type int");

    v = type.getField("myStatic");
    Asserts.assertNull(v, "got static field");

    v = type.getField("notAField");
    Asserts.assertNull(v, "got field that does not exist");

    v = type.getField("");
    Asserts.assertNull(v, "got field for empty name");

    try {
        v = type.getField(null);
        Asserts.fail("No Exception when getField(null)");
    } catch (NullPointerException e) {
        // Expected exception
    }
}
 
Example 15
Source File: TestIsArray.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Throwable {
    EventType type = EventType.getEventType(EventWithArray.class);

    ValueDescriptor d = type.getField("myIds");

    Asserts.assertNull(d, "ValueDescriptor for int[] was not null");

    type = EventType.getEventType(EventWithoutArray.class);
    d = type.getField("myId");
    Asserts.assertFalse(d.isArray(), "isArray() was true for int");
}
 
Example 16
Source File: GetAnnotatedOwnerType.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
private static void testNegative(AnnotatedType t, String msg) {
    Asserts.assertNull(t.getAnnotatedOwnerType(), msg);
}
 
Example 17
Source File: TestOwnCommit.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Throwable {
   Recording r = new Recording();
    r.enable(MyEvent.class);

    r.start();

    MyEvent event = new MyEvent();
    event.begin();
    event.begin = 10;
    event.duration = Instant.now();
    MyEvent.startTime = 20;
    event.shouldCommit = "shouldCommit";
    MyEvent.set = 30;
    event.end();
    event.commit();

    // Verify that our methods have not been removed by transformation.
    int id = 0;
    event.begin(++id);
    Asserts.assertEquals(id, staticTestValue, "EventWithBegin failed to set value");
    event.end(++id);
    Asserts.assertEquals(id, staticTestValue, "EventWithEnd failed to set value");
    event.commit(++id);
    Asserts.assertEquals(id, staticTestValue, "EventWithCommit failed to set value");
    event.shouldCommit(++id);
    Asserts.assertEquals(id, staticTestValue, "EventWithShouldCommit failed to set value");
    event.set(++id);
    Asserts.assertEquals(id, staticTestValue, "EventWithSet failed to set value");

    r.stop();

    Iterator<RecordedEvent> it = Events.fromRecording(r).iterator();
    Asserts.assertTrue(it.hasNext(), "No events");
    RecordedEvent recordedEvent = it.next();
    Asserts.assertTrue(Events.isEventType(recordedEvent, MyEvent.class.getName()));
    Events.assertField(recordedEvent, "begin").equal(10L);
    Events.assertField(recordedEvent, "shouldCommit").equal("shouldCommit");
    Events.assertField(recordedEvent, "startTime");
    Events.assertField(recordedEvent, "duration");
    Asserts.assertNull(recordedEvent.getEventType().getField("set")); // static not supported
    Asserts.assertFalse(it.hasNext(), "More than 1 event");

    r.close();
}
 
Example 18
Source File: TestDestInvalid.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Throwable {
    Recording r = new Recording();
    r.enable(EventNames.OSInformation);
    r.setToDisk(true);

    Asserts.assertNull(r.getDestination(), "dest not null by default");

    // Set destination to empty path (same as curr dir, not a file)
    verifyException(()->{r.setDestination(Paths.get(""));}, "No exception for setDestination(\"\")", IOException.class);
    System.out.println("1 destination: " + r.getDestination());
    Asserts.assertNull(r.getDestination(), "default dest not null after failed setDest");

    // Set dest to a valid path. This should be kept when a new setDest fails.
    Path dest = Paths.get(".", "my.jfr");
    r.setDestination(dest);
    System.out.println("2 destination: " + r.getDestination());
    Asserts.assertEquals(dest, r.getDestination(), "Wrong get/set dest");

    // Null is allowed for setDestination()
    r.setDestination(null);
    System.out.println("3 destination: " + r.getDestination());
    Asserts.assertNull(r.getDestination(), "dest not null after setDest(null)");

    // Reset dest to correct value and make ssure it is not overwritten
    r.setDestination(dest);
    System.out.println("4 destination: " + r.getDestination());
    Asserts.assertEquals(dest, r.getDestination(), "Wrong get/set dest");

    // Set destination to an existing dir. Old dest is saved.
    verifyException(()->{r.setDestination(Paths.get("."));}, "No exception for setDestination(.)", IOException.class);
    System.out.println("5 destination: " + r.getDestination());
    Asserts.assertEquals(dest, r.getDestination(), "Wrong get/set dest");

    // Set destination to a non-existing dir. Old dest is saved.
    verifyException(()->{r.setDestination(Paths.get(".", "missingdir", "my.jfr"));}, "No exception for setDestination(dirNotExists)", IOException.class);
    System.out.println("6 destination: " + r.getDestination());
    Asserts.assertEquals(dest, r.getDestination(), "Wrong get/set dest");

    // Verify that it works with the old setDest value.
    r.start();
    r.stop();
    r.close();
    Asserts.assertTrue(Files.exists(dest), "No recording file: " + dest);
    List<RecordedEvent> events = RecordingFile.readAllEvents(dest);
    Asserts.assertFalse(events.isEmpty(), "No event found");
    System.out.printf("Found event %s in %s%n", events.get(0).getEventType().getName(), dest.toString());
}
 
Example 19
Source File: TestTimeMultiple.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Throwable {
    Recording rA = new Recording();
    Asserts.assertNull(rA.getStartTime(), "getStartTime() not null before start");
    Asserts.assertNull(rA.getStopTime(), "getStopTime() not null before start");

    final Instant beforeStartA = Instant.now();
    rA.start();
    final Instant afterStartA = Instant.now();

    Recording rB = new Recording();
    Asserts.assertNull(rB.getStartTime(), "getStartTime() not null before start");
    Asserts.assertNull(rB.getStopTime(), "getStopTime() not null before start");

    final Instant beforeStartB = Instant.now();
    rB.start();
    final Instant afterStartB = Instant.now();

    final Instant beforeStopB = Instant.now();
    rB.stop();
    final Instant afterStopB = Instant.now();

    final Instant beforeStopA = Instant.now();
    rA.stop();
    final Instant afterStopA = Instant.now();

    rA.close();
    rB.close();

    Asserts.assertNotNull(rA.getStartTime(), "getStartTime() null after start");
    Asserts.assertNotNull(rA.getStopTime(), "getStopTime() null after stop");
    Asserts.assertGreaterThanOrEqual(rA.getStartTime(), beforeStartA, "getStartTime() < beforeStart");
    Asserts.assertLessThanOrEqual(rA.getStartTime(), afterStartA, "getStartTime() > afterStart");
    Asserts.assertGreaterThanOrEqual(rA.getStopTime(), beforeStopA, "getStopTime() < beforeStop");
    Asserts.assertLessThanOrEqual(rA.getStopTime(), afterStopA, "getStopTime() > afterStop");

    Asserts.assertNotNull(rB.getStartTime(), "getStartTime() null after start");
    Asserts.assertNotNull(rB.getStopTime(), "getStopTime() null after stop");
    Asserts.assertGreaterThanOrEqual(rB.getStartTime(), beforeStartB, "getStartTime() < beforeStart");
    Asserts.assertLessThanOrEqual(rB.getStartTime(), afterStartB, "getStartTime() > afterStart");
    Asserts.assertGreaterThanOrEqual(rB.getStopTime(), beforeStopB, "getStopTime() < beforeStop");
    Asserts.assertLessThanOrEqual(rB.getStopTime(), afterStopB, "getStopTime() > afterStop");
}