Skip to content

Commit

Permalink
bumped version of java-diff-utils (#64)
Browse files Browse the repository at this point in the history
* bumped version of java-diff-utils, killing some mutants

* predictable order

* doc fix
  • Loading branch information
therealryan authored Aug 15, 2022
1 parent 8209e44 commit 8fa205c
Show file tree
Hide file tree
Showing 12 changed files with 223 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Consumer;
import java.util.function.Function;
Expand Down Expand Up @@ -503,7 +505,8 @@ private void applyContexts( Flow flow, List<RuntimeException> executionFailures
try {
// work out the context updates
Set<Class<? extends Context>> unupdated = new HashSet<>( currentContext.keySet() );
List<Context> contextUpdates = new ArrayList<>();
Set<Context> contextUpdates = new TreeSet<>(
Comparator.comparing( ctx -> ctx.getClass().getName() ) );
flow.context()
.filter( ctx -> ctx.domain().stream().anyMatch( systemUnderTest::contains ) )
.forEach( ctx -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import com.mastercard.test.flow.Context;
import com.mastercard.test.flow.assrt.AbstractFlocessor.State;
import com.mastercard.test.flow.assrt.mock.AltTestContext;
import com.mastercard.test.flow.assrt.mock.TestContext;

/**
Expand Down Expand Up @@ -44,6 +45,23 @@ public Comparator<TestContext> order() {
}
};

/**
* Records context switches to {@link #ctxSwitchLog}
*/
static final Applicator<
AltTestContext> ALT_APPLICATOR = new Applicator<AltTestContext>( AltTestContext.class, 0 ) {

@Override
public void transition( AltTestContext from, AltTestContext to ) {
ctxSwitchLog.add( String.format( "switch from %s to %s", from, to ) );
}

@Override
public Comparator<AltTestContext> order() {
return Comparator.comparing( System::identityHashCode );
}
};

/**
* Clears the context switch log
*/
Expand All @@ -60,7 +78,7 @@ void contextSwitch() {

TestFlocessor tf = new TestFlocessor( "contextSwitch", TestModel.withContext() )
.system( State.FUL, B )
.applicators( APPLICATOR )
.applicators( APPLICATOR, ALT_APPLICATOR )
.behaviour( assrt -> {
assrt.actual().response( assrt.expected().response().content() );
} );
Expand All @@ -77,7 +95,9 @@ void contextSwitch() {
" | B response to A | B response to A |" ),
copypasta( tf.events() ) );
assertEquals( copypasta(
"switch from null to AltTestContext[alt ctx]",
"switch from null to TestContext[first ctx]",
"switch from AltTestContext[alt ctx] to null",
"switch from TestContext[first ctx] to TestContext[second ctx]" ),
copypasta( ctxSwitchLog ) );
}
Expand All @@ -97,7 +117,7 @@ void noApplicator() {
tf.execute();

assertEquals( copypasta(
"abc [] error No applicator for context type class com.mastercard.test.flow.assrt.mock.TestContext",
"abc [] error No applicator for context type class com.mastercard.test.flow.assrt.mock.AltTestContext",
"def [] error No applicator for context type class com.mastercard.test.flow.assrt.mock.TestContext" ),
copypasta( tf.events() ) );
assertEquals( copypasta( "" ),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,29 @@ void residueType() {
assertEquals( TestResidue.class, new TestChecker().residueType() );
}

/**
* Shows that residues with no checker implementations are ignored
*/
@Test
void unchecked() {
TestFlocessor tf = new TestFlocessor( "", TestModel.withResidue() )
.system( State.FUL, B )
.behaviour( assrt -> {
// no message assertions
} );

tf.execute();

assertEquals( copypasta(
"SKIP No assertions made",
"SKIP No assertions made" ),
copypasta( tf.events() ) );
assertEquals( copypasta(
"abc [] SKIP",
"def [] SKIP" ),
copypasta( tf.results() ) );
}

/**
* Shows that residues are checked and that the results are recorded for
* failure-avoidance purposes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,32 @@ void basisFailure() {
}
}

/**
* The dependency has been processed
*/
@Test
void dependencyPresent() {
History hst = new History();
hst.recordResult( dependency, Result.SUCCESS );

assertEquals( null, hst.skipReason(
dependent, State.FUL, Collections.singleton( Actors.BEN ) )
.orElse( null ) );
}

/**
* The dependency has not been processed
*/
@Test
void dependencyMissing() {
History hst = new History();

assertEquals( "Missing dependency", hst.skipReason(
dependent, State.FUL, Collections.singleton( Actors.BEN ) )
.orElse( null ) );

}

/**
* The dependency has failed
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,8 @@ void failureReporting() throws Exception {
}

/**
* Shows that flows that explode are tagged as such in the report
* Shows that flows that explode are tagged as such in the report and that the
* failures are logged
*/
@Test
void errorTagging() {
Expand All @@ -227,6 +228,41 @@ void errorTagging() {
assertTrue( ie.tags.contains( "ERROR" ), ie.tags.toString() );
FlowData fd = r.detail( ie );
assertTrue( fd.tags.contains( "ERROR" ), fd.tags.toString() );

assertEquals( "Encountered error: java.lang.RuntimeException: kaboom",
fd.logs.get( 0 ).message.split( "\n" )[0].trim(),
"First line of logged error"
// the stacktrace is logged, but we'll not assert on that
);
}

/**
* Shows that flows where we are supplied with unparseable bytes are tagged and
* logged correctly in the report
*/
@Test
void parseFailureTagging() {
TestFlocessor tf = new TestFlocessor( "parseFailureTagging", TestModel.abcWithParseFailures() )
.system( State.FUL, B )
.reporting( QUIETLY )
.behaviour( assrt -> {
assrt.actual().response( new byte[] { 0 } );
} );
tf.execute();

Reader r = new Reader( tf.report() );
Index index = r.read();
Entry ie = index.entries.get( 0 );
assertTrue( ie.tags.contains( "ERROR" ), ie.tags.toString() );
FlowData fd = r.detail( ie );
assertTrue( fd.tags.contains( "ERROR" ), fd.tags.toString() );

assertEquals(
"java.lang.IllegalArgumentException: Failed to parse response message from actual data",
fd.logs.get( 0 ).message.split( "\n" )[0].trim(),
"First line of logged error"
// the stacktrace is logged, but we'll not assert on that
);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.mastercard.test.flow.Actor;
import com.mastercard.test.flow.Flow;
import com.mastercard.test.flow.Model;
import com.mastercard.test.flow.assrt.mock.AltTestContext;
import com.mastercard.test.flow.assrt.mock.Flw;
import com.mastercard.test.flow.assrt.mock.Mdl;
import com.mastercard.test.flow.assrt.mock.TestContext;
Expand Down Expand Up @@ -99,6 +100,47 @@ public static Model abcWithImplicit() {
return new Mdl().withFlows( abc );
}

/**
* @return As with {@link #abc()}, but all of the messages will fail to parse
* actual content
*/
public static Model abcWithParseFailures() {
Flow abc = Creator.build( flow -> flow
.meta( data -> data
.description( "abc" ) )
.call( a -> a
.from( Actors.A )
.to( Actors.B )
.request( new FailText( "A request to B" ) )
.call( b -> b
.to( Actors.C )
.request( new FailText( "B request to C" ) )
.response( new FailText( "C response to B" ) ) )
.response( new FailText( "B response to A" ) ) ) );

return new Mdl().withFlows( abc );
}

private static class FailText extends Text {
private final String content;

public FailText( String s ) {
super( s );
content = s;
}

@Override
public Text peer( byte[] bytes ) {
System.out.println( "TestModel.FailText.peer()" );
throw new IllegalArgumentException( "kaboom!" );
}

@Override
public Text child() {
return new FailText( content );
}
}

/**
* @return A model with two flows with a dependency between them, calling from A
* to B to C
Expand Down Expand Up @@ -134,6 +176,7 @@ public static Model withContext() {
.meta( data -> data
.description( "abc" ) )
.context( new TestContext().value( "first ctx" ) )
.context( new AltTestContext().value( "alt ctx" ) )
.call( a -> a
.from( Actors.A )
.to( Actors.B )
Expand All @@ -147,7 +190,8 @@ public static Model withContext() {
Flow def = Deriver.build( abc, flow -> flow
.meta( data -> data
.description( "def" ) )
.context( TestContext.class, c -> c.value( "second ctx" ) ) );
.context( TestContext.class, c -> c.value( "second ctx" ) )
.context( AltTestContext.class, null ) );

return new Mdl().withFlows( abc, def );
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package com.mastercard.test.flow.assrt.mock;

import java.util.Collections;
import java.util.Set;

import com.mastercard.test.flow.Actor;
import com.mastercard.test.flow.Context;
import com.mastercard.test.flow.assrt.TestModel.Actors;

/**
* Trivial {@link Context} implementation to use in tests. Crucially, this is a
* different class from {@link TestContext}
*/
public class AltTestContext implements Context {

private String value;

/**
* @return context value
*/
public String value() {
return value;
}

/**
* @param v context value
* @return <code>this</code>
*/
public AltTestContext value( String v ) {
value = v;
return this;
}

@Override
public String name() {
return "AltTestContext";
}

@Override
public Set<Actor> domain() {
return Collections.singleton( Actors.B );
}

@Override
public Context child() {
return new AltTestContext().value( value );
}

@Override
public String toString() {
return "AltTestContext[" + value + "]";
}
}
10 changes: 5 additions & 5 deletions doc/src/main/markdown/further.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ By default the report will be saved to a timestamped directory under `target/mct

<!-- code_link_start -->

[AbstractFlocessor.reporting(Reporting)]: ../../../../assert/assert-core/src/main/java/com/mastercard/test/flow/assrt/AbstractFlocessor.java#L153-L160,153-160
[AbstractFlocessor.reporting(Reporting)]: ../../../../assert/assert-core/src/main/java/com/mastercard/test/flow/assrt/AbstractFlocessor.java#L155-L162,155-162
[Reporting]: ../../../../assert/assert-core/src/main/java/com/mastercard/test/flow/assrt/Reporting.java

<!-- code_link_end -->
Expand Down Expand Up @@ -230,7 +230,7 @@ Consider the following worked example:

[flow.Unpredictable]: ../../../../api/src/main/java/com/mastercard/test/flow/Unpredictable.java
[AbstractMessage.masking(Unpredictable,UnaryOperator)]: ../../../../message/message-core/src/main/java/com/mastercard/test/flow/msg/AbstractMessage.java#L45-L52,45-52
[AbstractFlocessor.masking(Unpredictable...)]: ../../../../assert/assert-core/src/main/java/com/mastercard/test/flow/assrt/AbstractFlocessor.java#L165-L172,165-172
[AbstractFlocessor.masking(Unpredictable...)]: ../../../../assert/assert-core/src/main/java/com/mastercard/test/flow/assrt/AbstractFlocessor.java#L167-L174,167-174
[mask.BenSys]: ../../test/java/com/mastercard/test/flow/doc/mask/BenSys.java
[mask.DieSys]: ../../test/java/com/mastercard/test/flow/doc/mask/DieSys.java
[mask.Unpredictables]: ../../test/java/com/mastercard/test/flow/doc/mask/Unpredictables.java
Expand All @@ -240,7 +240,7 @@ Consider the following worked example:
[msg.Mask.andThen(Consumer)]: ../../../../message/message-core/src/main/java/com/mastercard/test/flow/msg/Mask.java#L289-L291,289-291
[BenDiceTest?masking]: ../../test/java/com/mastercard/test/flow/doc/mask/BenDiceTest.java#L31,31
[BenTest]: ../../test/java/com/mastercard/test/flow/doc/mask/BenTest.java
[AbstractFlocessor.masking(Unpredictable...)]: ../../../../assert/assert-core/src/main/java/com/mastercard/test/flow/assrt/AbstractFlocessor.java#L165-L172,165-172
[AbstractFlocessor.masking(Unpredictable...)]: ../../../../assert/assert-core/src/main/java/com/mastercard/test/flow/assrt/AbstractFlocessor.java#L167-L174,167-174

<!-- code_link_end -->

Expand All @@ -260,7 +260,7 @@ You can see usage of these types in the example system:
[flow.Context]: ../../../../api/src/main/java/com/mastercard/test/flow/Context.java
[Builder.context(Context)]: ../../../../builder/src/main/java/com/mastercard/test/flow/builder/Builder.java#L225-L232,225-232
[assrt.Applicator]: ../../../../assert/assert-core/src/main/java/com/mastercard/test/flow/assrt/Applicator.java
[AbstractFlocessor.applicators(Applicator...)]: ../../../../assert/assert-core/src/main/java/com/mastercard/test/flow/assrt/AbstractFlocessor.java#L192-L198,192-198
[AbstractFlocessor.applicators(Applicator...)]: ../../../../assert/assert-core/src/main/java/com/mastercard/test/flow/assrt/AbstractFlocessor.java#L194-L200,194-200
[model.ctx.QueueProcessing]: ../../../../example/app-model/src/main/java/com/mastercard/test/flow/example/app/model/ctx/QueueProcessing.java
[QueueProcessingApplicator]: ../../../../example/app-assert/src/main/java/com/mastercard/test/flow/example/app/assrt/ctx/QueueProcessingApplicator.java

Expand All @@ -283,7 +283,7 @@ You can see usage of these types in the example system:

[flow.Residue]: ../../../../api/src/main/java/com/mastercard/test/flow/Residue.java
[assrt.Checker]: ../../../../assert/assert-core/src/main/java/com/mastercard/test/flow/assrt/Checker.java
[AbstractFlocessor.checkers(Checker...)]: ../../../../assert/assert-core/src/main/java/com/mastercard/test/flow/assrt/AbstractFlocessor.java#L205-L211,205-211
[AbstractFlocessor.checkers(Checker...)]: ../../../../assert/assert-core/src/main/java/com/mastercard/test/flow/assrt/AbstractFlocessor.java#L207-L213,207-213
[model.rsd.DBItems]: ../../../../example/app-model/src/main/java/com/mastercard/test/flow/example/app/model/rsd/DBItems.java
[DBItemsChecker]: ../../../../example/app-assert/src/main/java/com/mastercard/test/flow/example/app/assrt/rsd/DBItemsChecker.java

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public Text child() {

@Override
public Text peer( byte[] content ) {
return copyMasksTo( new Text( new String( content, UTF_8 ) ) );
return copyMasksTo( new Text( content ) );
}

@Override
Expand Down
7 changes: 7 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,13 @@
<version>5.2.0</version>
</dependency>

<dependency>
<!-- text diffs -->
<groupId>io.github.java-diff-utils</groupId>
<artifactId>java-diff-utils</artifactId>
<version>4.12</version>
</dependency>

</dependencies>
</dependencyManagement>

Expand Down
Loading

0 comments on commit 8fa205c

Please sign in to comment.