Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: f031eab9a419ea78d4af80a5c09361a66ef0435a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/*
 * Copyright (c) 2012 Eike Stepper (Berlin, Germany) and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    Christian W. Damus (CEA) - initial API and implementation
 */
package org.eclipse.emf.cdo.tests.model5.util;

import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

import org.junit.Assert;

/**
 * Test fixture for the CDO resource "is loading" tests. Bug 393164.
 */
public class IsLoadingTestFixture
{
  private static IsLoadingTestFixture instance;

  private Map<Resource, Set<EObject>> objectsReportedLoading = new HashMap<Resource, Set<EObject>>();

  private IsLoadingTestFixture()
  {
  }

  public static IsLoadingTestFixture newInstance()
  {
    IsLoadingTestFixture result = new IsLoadingTestFixture();
    instance = result;
    return result;
  }

  public void dispose()
  {
    if (instance == this)
    {
      instance = null;
    }

    objectsReportedLoading.clear();
  }

  public static void reportLoading(Resource resource, EObject object)
  {
    if (instance != null)
    {
      instance.doReportLoading(resource, object);
    }
  }

  private Set<EObject> demandObjectsReportedLoading(Resource resource)
  {
    Set<EObject> result = objectsReportedLoading.get(resource);
    if (result == null)
    {
      result = new java.util.HashSet<EObject>();
      objectsReportedLoading.put(resource, result);
    }

    return result;
  }

  private Set<EObject> getObjectsReportedLoading(Resource resource)
  {
    Set<EObject> result = objectsReportedLoading.get(resource);
    if (result == null)
    {
      result = Collections.emptySet();
    }

    return result;
  }

  private void doReportLoading(Resource resource, EObject object)
  {
    if (resource instanceof Resource.Internal && ((Resource.Internal)resource).isLoading())
    {
      demandObjectsReportedLoading(resource).add(object);
    }
  }

  public void assertReportedLoading(Resource resource, EObject object)
  {
    Assert.assertEquals("Object did not report loading: " + object, true,
        getObjectsReportedLoading(resource).contains(object));
  }

  public void assertNotReportedLoading(Resource resource, EObject object)
  {
    Assert.assertEquals("Object reported loading: " + object, false,
        getObjectsReportedLoading(resource).contains(object));
  }
}

Back to the top