Clover coverage report - DrJava Test Coverage (drjava-20120304-r5456)
Coverage timestamp: Sun Mar 4 2012 03:13:23 CST
file stats: LOC: 110   Methods: 8
NCLOC: 49   Classes: 2
 
 Source file Conditionals Statements Methods TOTAL
TestDocGetter.java 83.3% 87% 87.5% 86.5%
coverage coverage
 1    /*BEGIN_COPYRIGHT_BLOCK
 2    *
 3    * Copyright (c) 2001-2010, JavaPLT group at Rice University (drjava@rice.edu)
 4    * All rights reserved.
 5    *
 6    * Redistribution and use in source and binary forms, with or without
 7    * modification, are permitted provided that the following conditions are met:
 8    * * Redistributions of source code must retain the above copyright
 9    * notice, this list of conditions and the following disclaimer.
 10    * * Redistributions in binary form must reproduce the above copyright
 11    * notice, this list of conditions and the following disclaimer in the
 12    * documentation and/or other materials provided with the distribution.
 13    * * Neither the names of DrJava, the JavaPLT group, Rice University, nor the
 14    * names of its contributors may be used to endorse or promote products
 15    * derived from this software without specific prior written permission.
 16    *
 17    * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 18    * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 19    * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 20    * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
 21    * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 22    * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 23    * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 24    * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
 25    * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 26    * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 27    * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 28    *
 29    * This software is Open Source Initiative approved Open Source Software.
 30    * Open Source Initative Approved is a trademark of the Open Source Initiative.
 31    *
 32    * This file is part of DrJava. Download the current version of this project
 33    * from http://www.drjava.org/ or http://sourceforge.net/projects/drjava/
 34    *
 35    * END_COPYRIGHT_BLOCK*/
 36   
 37    package edu.rice.cs.drjava.model;
 38   
 39    import java.util.HashMap;
 40    import java.io.File;
 41    import java.io.IOException;
 42    import javax.swing.text.BadLocationException;
 43    import java.util.List;
 44    import java.util.ArrayList;
 45   
 46    import edu.rice.cs.util.FileOps;
 47    import edu.rice.cs.util.UnexpectedException;
 48    import edu.rice.cs.drjava.model.definitions.DefinitionsDocument;
 49   
 50    /** Test implementation of the document fetching methods in the GlobalModel interface. */
 51    public class TestDocGetter extends DummyGlobalModel {
 52   
 53    /** Storage for documents and File keys. */
 54    HashMap<File, OpenDefinitionsDocument> docs;
 55   
 56    /** Convenience constructor for no-documents case. */
 57  3 public TestDocGetter() { this(new File[0], new String[0]); }
 58   
 59    /** Primary constructor, builds OpenDefDocs from Strings.
 60    * @param files the keys to use when getting OpenDefDocs
 61    * @param texts the text to put in the OpenDefDocs
 62    */
 63  15 public TestDocGetter(File[] files, String[] texts) {
 64  15 if (files.length != texts.length) {
 65  0 throw new IllegalArgumentException("Argument arrays must match in size.");
 66    }
 67   
 68  15 docs = new HashMap<File, OpenDefinitionsDocument>(texts.length * 2);
 69   
 70  15 GlobalEventNotifier en = new GlobalEventNotifier();
 71  15 for (int i = 0; i < texts.length; i++) {
 72  37 DefinitionsDocument doc = new DefinitionsDocument(en);
 73  37 OpenDefinitionsDocument odoc = new TestOpenDoc(doc);
 74  37 odoc.setFile(files[i]);
 75  37 try { doc.insertString(0, texts[i], null); }
 76  0 catch (BadLocationException e) { throw new UnexpectedException(e); }
 77  37 docs.put(files[i], odoc);
 78    }
 79    }
 80   
 81  34 public OpenDefinitionsDocument getDocumentForFile(File file)
 82    throws IOException {
 83    // Try to find the key in docs.
 84  33 if (docs.containsKey(file)) return docs.get(file);
 85  1 else throw new IllegalStateException("TestDocGetter can't open new files!");
 86    }
 87   
 88  14 public List<OpenDefinitionsDocument> getOpenDefinitionsDocuments() {
 89  14 return new ArrayList<OpenDefinitionsDocument>(docs.values());
 90    }
 91   
 92    /** Test implementation of OpenDefinitionsDocument interface. */
 93    private static class TestOpenDoc extends DummyOpenDefDoc {
 94    DefinitionsDocument _doc;
 95    File _file;
 96  37 TestOpenDoc(DefinitionsDocument d) {
 97  37 _doc = d;
 98  37 _defDoc = d;
 99  37 _file = FileOps.NULL_FILE;
 100    }
 101   
 102    /** This is the only method that we care about. */
 103  0 public DefinitionsDocument getDocument() { return _doc; }
 104   
 105    /** Okay, I lied. We need this one, too. */
 106  7 public File getFile() throws FileMovedException { return _file; }
 107   
 108  38 public void setFile(File f) { _file = f; }
 109    }
 110    }