Skip to main content
summaryrefslogtreecommitdiffstats
blob: 548f59b86e57b54ff9d93b9d57a6335d8ef166c1 (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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
/**********************************************************************
 * This file is part of "Object Teams Development Tooling"-Software
 *
 * Copyright 2004, 2013 Fraunhofer Gesellschaft, Munich, Germany,
 * for its Fraunhofer Institute and Computer Architecture and Software
 * Technology (FIRST), Berlin, Germany and Technical University Berlin,
 * Germany.
 *
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Please visit http://www.eclipse.org/objectteams for updates and contact.
 *
 * Contributors:
 * 	  Fraunhofer FIRST - Initial API and implementation
 * 	  Technical University Berlin - Initial API and implementation
 **********************************************************************/
package org.eclipse.objectteams.otdt.ui.tests.refactoring;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.StringBufferInputStream;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import junit.framework.TestCase;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IField;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.IMember;
import org.eclipse.jdt.core.IMethod;
import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jdt.core.IPackageFragmentRoot;
import org.eclipse.jdt.core.ISourceManipulation;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.core.search.IJavaSearchConstants;
import org.eclipse.jdt.core.search.ITypeNameRequestor;
import org.eclipse.jdt.core.search.SearchEngine;
import org.eclipse.jdt.core.search.SearchPattern;
import org.eclipse.jdt.internal.corext.refactoring.util.JavaElementUtil;
import org.eclipse.jdt.internal.corext.util.Strings;
import org.eclipse.ltk.core.refactoring.Change;
import org.eclipse.ltk.core.refactoring.CheckConditionsOperation;
import org.eclipse.ltk.core.refactoring.CreateChangeOperation;
import org.eclipse.ltk.core.refactoring.IUndoManager;
import org.eclipse.ltk.core.refactoring.PerformChangeOperation;
import org.eclipse.ltk.core.refactoring.Refactoring;
import org.eclipse.ltk.core.refactoring.RefactoringCore;
import org.eclipse.ltk.core.refactoring.RefactoringDescriptor;
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
import org.eclipse.objectteams.otdt.core.IOTJavaElement;
import org.eclipse.objectteams.otdt.internal.core.AbstractCalloutMapping;

@SuppressWarnings("restriction")
public abstract class RefactoringTest extends TestCase
{
    private IPackageFragmentRoot _root;
    private IPackageFragment _packageP;

    public boolean _isVerbose = false;

    public static final String TEST_PATH_PREFIX = "";

    protected static final String TEST_INPUT_INFIX = "/in/";
    protected static final String TEST_OUTPUT_INFIX = "/out/";
    protected static final String CONTAINER = "src";

    public RefactoringTest(String name)
    {
        super(name);
    }

    protected void setUp() throws Exception
    {
        _root = MySetup.getDefaultSourceFolder();
        _packageP = MySetup.getPackageP();

        if (_isVerbose)
        {
            System.out
                    .println("\n---------------------------------------------");
            System.out.println("\nTest:" + getClass() + "." + getName());
        }
        RefactoringCore.getUndoManager().flush();
    }

    protected void tearDown() throws Exception
    {
        refreshFromLocal();
        performDummySearch();

        if (getPackageP().exists())
        {
            tryDeletingAllJavaChildren(getPackageP());
            tryDeletingAllNonJavaChildResources(getPackageP());
        }

        if (getRoot().exists())
        {
            IJavaElement[] packages = getRoot().getChildren();
            for (int i = 0; i < packages.length; i++)
            {
                try
                {
                    IPackageFragment pack = (IPackageFragment)packages[i];
                    if (!pack.equals(getPackageP()) && pack.exists()
                            && !pack.isReadOnly())
                        pack.delete(true, null);
                }
                catch (JavaModelException ex)
                {
                    //try to delete'em all
                    ex.printStackTrace();
                }
            }
        }
    }

    private void refreshFromLocal() throws CoreException
    {
        if (getRoot().exists())
        {
            getRoot().getResource().
            		  refreshLocal(IResource.DEPTH_INFINITE, null);
        }
        else if (getPackageP().exists())//don't refresh package if root already refreshed
        {
            getPackageP().getResource().
            			  refreshLocal(IResource.DEPTH_INFINITE, null);
        }
    }

    private static void tryDeletingAllNonJavaChildResources(
            IPackageFragment pack) throws JavaModelException
    {
        Object[] nonJavaKids = pack.getNonJavaResources();
        for (int i = 0; i < nonJavaKids.length; i++)
        {
            if (nonJavaKids[i] instanceof IResource)
            {
                IResource resource = (IResource)nonJavaKids[i];
                try
                {
                    resource.delete(true, null);
                }
                catch (CoreException ex)
                {
                    //try to delete'em all
                    ex.printStackTrace();
                }
            }
        }
    }

    private static void tryDeletingAllJavaChildren(IPackageFragment pack)
            throws JavaModelException
    {
        IJavaElement[] kids = pack.getChildren();
        for (int i = 0; i < kids.length; i++)
        {
            if (kids[i] instanceof ISourceManipulation)
            {
                try
                {
                    if (kids[i].exists() && !kids[i].isReadOnly())
                        ((ISourceManipulation)kids[i]).delete(true, null);
                }
                catch (JavaModelException ex)
                {
                    //try to delete'em all
                    ex.printStackTrace();
                }
            }
        }
    }

    protected IPackageFragmentRoot getRoot()
    {
        return _root;
    }

    protected IPackageFragment getPackageP()
    {
        return _packageP;
    }

    protected final Refactoring createRefactoring(RefactoringDescriptor descriptor) throws CoreException {
	    RefactoringStatus status= new RefactoringStatus();
		Refactoring refactoring= descriptor.createRefactoring(status);
		assertNotNull("refactoring should not be null", refactoring);
		assertTrue("status should be ok", status.isOK());
	    return refactoring;
    }

	protected final RefactoringStatus performRefactoring(RefactoringDescriptor descriptor) throws Exception {
		return performRefactoring(descriptor, true);
	}

	protected final RefactoringStatus performRefactoring(RefactoringDescriptor descriptor, boolean providesUndo) throws Exception {
		Refactoring refactoring= createRefactoring(descriptor);
		return performRefactoring(refactoring, providesUndo);
	}

    protected final RefactoringStatus performRefactoring(Refactoring ref)
            throws Exception
    {
        return performRefactoring(ref, true);
    }

    protected final RefactoringStatus performRefactoring(Refactoring ref,
            boolean providesUndo) throws Exception
    {
        performDummySearch();
        IUndoManager undoManager = getUndoManager();
        CreateChangeOperation create = new CreateChangeOperation(
                new CheckConditionsOperation(ref,
                        CheckConditionsOperation.ALL_CONDITIONS),
                RefactoringStatus.FATAL);
        PerformChangeOperation perform = new PerformChangeOperation(create);
        perform.setUndoManager(undoManager, ref.getName());
        ResourcesPlugin.getWorkspace().run(perform, new NullProgressMonitor());
        RefactoringStatus status = create.getConditionCheckingStatus();
        if (!status.isOK())
        {
            return status;
        }
        assertTrue("Change wasn't executed", perform.changeExecuted());
        Change undo = perform.getUndoChange();
        if (providesUndo)
        {
            assertNotNull("Undo doesn't exist", undo);
            assertTrue("Undo manager is empty", undoManager.anythingToUndo());
        }
        else
        {
            assertNull("Undo manager contains undo but shouldn't", undo);
        }
        return null;
    }

    protected final RefactoringStatus performRefactoringWithStatus(
            Refactoring ref) throws Exception
    {
        performDummySearch();
        CreateChangeOperation create = new CreateChangeOperation(
                new CheckConditionsOperation(ref,
                        CheckConditionsOperation.ALL_CONDITIONS),
                RefactoringStatus.FATAL);
        PerformChangeOperation perform = new PerformChangeOperation(create);
        perform.setUndoManager(RefactoringCore.getUndoManager(), ref.getName());
        ResourcesPlugin.getWorkspace().run(perform, new NullProgressMonitor());
        RefactoringStatus status = create.getConditionCheckingStatus();
        if (status.hasFatalError())
        {
            return status;
        }
        assertTrue("Change wasn't executed", perform.changeExecuted());
        return status;
    }

    protected void performDummySearch() throws Exception
    {
        performDummySearch(getPackageP());
    }

    protected final Change performChange(final Refactoring refactoring,
            boolean storeUndo) throws Exception
    {
        CreateChangeOperation create = new CreateChangeOperation(refactoring);
        PerformChangeOperation perform = new PerformChangeOperation(create);
        if (storeUndo)
        {
            perform.setUndoManager(getUndoManager(), refactoring.getName());
        }
        ResourcesPlugin.getWorkspace().run(perform, new NullProgressMonitor());
        assertTrue("Change wasn't executed", perform.changeExecuted());
        return perform.getUndoChange();
    }

    protected final Change performChange(final Change change) throws Exception
    {
        PerformChangeOperation perform = new PerformChangeOperation(change);
        ResourcesPlugin.getWorkspace().run(perform, new NullProgressMonitor());
        assertTrue("Change wasn't executed", perform.changeExecuted());
        return perform.getUndoChange();
    }

    protected IUndoManager getUndoManager()
    {
        IUndoManager undoManager = RefactoringCore.getUndoManager();
        undoManager.flush();
        return undoManager;
    }

    /** ************** helpers ***************** */
    /** ** mostly not general, just shortcuts **** */

    protected IType getType(ICompilationUnit cu, String name)
            throws JavaModelException
    {
        IType[] types = cu.getAllTypes();
        for (int i = 0; i < types.length; i++)
        {
            if (types[i].getFullyQualifiedName().equals(name)
                    || types[i].getElementName().equals(name))
            {
                return types[i];
            }
        }
        return null;
    }

    /**
     * subclasses override to inform about the location of their test cases
     */
    protected String getRefactoringPath()
    {
        return "";
    }

    /**
     * example "RenameType/"
     */
    protected String getTestPath()
    {
        return TEST_PATH_PREFIX + getRefactoringPath();
    }

    /**
     * @param cuName
     * @param infix
     *            example "RenameTest/test0 + infix + cuName.java"
     */
    protected String createTestFileName(String cuName, String infix)
    {
        return getTestPath() + getName() + infix + cuName + ".java";
    }

    protected String getInputTestFileName(String cuName)
    {
        return createTestFileName(cuName, TEST_INPUT_INFIX);
    }

    /**
     * @param subDirName
     *            example "p/" or "org/eclipse/jdt/"
     */
    protected String getInputTestFileName(String cuName, String subDirName)
    {
        return createTestFileName(cuName, TEST_INPUT_INFIX + subDirName);
    }

    protected String getOutputTestFileName(String cuName)
    {
        return createTestFileName(cuName, TEST_OUTPUT_INFIX);
    }

    /**
     * @param subDirName
     *            example "p/" or "org/eclipse/jdt/"
     */
    protected String getOutputTestFileName(String cuName, String subDirName)
    {
        return createTestFileName(cuName, TEST_OUTPUT_INFIX + subDirName);
    }

    protected ICompilationUnit createCUfromTestFile(IPackageFragment pack,
            String cuName) throws Exception
    {
        return createCUfromTestFile(pack, cuName, true);
    }

    protected ICompilationUnit createCUfromTestFile(IPackageFragment pack,
            String cuName, String subDirName) throws Exception
    {
        return createCUfromTestFile(pack, cuName, subDirName, true);
    }

    protected ICompilationUnit createCUfromTestFile(IPackageFragment pack,
            String cuName, boolean input) throws Exception
    {
        String contents = input ? getFileContents(getInputTestFileName(cuName))
                : getFileContents(getOutputTestFileName(cuName));
        return createCU(pack, cuName + ".java", contents);
    }

    protected ICompilationUnit createCUfromTestFile(IPackageFragment pack,
            String cuName, String subDirName, boolean input) throws Exception
    {
        String contents = input ? getFileContents(getInputTestFileName(cuName,
                subDirName)) : getFileContents(getOutputTestFileName(cuName,
                subDirName));

        return createCU(pack, cuName + ".java", contents);
    }

    protected void printTestDisabledMessage(String explanation)
    {
        System.out.println("\n" + getClass().getName() + "::" + getName()
                + " disabled (" + explanation + ")");
    }

    protected ICompilationUnit[] createCUs(String[] cuNames) throws Exception {
		ICompilationUnit[] cus = new ICompilationUnit[cuNames.length];

		for (int idx = 0; idx < cuNames.length; idx++) {
			Assert.isNotNull(cuNames[idx]);
			cus[idx] = createCUfromTestFile(getPackageP(), cuNames[idx]);
		}
		return cus;
	}

	protected String createInputTestFileName(ICompilationUnit[] cus, int idx) {
		return getInputTestFileName(getSimpleNameOfCu(cus[idx].getElementName()));
	}

	protected String createOutputTestFileName(ICompilationUnit[] cus, int idx) {
		return getOutputTestFileName(getSimpleNameOfCu(cus[idx].getElementName()));
	}

	private String getSimpleNameOfCu(String compUnit) {
		int dot = compUnit.lastIndexOf('.');
		return compUnit.substring(0, dot);
	}

	//-----------------------
    public static InputStream getStream(String content)
    {
        return new StringBufferInputStream(content);
    }

    public static IPackageFragmentRoot getSourceFolder(
            IJavaProject javaProject, String name) throws JavaModelException
    {
        IPackageFragmentRoot[] roots = javaProject.getPackageFragmentRoots();
        for (int i = 0; i < roots.length; i++)
        {
            if (!roots[i].isArchive() && roots[i].getElementName().equals(name))
                return roots[i];
        }
        return null;
    }

    public static String getFileContents(String fileName) throws IOException
    {
        return getContents(getFileInputStream(fileName));
    }

    public static String getContents(IFile file) throws IOException,
            CoreException
    {
        return getContents(file.getContents());
    }

    public static ICompilationUnit createCU(IPackageFragment pack, String name,
            String contents) throws Exception
    {
        if (pack.getCompilationUnit(name).exists())
        {
            return pack.getCompilationUnit(name);
        }
        ICompilationUnit cu = pack.createCompilationUnit(name, contents, true,
                null);
        cu.save(null, true);
        return cu;
    }

    public static String getContents(InputStream in) throws IOException
    {
        BufferedReader br = new BufferedReader(new InputStreamReader(in));
        StringBuffer sb = new StringBuffer(300);
        try
        {
            int read = 0;
            while ((read = br.read()) != -1)
            {
                sb.append((char)read);
            }
        }
        finally
        {
            br.close();
        }
        return sb.toString();
    }

    public static InputStream getFileInputStream(String fileName)
            throws IOException
    {
        return OTRefactoringTestPlugin.getDefault().getTestResourceStream(
                fileName);
    }

    public static String removeExtension(String fileName)
    {
        return fileName.substring(0, fileName.lastIndexOf('.'));
    }

    public static void performDummySearch(IJavaElement element)
            throws Exception
    {
        new SearchEngine().searchAllTypeNames(ResourcesPlugin.getWorkspace(),
                null, null, SearchPattern.R_EXACT_MATCH, true,
                IJavaSearchConstants.CLASS, SearchEngine
                        .createJavaSearchScope(new IJavaElement[] { element }),
                new Requestor(),
                IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, null);
    }

    public static IMember[] merge(IMember[] a1, IMember[] a2, IMember[] a3)
    {
        return JavaElementUtil.merge(JavaElementUtil.merge(a1, a2), a3);
    }

    public static IMember[] merge(IMember[] a1, IMember[] a2)
    {
        return JavaElementUtil.merge(a1, a2);
    }

    public static IField[] getFields(IType type, String[] names)
            throws JavaModelException
    {
        if (names == null)
        {
            return new IField[0];
        }
        Set<IField> fields = new HashSet<IField>();
        for (int i = 0; i < names.length; i++)
        {
            IField field = type.getField(names[i]);
            assertTrue("field " + field.getElementName() + " does not exist",
                    field.exists());
            fields.add(field);
        }
        return fields.toArray(new IField[fields.size()]);
    }

    public static IType[] getMemberTypes(IType type, String[] names)
            throws JavaModelException
    {
        if (names == null)
        {
            return new IType[0];
        }
        Set<IType> memberTypes = new HashSet<IType>();
        for (int i = 0; i < names.length; i++)
        {
            IType memberType = type.getType(names[i]);
            assertTrue("member type " + memberType.getElementName()
                    + " does not exist", memberType.exists());
            memberTypes.add(memberType);
        }
        return memberTypes.toArray(new IType[memberTypes.size()]);
    }

    public static IMethod[] getMethods(IType type, String[] names,
            String[][] signatures) throws JavaModelException
    {
    	return getMethods(type, names, signatures, null, false);
    }
    public static IMethod[] getMethods(IType type, String[] names, String[][] signatures,
    									boolean[] flags, boolean flag)
            		throws JavaModelException
    {
        if (names == null || signatures == null)
        {
            return new IMethod[0];
        }
        List<IMethod> methods = new ArrayList<IMethod>(names.length);
        for (int i = 0; i < names.length; i++)
        {
        	// use flags to filter sub-set of names/signatures:
        	if (flags != null && flags[i] != flag) continue;

            IMethod method = type.getMethod(names[i], signatures[i]);
            if (!method.exists()) {
            	// search a callout mapping that might be "equal" to this method:
            	for (IJavaElement child : type.getChildren()) {
            		int elementType = child.getElementType();
					if (elementType == IOTJavaElement.CALLOUT_MAPPING || elementType == IOTJavaElement.CALLOUT_TO_FIELD_MAPPING) {
						AbstractCalloutMapping map = (AbstractCalloutMapping) child;
						if (method.equals(map.getCorrespondingJavaElement())) {
							method = map;
							break;
						}
					}
            	}
            }
            assertTrue("method " + method.getElementName() + " does not exist",
                    method.exists());
            if (!methods.contains(method))
            {
                methods.add(method);
            }
        }
        return methods.toArray(new IMethod[methods.size()]);
    }

    public static IType[] findTypes(IType[] types, String[] namesOfTypesToPullUp)
    {
        List<IType> found = new ArrayList<IType>(types.length);
        for (int i = 0; i < types.length; i++)
        {
            IType type = types[i];
            for (int j = 0; j < namesOfTypesToPullUp.length; j++)
            {
                String name = namesOfTypesToPullUp[j];
                if (type.getElementName().equals(name))
                {
                    found.add(type);
                }
            }
        }
        return found.toArray(new IType[found.size()]);
    }

    public static IField[] findFields(IField[] fields,
            String[] namesOfFieldsToPullUp)
    {
        List<IField> found = new ArrayList<IField>(fields.length);
        for (int i = 0; i < fields.length; i++)
        {
            IField field = fields[i];
            for (int j = 0; j < namesOfFieldsToPullUp.length; j++)
            {
                String name = namesOfFieldsToPullUp[j];
                if (field.getElementName().equals(name))
                {
                    found.add(field);
                }
            }
        }
        return found.toArray(new IField[found.size()]);
    }

    public static IMethod[] findMethods(IMethod[] selectedMethods,
            String[] namesOfMethods, String[][] signaturesOfMethods)
    {
        List<IMethod> found = new ArrayList<IMethod>(selectedMethods.length);
        for (int i = 0; i < selectedMethods.length; i++)
        {
            IMethod method = selectedMethods[i];
            String[] paramTypes = method.getParameterTypes();
            for (int j = 0; j < namesOfMethods.length; j++)
            {
                String methodName = namesOfMethods[j];
                if (!methodName.equals(method.getElementName()))
                {
                    continue;
                }
                String[] methodSig = signaturesOfMethods[j];
                if (!areSameSignatures(paramTypes, methodSig))
                {
                    continue;
                }
                found.add(method);
            }
        }
        return found.toArray(new IMethod[found.size()]);
    }

    private static boolean areSameSignatures(String[] s1, String[] s2)
    {
        if (s1.length != s2.length)
        {
            return false;
        }
        for (int i = 0; i < s1.length; i++)
        {
            if (!s1[i].equals(s2[i]))
            {
                return false;
            }
        }
        return true;
    }

    /**
     * Line-based version of junit.framework.Assert.assertEquals(String, String)
     * without considering line delimiters.
     */
    public static void assertEqualLines(String expected, String actual)
    {
        assertEqualLines("", expected, actual);
    }

    /**
     * Line-based version of junit.framework.Assert.assertEquals(String, String, String)
     * without considering line delimiters.
     */
    public static void assertEqualLines(String message, String expected,
            String actual)
    {
        String[] expectedLines = Strings.convertIntoLines(expected);
        String[] actualLines = Strings.convertIntoLines(actual);

        String expected2 = (expectedLines == null ? null : Strings.concatenate(
                expectedLines, "\n"));
        String actual2 = (actualLines == null ? null : Strings.concatenate(
                actualLines, "\n"));
        assertEquals(message, expected2, actual2);
    }

    private static class Requestor implements ITypeNameRequestor
    {

        public void acceptClass(char[] packageName, char[] simpleTypeName,
                char[][] enclosingTypeNames, String path)
        {
        }

        public void acceptInterface(char[] packageName, char[] simpleTypeName,
                char[][] enclosingTypeNames, String path)
        {
        }
    }
}

Back to the top