1 19 20 package org.netbeans.modules.diff; 21 22 import java.io.*; 23 24 import org.netbeans.junit.*; 25 import org.netbeans.api.diff.DiffView; 26 import org.netbeans.api.diff.Difference; 27 import org.netbeans.api.diff.StreamSource; 28 29 33 public abstract class DiffViewAbstract extends NbTestCase { 34 35 private DiffView dv; 36 37 public DiffViewAbstract(String name) { 38 super(name); 39 } 40 41 protected abstract DiffView createDiffView(StreamSource ss1, StreamSource ss2) throws IOException; 42 43 protected void setUp() throws Exception { 44 dv = createDiffView(new Impl("name1", "title1", "text/plain", "content1\nsame\ndifferent1"), new Impl("name2", "title2", "text/plain", "content2\nsame\ndifferent2")); 45 } 46 47 public void testCanDiffConsistent() throws Exception { 48 if (dv.canSetCurrentDifference()) { 49 dv.setCurrentDifference(0); 50 } else { 51 try { 52 dv.setCurrentDifference(0); 53 fail("Should throw UnsupportedOperationException"); 54 } catch (UnsupportedOperationException uoex) { 55 } 57 } 58 } 59 60 public void testCurrentDifference() throws Exception { 61 if (dv.canSetCurrentDifference()) { 62 int dc = dv.getDifferenceCount(); 63 assertEquals("Just one difference", 2, dc); 64 dv.setCurrentDifference(1); 65 assertEquals("Test current difference", 1, dv.getCurrentDifference()); 66 try { 67 dv.setCurrentDifference(10); 68 fail("Should report an exception."); 69 } catch (IllegalArgumentException ioex) { 70 } 72 } 73 } 74 75 78 private static class Impl extends StreamSource { 79 80 private String name; 81 private String title; 82 private String MIMEType; 83 private Reader r; 84 private String buffer; 85 private Writer w; 86 87 Impl(String name, String title, String MIMEType, String str) { 88 this.name = name; 89 this.title = title; 90 this.MIMEType = MIMEType; 91 this.w = null; 92 buffer = str; 93 } 94 95 public String getName() { 96 return name; 97 } 98 99 public String getTitle() { 100 return title; 101 } 102 103 public String getMIMEType() { 104 return MIMEType; 105 } 106 107 public Reader createReader() throws IOException { 108 return new StringReader(buffer); 109 } 110 111 public Writer createWriter(Difference[] conflicts) throws IOException { 112 return null; 113 } 114 } 115 116 } 117 | Popular Tags |