create changelog entry
[debian/openrocket] / core / test / net / sf / openrocket / preset / PresetAssertHelper.java
1 package net.sf.openrocket.preset;
2
3 import static org.junit.Assert.*;
4
5 public abstract class PresetAssertHelper {
6
7         public static void assertInvalidPresetException( InvalidComponentPresetException exceptions, TypedKey<?>[] keys, String[] messages ) {
8                 if ( keys != null ) {
9                         assertEquals( keys.length, exceptions.getInvalidParameters().size() );
10                         for( TypedKey<?> expectedKey : keys ) {
11                                 boolean keyFound = false;
12                                 for( TypedKey<?> k : exceptions.getInvalidParameters() ) {
13                                         if ( expectedKey == k ) {
14                                                 keyFound = true;
15                                                 break;
16                                         }
17                                 }
18                                 if ( ! keyFound ) {
19                                         fail( "Expected key " + expectedKey + " not in exception");
20                                 }
21                         }
22                 } else {
23                         assertEquals(0, exceptions.getInvalidParameters().size() );
24                 }
25                 if ( messages != null ) {
26                         assertEquals( messages.length, exceptions.getErrors().size() );
27                         for( String expectedMessage : messages ) {
28                                 boolean stringMatched = false;
29                                 for ( String s : exceptions.getErrors() ) {
30                                         if ( s.contains( expectedMessage ) ) {
31                                                 stringMatched = true;
32                                                 break;
33                                         }
34                                 }
35                                 if( !stringMatched ) {
36                                         fail( "Expected string \"" + expectedMessage + "\" not reported in errors");
37                                 }
38                         }
39                 } else {
40                         assertEquals(0, exceptions.getErrors().size() );
41                 }
42         }
43 }